A command line tool for parsing Prometheus metrics
Project description
Parse and filter metrics from Prometheus endpoints so that they can be visualized, stored into InfluxDB, or used as Juju charm metrics.
Installation
Run pip install firestealer. This will make the fsteal command available.
CLI
Print JSON formatted samples from a Prometehus endpoint:
$ fsteal http://localhost:8000/metrics
Filter metrics using a regular expression against the sample name:
$ fsteal http://localhost:8000/metrics -m '^myservice(Downloads|Uploads)'
Store samples into InfluxDB:
$ fsteal localhost:8000/metrics influxdb://user:passwd@10.0.0.1:8086/mydb
Store a subset of samples into InfluxDB:
$ fsteal localhost:8000/metrics influxdb://user:passwd@10.0.0.1:8086/mydb -m '^myservice'
In the example above the InfluxDB connection info is provided using a influxdb://$user:$passwd@$host:$port/$database connection string.
Only print specific metrics values (useful when executing fsteal in order to retrieve charm metrics):
$ fsteal localhost:8000/metrics a-single-specific-key --format values-only
API Usage
An API is exposed so that firestealer can be used as a library from Python applications. For instance, a charm could propagate metrics from Prometheus to Juju with the following snippet placed in the collect-metrics hook:
from firestealer import ( add_metrics, retrieve_metrics, ) url = 'https://localhost:8000/metrics' with open('metrics.yaml') as f: metrics = yaml.safe_load(f) samples = retrieve_metrics(url, metrics, noverify=True) add_metrics(samples)
Similarly, to write relevant samples to InfluxDB, the following snippet can be used:
from firestealer import ( retrieve_metrics, write_to_influx, ) url = 'https://localhost:8000/metrics' with open('metrics.yaml') as f: metrics = yaml.safe_load(f) samples = retrieve_metrics(url, metrics) write_to_influx('user:passwd@1.2.3.4/dbname', samples)
API Reference
- add_metrics(samples)
Add the given samples as metrics to Juju.
This function assumes an add-metric executable to be present in the PATH.
- retrieve_metrics(url, metrics, noverify=False)
Retrieve samples for the given metrics from the given Prometheus URL.
Raise a firestealer.PrometheusError if the samples cannot be retrieved.
Only return samples whose name is included in the given metrics object, which is a decoded metrics.yaml content. Samples are renamed based on the metrics provided. If noverify is True, then do not validate URL certificates.
- retrieve_samples(url, regex=’’, prefix=’’, noverify=False)
Retrieve and return samples from the given Prometheus URL.
Raise a firestealer.PrometheusError if the samples cannot be retrieved.
Only return samples whose name matches the given regex. If a prefix is provided, include that in the resultimg sample names. If noverify is True, then do not validate URL certificates.
- samples_to_points(samples)
Convert samples to InfluxDB points.
Only samples with an actual value are included in the resulting list.
- text_to_samples(text, regex=’’, prefix=’’)
Parse the given metrics text and return a sequence of samples.
Only return samples whose name matches the given regex. If a prefix is provided, include that in the resultimg sample names.
- write_to_influx(conn_string, samples)
Write the given samples to the InfluxDB at the given connection string.
The connection string is in “$user:$passwd@$host:$port/$database” form. Raise a firestealer.InfluxError if the connection string is not well formed or when it is not possible to communicate with InfluxDB.
- Sample = namedtuple(‘Sample’, [‘name’, ‘tags’, ‘value’])
A sample represents a sigle Prometheus key/value measurement.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file firestealer-0.5.0.tar.gz
.
File metadata
- Download URL: firestealer-0.5.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 608042ba4141cd66c485e939d97d1cb00b7e885edbf705fb865929b5aacbafb5 |
|
MD5 | c93b8afd2bbb965a85d68a1edfee62cb |
|
BLAKE2b-256 | 9d704f275586f76c042ae61f252f3436101feeabdd7f612d6072c941fc5a2dfb |
File details
Details for the file firestealer-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: firestealer-0.5.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb32566d7c9843470130c42e5de79b16e0b89604ed4ba08d87f3414b53bc794d |
|
MD5 | 643041efc200392532a88b66d9b837df |
|
BLAKE2b-256 | 27b75cfbcdffe7628a3cd044f435e19b0e1d763deba6b544e40376e0cbd7efa4 |