Skip to main content

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.

Metadata

Release files for firestealer 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for firestealer 0.5.0
File Size Uploaded
firestealer-0.5.0.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for firestealer 0.5.0
File Interpreter ABI Platform
firestealer-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.4 kB

Release files / firestealer-0.5.0.tar.gz

Download URL firestealer-0.5.0.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
608042ba4141cd66c485e939d97d1cb00b7e885edbf705fb865929b5aacbafb5
BLAKE2b-256 checksum
How to use checksums
9d704f275586f76c042ae61f252f3436101feeabdd7f612d6072c941fc5a2dfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / firestealer-0.5.0-py3-none-any.whl

Download URL firestealer-0.5.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb32566d7c9843470130c42e5de79b16e0b89604ed4ba08d87f3414b53bc794d
BLAKE2b-256 checksum
How to use checksums
27b75cfbcdffe7628a3cd044f435e19b0e1d763deba6b544e40376e0cbd7efa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page