Simple python script to log the output of a prometheus exporter as CSV
This project periodically fetches a Prometheus exporter endpoint and logs selected metrics as CSV to stdout.
$ ./prom2csv -u http://127.0.0.1:34567/metrics \
> -m rx_bytes \
> -m tx_bytes > test.csv
INFO Tip: You can pipe stdout to a file to store the CSV on disk!
INFO Tip: Press Ctrl+C or send SIGINT to quit!
INFO Listening on http://127.0.0.1:34567/metrics for 2 metrics...
^C INFO Quitting...
$ head test.csv
time,rx_bytes,tx_bytes
0,5.456372e+06,3.776076e+06
100,5.456372e+06,3.776076e+06
200,5.456372e+06,3.776076e+06
300,5.456372e+06,3.776076e+06
400,5.456372e+06,3.776076e+06
500,5.456372e+06,3.776076e+06
600,5.456372e+06,3.776076e+06
700,5.456372e+06,3.776076e+06
800,5.456372e+06,3.776076e+06
$
Just download the script prom2csv from this repository, make it executable and run it.
- Python 3
requestsmodule
The usage is straightforward, just look at the help page:
usage: prom2csv [-h] [-l {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [-i INTERVAL]
[-d DELIMITER] -u URL [-m METRICS] [-s]
Log prometheus metrics as csv
optional arguments:
-h, --help show this help message and exit
-l {DEBUG,INFO,WARNING,ERROR,CRITICAL}, --log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
the log level on stderr for this application
-i INTERVAL, --interval INTERVAL
polling interval in ms
-d DELIMITER, --delimiter DELIMITER
CSV delimiter character
-u URL, --url URL the prometheus exporter url
-m METRICS, --metric METRICS
the metric names to record
-s, --show show available metrics and exit
If you find any bugs/unexpected behaviour or you have a proposition for future changes open an issue describing the current behaviour and what you expected.
Fin Christensen
Give a ⭐ if this project helped you!