Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to integrate Prometheus and Grafana

Shulou Source: shulou.com Published: 2022-06-01 09:18:03 10月01日 Update

This article will explain in detail how Prometheus and Grafana are integrated. Xiaobian thinks it is quite practical, so share it with you for reference. I hope you can gain something after reading this article.

profile

Grafana is a visual dashboard with beautiful icons and layouts, a full-featured dashboard and graphical editor, and default support for CloudWatch, Graphite, Elasticsearch, InfluxDB, Mysql, PostgreSQL, Prometheus, OpenTSDB, etc. as data sources.

Install Grafana Install Grafanadocker run -d --name=grafana -p 3000:3000 grafana/grafana via docker container

Visit http://localhost:3000/account admin password admin, login interface is as follows:

Add Prometheus data sources

Click "Add data soure" and select "Prometheus" to display the Add interface:

Then fill in Name : prometheus-datasets, URL : prometheus server address, other configurations default, and then save.

Configure Creating a Dashboard

Click on the "+" icon to create a Dashbaord

Click the Save icon to save Dashboard, use default Folder, name Dashboard http-simulator

Display request rate

Click on the Add panel icon, click on Choose Visualization to select the type of visualization.

Click on "Visualization" Select "Graph"

Adjust Legend to show minimum, maximum, average, current, total of all values returned by a metric query

Click "General" to modify "Title" to "Request Rate",

Click on "Queries" and enter the Prometheus expression

sum(rate(http_requests_total{job="http-simulator"}[5m]))

You can see that the request rate graph has been displayed, and the minimum, maximum, average, current, and total values are also displayed.

Click the Save icon at the top right to save changes to Dahsboard.

Show real-time error rates

To demonstrate data visibility, change the error rate of http-simulator service to 40%

curl -H 'Content-Type: application/json' -X PUT -d '{"error_rate": 1}' http://127.0.0.1:8080/error_rate

With the above configuration experience, I won't say too much here.

Click "Add panel icon" to add a new Pannel, click "Choose Visualization" to select the type of visualization chart, click "Singlestat" icon to add a Singlestat, modify Panel Title to Live Error Rate

Click on "Queries" and enter the Prometheus expression

sum(rate(http_requests_total{job="http-simulator", status="500"}[5m])) / sum(rate(http_requests_total{job="http-simulator"}[5m]))

Adjust the display unit to None->percent(0.0-1.0), then adjust the display value (currently average) to the current value (now): Options->Value->Stat, set to Current

Add threshold and color, under Coloring, check Value, set Threshold to 0.01, 0.05, indicating

Green: 0-1%

Orange: 1-5%

Red: >5%

To add a gauge effect, under Gauge, check Show and set Max to 1

Finally, don't forget to "Control + S" or click the "Save" icon at the top right to save the modified Dashbaord.

Show Top requested endpoints

Add a new Pannel, click "Choose Visualization" to select the type of visualization chart, click "Table" icon to add a Table, modify Panel Title to Top requested

Click on "Queries" and enter the Prometheus expression

sum(rate(http_requests_total{job="http-simulator"}[5m])) by (endpoint)

Reduce data items in the table, check Instant to show only current values

Hide the Time column, under Column Sytle, Apply to columns named as Time, and set Type->Type to Hidden

Rename the Value column, add a Column Style, Apply to columns named to Value, and set Column Header to Requests/s

Click the Requests/s header in the table to sort the data according to endpoint activity.

Save the modified Dashbaord.

About "Prometheus and Grafana how to integrate" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Tags: Icons data selection visualization charts articles types expressions adjustments inputs configurations maximum minimum gauges dashboards averages data sources more maximum interface Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Huawei Xiaomi Shulou Technology Shulou Information