Skip to main content

Build Status Code Climate Coverage Status

Prometheus Distributed Client

Purpose and principle

prometheus-distributed-client is aimed at shorted lived process that can expose Prometheus metrics through HTTP.

Advantages over Pushgateway

The prometheus project provides several ways of publishing metrics. Either you publish them directly like the official client allows you to do, or you push them to a pushgateway.

The first method implies you've got to keep your metrics in-memory and publishs them over http. The second method implies that you'll either have a pushgateway per process or split your metrics over all your processes to avoid overwriting your existing pushed metrics.

prometheus-distributed-client allows you to have your short lived process push metrics to a database and have another process serving them over HTTP. One of the perks of that approach is that you keep consistency over concurrent calls. (Making multiple counter increment from multiple process will be acknowledge correctly by the database).

Code examples

prometheus-distributed-client uses the base of the official client but replaces all write and read operation by database call.

Declaring and using metrics

from prometheus-distributed-client import set_redis_conn, Counter, Gauge
# we use the official clients internal architecture
from prometheus_client import CollectorRegistry

# set your own registry
REGISTRY = CollectorRegistry()
# declare metrics from prometheus-distributed-client
COUNTER = Counter('counter_metric_name', 'metric documentation',
                  [labels], registry=REGISTRY)
GAUGE = Gauge('gauge_metric_name', 'metric documentation',
                  [labels], registry=REGISTRY)

# increment a counter and set a value for a gauge
COUNTER.labels('label_value').inc()
GAUGE.labels('other_label_value').set(12)

Serving the metrics

prometheus-distributed-client use the registry system from the official client and is de facto compatible with it. If you want to register regular metrics alongside the one from prometheus-distributed-client it is totally feasible. Here is a little example of how to serv metrics from prometheus-distributed-client, but you can also refer to the documentation of the official client.

# with flask

from flask import Flask
from prometheus_client import generate_latest
# get the registry you declared your metrics in
from metrics import REGISTRY

app = Flask()

@app.route('/metrics')
def metrics():
    return generate_latest(REGISTRY)

Release files for prometheus-distributed-client 1.2.2

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

Source distribution (sdist)

Source distribution for prometheus-distributed-client 1.2.2
File Size Uploaded
prometheus_distributed_client-1.2.2.tar.gz 15.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prometheus-distributed-client 1.2.2
File Interpreter ABI Platform
prometheus_distributed_client-1.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 31.5 kB

Release files / prometheus_distributed_client-1.2.2.tar.gz

Download URL prometheus_distributed_client-1.2.2.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ae26c4f539e6b3e69e6086ff0e1376e82e49c1ad65ccf5eff1fc17e95debc278
BLAKE2b-256 checksum
How to use checksums
94e39d75aea666a46820c7b6aad09d65ab45373fe5c9f2a275974a106c3abf63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-58-generic

Release files / prometheus_distributed_client-1.2.2-py3-none-any.whl

Download URL prometheus_distributed_client-1.2.2-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
194fb46cd990d72403936b0d0569b24a36cb69ba8bd951f656d2a7ea5124b4bd
BLAKE2b-256 checksum
How to use checksums
61af844ab330b77f0805f1d32b422f7c661ce3f96c2a3baf27f8a4419ff83ca6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-58-generic

Release history Release notifications | RSS feed

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.2.3

2 release files

This release

1.2.2 This release

2 release files

1.2.1

1 release file

1.1.0

1 release file

1.0.1

1 release file

0.2.0

1 release file

0.0.1

1 release file

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