项目作者: chaostoolkit-incubator

项目描述 :
Prometheus Extension for the Chaos Toolkit
高级语言: Python
项目地址: git://github.com/chaostoolkit-incubator/chaostoolkit-prometheus.git
创建时间: 2017-10-16T20:19:44Z
项目社区:https://github.com/chaostoolkit-incubator/chaostoolkit-prometheus

开源协议:Apache License 2.0

下载


Prometheus extension for the Chaos Toolkit

Version
License
Build
Python versions

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.

  1. $ 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.

By default, the Prometheus instance at http://localhost:9090 will be queried.
To override, you need to set up the instance details using the prometheus_base_url
configuration property:

  1. "configuration": {
  2. "prometheus_base_url": "http://my.prometheus.server/"
  3. }

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

  1. {
  2. "type": "probe",
  3. "name": "fetch-cpu-just-2mn-ago",
  4. "provider": {
  5. "type": "python",
  6. "module": "chaosprometheus.probes",
  7. "func": "query",
  8. "arguments": {
  9. "query": "process_cpu_seconds_total{job='websvc'}",
  10. "when": "2 minutes ago"
  11. }
  12. }
  13. }

You can also ask for an interval as follows:

  1. {
  2. "type": "probe",
  3. "name": "fetch-cpu-over-interval",
  4. "provider": {
  5. "type": "python",
  6. "module": "chaosprometheus.probes",
  7. "func": "query_interval",
  8. "arguments": {
  9. "query": "process_cpu_seconds_total{job='websvc'}",
  10. "start": "2 minutes ago",
  11. "end": "now",
  12. "step": 5
  13. }
  14. }
  15. }

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.

You can also send metrics to a pushgateway service via a control:

  1. {
  2. "controls": [
  3. {
  4. "name": "prometheus",
  5. "provider": {
  6. "type": "python",
  7. "module": "chaosprometheus.metrics",
  8. "arguments": {
  9. "pushgateway_url": "http://someip:9091",
  10. "job": "chaostoolkit"
  11. }
  12. }
  13. }
  14. ]
  15. }

You can also set three more arguments:

  • grouping_key: A mapping of strings to uniquely aggregate multiple runs
    in the Prometheus backend
  • trace_id: This must be a string which will identify this run uniquely in
    your metrics. If none is a provided, a random string is generated.
  • experiment_ref: Sometimes it’s useful to identify a particular experiment,
    not just its run, throughout many runs. This is the string to do that. If
    none is provided, a hash of the experiment is performed and used. The hash
    is not stable across changes of the experiment of course.

These are particularly useful when you couple this extension with others like
Loki where you want to cross-reference between logs and metrics.

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.