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.15.tar.gz (58.1 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.15-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for tqdm_prometheus_exporter-0.1.15.tar.gz
Algorithm Hash digest
SHA256 7a2a383b628f7abda50423fc14fc433b77e7b5749dbab9c441b593e0841602b0
MD5 760be3b38077be8f455faac908f1b5b0
BLAKE2b-256 989fdd8cd2f6cbff2262f911823e93504c0c2bf25e6f9b9e6ff87c6d111270c2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tqdm_prometheus_exporter-0.1.15-py3-none-any.whl
Algorithm Hash digest
SHA256 dd95bbe77c47ee90076d2e84e8893279b0b965b59425699228530190022a5054
MD5 a02df0094f210a5917e67bd9d3dce21d
BLAKE2b-256 0438e2d761716df9720520c9e136abb713d6b0795257319ebb5814f0c15ce5c7

See more details on using hashes here.

Provenance

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