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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for tqdm_prometheus_exporter-0.1.13.tar.gz
Algorithm Hash digest
SHA256 12f502af0a6cd8962ad96961e7cfc255f54ae83a80e9c7ffda540a39ae9b6a35
MD5 05840df7c8f630bba5b0f9b4f39ff199
BLAKE2b-256 b55fe8ba73317d8e4bb2c23e72b4719dbb6d66bba5b876ddd18c9a05bce770d5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tqdm_prometheus_exporter-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 3a831f00c87f75611c2ab710684a6e6e173e1b639ecfd8855ec3d621aefe207c
MD5 0c42dadea949e6431ff3970952c93255
BLAKE2b-256 29306d52b1aba2bab6301f212a9332b41e3ed6743570a3a2e44cdefcc8b5ef9b

See more details on using hashes here.

Provenance

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