Skip to content

Extension chaosprometheus

Version 0.3.0
Repository https://github.com/chaostoolkit-incubator/chaostoolkit-prometheus

Build Status

Prometheus support for the Chaos Toolkit.

Install

To be used from your experiment, this package must be installed in the Python environment where chaostoolkit already lives.

$ pip install chaostoolkit-prometheus

Usage

To use this package, you must create have access to a Prometheus instance via HTTP and be allowed to connect to it.

This package only exports probes to query for some aspects of your system as monitored by Prometheus.

Here is an example of querying Prometheus at a given moment

{
    "type": "probe",
    "name": "fetch-cpu-just-2mn-ago",
    "provider": {
        "type": "python",
        "module": "chaosprometheus.probes",
        "func": "query",
        "arguments": {
            "query": "process_cpu_seconds_total{job='websvc'}",
            "when": "2 minutes ago"
        }
    }
}

You can also ask for an interval as follows:

{
    "type": "probe",
    "name": "fetch-cpu-over-interval",
    "provider": {
        "type": "python",
        "module": "chaosprometheus.probes",
        "func": "query_interval",
        "arguments": {
            "query": "process_cpu_seconds_total{job='websvc'}",
            "start": "2 minutes ago",
            "end": "now",
            "step": 5
        }
    }
}

In both cases, the probe returns the JSON payload as-is from Prometheus or raises an exception when an error is met.

The result is not further process and should be found in the generated report of the experiment run.

Contribute

If you wish to contribute more functions to this package, you are more than welcome to do so. Please, fork this project, make your changes following the usual PEP 8 code style, sprinkling with tests and submit a PR for review.

Exported Activities

probes


query

Type probe
Module chaosprometheus.probes
Name query
Return None

Run an instant query against a Prometheus server and returns its result as-is.

Signature:

def query(query: str,
          when: str = None,
          timeout: float = None,
          configuration: Dict[str, Dict[str, str]] = None,
          secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
query string Yes
when string null No
timeout number null No

Usage:

{
  "provider": {
    "module": "chaosprometheus.probes",
    "arguments": {
      "query": ""
    },
    "func": "query",
    "type": "python"
  },
  "type": "probe",
  "name": "query"
}
name: query
provider:
  arguments:
    query: ''
  func: query
  module: chaosprometheus.probes
  type: python
type: probe

query_interval

Type probe
Module chaosprometheus.probes
Name query_interval
Return None

Run a range query against a Prometheus server and returns its result as-is.

The start and end arguments can be a RFC 3339 date or expressed more colloquially such as "5 minutes ago".

Signature:

def query_interval(
        query: str,
        start: str,
        end: str,
        step: int = 1,
        timeout: float = None,
        configuration: Dict[str, Dict[str, str]] = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
query string Yes
start string Yes
end string Yes
step integer 1 No
timeout number null No

Usage:

{
  "provider": {
    "module": "chaosprometheus.probes",
    "arguments": {
      "end": "",
      "query": "",
      "start": ""
    },
    "func": "query_interval",
    "type": "python"
  },
  "type": "probe",
  "name": "query-interval"
}
name: query-interval
provider:
  arguments:
    end: ''
    query: ''
    start: ''
  func: query_interval
  module: chaosprometheus.probes
  type: python
type: probe