Prometheus Interactions


Use promtool to check to see if a rule is valid or not

The command name changed slightly from 1.x -> 2.x but this uses promtool to verify if the rules are correct or not. This can be bypassed by setting a dummy command such as /usr/bin/true that always returns true

promgen.prometheus.import_config(config, replace_shard=None)[source]
promgen.prometheus.import_rules_v2(config, content_object=None)[source]

Loop through a dictionary and add rules to the database

This assumes a dictonary in the 2.x rule format. See promgen/tests/examples/import.rule.yml for an example

promgen.prometheus.render_config(service=None, project=None)[source]

Render rules in a format that Prometheus understands

  • rules (list(Rule)) – List of rules
  • version (int) – Prometheus rule format (1 or 2)

Returns rules in yaml or Prometheus v1 format

Return type:


This function can render in either v1 or v2 format We call prefetch_related_objects within this function to populate the other related objects that are mostly used for the sub lookups.

promgen.prometheus.silence(labels, duration=None, **kwargs)[source]

Post a silence message to Alert Manager Duration should be sent in a format like 1m 2h 1d etc