devopstoday11 / prometheus-csvplot

Scrape Prometheus metrics, export them as csv files and generate plots

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Quickly run queries on prometheus and view results on csv and pdf reports with plots.

Usage

Metrics config

This file contains 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

Run on local machine

Run prometheus and node exporter with docker-compose:

docker-compose up -d 

Generate csv files from prometheus metrics

Prerequisites:

  • python v3
  • 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 <prometheus_url> <dateStart RFC 3339 | unix_timestamp> <dateEnd RFC 3339 | unix_timestamp> <custom_metrics_file_name>

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

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

About

Scrape Prometheus metrics, export them as csv files and generate plots


Languages

Language:Python 98.7%Language:Shell 1.3%