# 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

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

### Use the proxy

Replace `tqdm` initalisers with `proxy.tqdm`.

```python
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
```

If you require `tqdm.write` for sticky console output,

```python
from tqdm import tqdm as tqdm_og
tqdm_og.write('Job done')
```

```sh
curl http://[::1]:3000/metrics
```

> [!WARNING]  
> For windows users ensure you add this to your `__main__` block, and before any initialisation of `TqdmPrometheusProxy`
>
> ```python
> from multiprocessing import freeze_support
> freeze_support()
> ```

## Overview

```mermaid

---
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

```
