Skip to main content

Echo tqdm progress to a prometheus endpoint

Project description

Prometheus exporter for tqdm

Publish your pretty CLI stats for monitoring elsewhere

Usage

There are no security or authentication mechanisms provided, be careful exposing the host more widely

Initalise the proxy

proxy = TqdmPromProxy(http_host='[::1]', http_port=3000, metric_func=metric_formatter_func)
proxy.start()

Use the proxy

Replace tqdm initalisers with proxy.tqdm.

for item in proxy.tqdm(range(100), desc='My first bar')
    item.doathing()

with proxy.tqdm(range(100), desc='My second bar') as f:
    f.update(50)

# etc

Formatting your content

TQDM bars are a lot more verbose than prometheus metrics. You can customise their names by passing in a function with this signature.

def metric_formatter_func(metric_name: str, metric_property: str, metric_scale: str) -> str:
    pass

metric_property is one of:

  • completed the number executions thus far in TQDM;
  • total the configured expected maximum in TQDM as tqdm(total=x);
  • active based on the naming, how many current bars are being grouped together as this name
  • finished based on the naming, how many bars with this name have been completely finished

The str that is returned must adhere to the metric naming conventions (A-Za-z0-9_) outlined in the prometheus docs https://prometheus.io/docs/practices/naming/

This function is called a lot, so avoid computation or cache your values

Additionally to control which properties are aggregated, provide a bucket_func: This example will aggregate all bars with a description starting with upload together

def bucketting_func(snapshot: TqdmSnapshot):
    if snapshot.desc.lowercase().startswith('upload'):
        return "Upload"

    return snapshot.desc

If you require tqdm.write for sticky console output,

from tqdm import tqdm as tqdm_og
tqdm_og.write('Job done')
curl http://[::1]:3000/metrics

[!WARNING]
For windows users ensure you add this to your __main__ block, and before any initialisation of TqdmPrometheusProxy

from multiprocessing import freeze_support
freeze_support()

Overview

---
Conceptual Overview
---
flowchart LR

    Queue@{ shape: das, label: "Update buffer" }
    TQDM@{ shape: process, label: "(your) faux TQDM instance"}
    Bucketting@{ shape: process, label: "Metric extraction & aggregation"}

    TQDM -- "Periodic Updates" --> Queue
    Queue --> Bucketting
    Bucketting -- "Expose aggregate metrics" --> HttpServer

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

tqdm_prometheus_exporter-0.1.14.tar.gz (57.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tqdm_prometheus_exporter-0.1.14-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file tqdm_prometheus_exporter-0.1.14.tar.gz.

File metadata

File hashes

Hashes for tqdm_prometheus_exporter-0.1.14.tar.gz
Algorithm Hash digest
SHA256 fbdb4b531d238f174fa8e1670060e9484b96960b3a24302701a68c7e376c69fe
MD5 31173aaf8c2863c5fe7ee690471c2c9f
BLAKE2b-256 3d3a7b6e31b16efd083f1d56bd707bc436a2b073f1e8eec48e8e9c09c0f719e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tqdm_prometheus_exporter-0.1.14.tar.gz:

Publisher: python-publish.yml on arrowed/tqdm-prometheus-exporter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tqdm_prometheus_exporter-0.1.14-py3-none-any.whl.

File metadata

File hashes

Hashes for tqdm_prometheus_exporter-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 1cf46774db2efffd3614ffb9abbdba24bcb8817563f1efca6c15826b2d232ba8
MD5 e61087e89ddeb2574230cd883f57f17e
BLAKE2b-256 389f5a6a6e63b25338420dceb458cc728ac10651fe4c1ffd1f5cf2ab257cee13

See more details on using hashes here.

Provenance

The following attestation bundles were made for tqdm_prometheus_exporter-0.1.14-py3-none-any.whl:

Publisher: python-publish.yml on arrowed/tqdm-prometheus-exporter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page