prometheus

Prometheus module.

exception wmflib.prometheus.PrometheusError[source]

Bases: wmflib.exceptions.WmflibError

Custom exception class for errors of this module.

class wmflib.prometheus.Prometheus[source]

Bases: object

Class to interact with the Prometheus server.

Initialize the instance.

Examples

>>> from wmflib.prometheus import Prometheus
>>> prometheus = Prometheus()
query(query: str, site: str, *, timeout: Optional[Union[float, int]] = 10) List[Dict][source]

Perform a generic query.

Examples

results = prometheus.query('node_memory_MemTotal_bytes{instance=~"host1001:.*"}', 'eqiad')

The results will be something like:

[
    {
        'metric': {
            '__name__': 'node_memory_MemTotal_bytes',
            'cluster': 'management',
            'instance': 'host1001:9100',
            'job': 'node',
            'site': 'eqiad'
        },
        'value': [1636569623.988, '67225329664']
    }
]
Parameters
  • query (str) – a prometheus query

  • site (str) – The site to use for queries. Must be one of wmflib.constants.ALL_DATACENTERS

  • timeout (float, int, None, optional) – How many seconds to wait for the prometheus to send data before giving up, as a float or int. Alternatively None to indicate an infinite timeout.

Returns

returns an empty list if there are no results otherwise return a list of results of the form: {‘metric’: {}, ‘value’: [$timestamp, $value]}

Return type

list

Raises

wmflib.prometheus.PrometheusError – on error