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.12.tar.gz (55.0 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.12-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for tqdm_prometheus_exporter-0.1.12.tar.gz
Algorithm Hash digest
SHA256 e7c2a86ea498e034a2abb157f13f8fae1c0c1cb3ef250d31ae0c65db765a3f4b
MD5 28ad533de8c232db39fdc891cea6ae76
BLAKE2b-256 d7442e33d466f1096391e22b9138a9b6ff71b2d9a927c0023aa2ba50ac000171

See more details on using hashes here.

Provenance

The following attestation bundles were made for tqdm_prometheus_exporter-0.1.12.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.12-py3-none-any.whl.

File metadata

File hashes

Hashes for tqdm_prometheus_exporter-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 cec09c6831130f2e9327c81097875208dc1cf0fb00b754293ffc8c231907393d
MD5 81bef41c472348d4c8cf2d9bd5d57480
BLAKE2b-256 ab8862db456acd8eb5a7d96430b155834968e20fbce54e0a9d04a47a28f967e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for tqdm_prometheus_exporter-0.1.12-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