prom2csv: Export prometheus metrics into CSV
A hi-performance tool to export prometheus metrics in a CSV file.
It will help you fetching the last value of metrics extracted from prometheus, including computed values and export those results as CSV files. Which make it efficient to export those data to other tools.
It also supports generating IDs based on labels of metrics (see --row-id-expression), so tools
can compare values or override existing ones easily => one metric is always named the same way.
Requirements
It just requires requests => pip install requests
You can install it with pip install prom2csv in any python environment (Python 3.9+)
Usage
usage: prom2csv [-h] [--prometheus-url PROMETHEUS_URL] [--column-name-mapping COLUMN_NAME_MAPPING COLUMN_NAME_MAPPING]
[--row-id-expression ROW_ID_EXPRESSION] [--remove-column REMOVE_COLUMN] [--skip-csv-header] [-o OUTPUT_CSV] [-v]
query
Export Prometheus time-serie to CSV
positional arguments:
query Prometheus query to perform
options:
-h, --help show this help message and exit
--prometheus-url PROMETHEUS_URL
Connect to the given prometheus host (default=$PROMETHEUS_URL or http://localhost:9090)
--column-name-mapping COLUMN_NAME_MAPPING COLUMN_NAME_MAPPING
map a column into a specific name (id, timestamp, value + labels) into another name: --column-name-mapping id my_id (can be
repeated)
--row-id-expression ROW_ID_EXPRESSION
First column value (default=__name__'). You can use python expression using labels: --name 'f"{__name__}.{__job__}"
--remove-column REMOVE_COLUMN
Remove a column, can be specified multiple times
--skip-csv-header Do not create CSV header
-o OUTPUT_CSV, --output-csv OUTPUT_CSV
File to perform the output to, defaults to stdout
-v, --version show program's version number and exit
Examples
Get the size of the table user on all Postgresql instance in env=prod
./prom2csv.py 'pg_stat_user_tables_n_live_tup{relname="user",env="prod"}'
id,timestamp,value,datname,duty,env,hostname,instance,job,relname,schemaname,tenant_id,type
pg_stat_user_tables_n_live_tup,2024-06-05 09:54:09.274000+00:00,180,pgdb,always,prod,prod1005-01,prod1005-01.example.org:39187,postgres,user,public,1005,app
pg_stat_user_tables_n_live_tup,2024-06-05 09:54:09.274000+00:00,107,pgdb,always,prod,prod1006-01,prod1006-01.example.org:39187,postgres,user,public,1006,app
Same, but set the name of instance as first row and hide some rows
./prom2csv.py 'pg_stat_user_tables_n_live_tup{relname="user",env="prod"}' \
--column-name-mapping id my_instance \
--row-id-expression 'instance' \
--column-name-mapping tenant_id my_customer \
--remove-column timestamp \
--remove-column type \
--remove-column duty
my_instance,value,datname,env,hostname,instance,job,relname,schemaname,my_customer
prod1005-01.example.org:39187,180,pgdb,prod,prod1005-01,prod1005-01.example.org:39187,postgres,user,public,1005
prod1006-01.example.org:39187,107,pgdb,prod,prod1006-01,prod1006-01.example.org:39187,postgres,user,public,1006
List all machines/partitions in dev or prod with partition usage > 50%
./prom2csv.py --column-name-mapping id instance --row-id-expression 'instance' '(node_filesystem_free_bytes{env=~"dev|prod",device!~"rootfs",fstype!="tmpfs"} / node_filesystem_size_bytes{env=~"dev|prod",device!~"rootfs",fstype!="tmpfs"}) < 0.5'
Metadata
Release files for prom2csv 0.9.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| prom2csv-0.9.1.tar.gz | 6.1 kB | Without provenance | Details for prom2csv-0.9.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| prom2csv-0.9.1-py3-none-any.whl | Python 3 | none | any | Details for prom2csv-0.9.1-py3-none-any.whl |
Total release size: 11.6 kB
Release files / prom2csv-0.9.1.tar.gz
| Download URL | prom2csv-0.9.1.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8ee3435136d31ed4e7ca7c22769643df29a7cdabb22e153fe5a818933b5173f1
|
|
BLAKE2b-256 checksum How to use checksums |
38ad0c94343e8d5be27fffdb41c3aefe8f21f5b24099fd498123490c77bd2064
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Release files / prom2csv-0.9.1-py3-none-any.whl
| Download URL | prom2csv-0.9.1-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7ec7b0dc48d73343e708c7818f49ac37a92e0ebf1189f0dc43894884bf11425b
|
|
BLAKE2b-256 checksum How to use checksums |
1dd5aa5d553579f6e89864b360951b4c15074e4f1f4ef77687860687a5148e04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Security for prom2csv 0.9.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.