Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to integrate Prometheus and Grafana

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report