prometheus + grafana 对 springboot 项目进行监控
发布于 2024-07-21
1381
版权声明
我们非常重视原创文章,为尊重知识产权并避免潜在的版权问题,我们在此提供文章的摘要供您初步了解。如果您想要查阅更为详尽的内容,访问作者的公众号页面获取完整文章。
BUG弄潮儿
扫码关注公众号
扫码阅读
手机扫码阅读
1. Prometheus接入Spring Boot
安装Prometheus后,需要配置其prometheus.yml文件以监控Spring Boot项目。默认配置文件已经设定了监控Prometheus本身的job_name。为了监控Spring Boot,应该增加一个新的job_name,指定metrics_path为/actuator/prometheus,并设置targets为Spring Boot应用的地址和端口。
2. 访问Prometheus
通过访问http://127.0.0.1:9090/,可以看到监控的Spring Boot端点列表,并能在首页查询到各种指标,例如custom_http_request_time_seconds_count。
3. Grafana接入Prometheus
在Grafana中访问http://127.0.0.1:3000/,进行数据源配置。添加Prometheus作为数据源,设置名称和服务地址以连接到Prometheus。
4. 配置仪表盘
在Grafana中添加新面板并配置查询,例如使用查询语句sum by(api) (rate(custom_http_request_time_seconds_count{job="custom_spring_boot", api="/order"}[5m]))来获取平均时间。设置完成后保存,以在仪表盘上显示监控结果。
BUG弄潮儿
BUG弄潮儿
扫码关注公众号