https://github.com/hifly81/prometheus-csvplot
Scrape Prometheus metrics, export them as csv files and generate plots
https://github.com/hifly81/prometheus-csvplot
csv grafana kubernetes openshift orca pandas pdf plotly prometheus python
Last synced: 3 months ago
JSON representation
Scrape Prometheus metrics, export them as csv files and generate plots
- Host: GitHub
- URL: https://github.com/hifly81/prometheus-csvplot
- Owner: hifly81
- License: apache-2.0
- Created: 2020-02-19T16:00:30.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-19T07:22:44.000Z (about 1 year ago)
- Last Synced: 2025-03-17T01:35:05.829Z (7 months ago)
- Topics: csv, grafana, kubernetes, openshift, orca, pandas, pdf, plotly, prometheus, python
- Language: Python
- Homepage:
- Size: 43 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Quickly run queries on prometheus and view results as csv files. Extract pdf reports with plots.
## Usage
### Configuration
A configuration file is required with a list of Prometheus metrics to be collected.
By default, metrics are listed in file: _config/metrics.txt_
If you want to use a custom metrics file, place it in config directory:
e.g. _config/metrics_haproxy.txt_Example of a metrics config file:
```
rate(go_gc_duration_seconds[5m])
scrape_duration_seconds
prometheus_http_request_duration_seconds_bucket{handler="/api/v1/query_range", instance="localhost:9090", job="prometheus", le="0.1"}
sum(rate(http_server_requests_seconds_count{instance="application:8080", status!~"5.*"}[5m]))
```## How to use
You need a **prometheus** instance running.
File _docker-compose_ in root folder can be used to run a prometheus instance on port 9090 and node exporter:
```
docker-compose up -d
```### Generate csv files from prometheus metrics
This component is written in **python v3**, and you need some python libs to be installed on your local machine:
- python modules: _jproperties, requests, pandas, pillow, plotly, kaleido_
you can install those with _pip3_:
```
pip3 install jproperties requests pandas pillow plotly kaleido
```### Generate csv files from prometheus metrics
```
python3 export_csv.py
```Example of usage:
```
python3 export_csv.py http://localhost:9090 2022-12-14T10:00:00Z 2022-12-14T11:30:00Z metrics.txt
```A new directory named csv/metrics_%Y-%m-%d-%H:%M:%S with the csv files will be generated.
### Create a pdf report with plots from csv files
```
python3 plot.py
```Example of usage:
```
python3 plot.py csv/metrics_2022-12-14_11:20:20
```A new pdf file *report.pdf* will be generated in directory csv/metrics_%Y-%m-%d-%H:%M:%S
## Teardown
```
docker-compose down --volumes
```