为 Spring Boot 健康检查监控配置 Prometheus [英] Configuring Prometheus for Spring Boot health check monitoring
问题描述
我们几乎没有实现健康检查的 Spring Boot 应用程序.这些检查的响应已根据@Thiru 的
Prometheus 服务器在 Ubuntu 实例上运行.需要监控的Spring Boot服务在Windows server 2016上运行.我看到后在Windows server上安装了blackbox-exporter(版本0.12.0.windows-amd64
)
我建议使用某种工具来帮助导出 spring health 作为 prometheus 导出器.基本上,导出器有助于使用 jsonpath 将 json 数据从 http url 转换为 prometheus 指标,例如:
- https://github.com/project-sunbird/prometheus-jsonpath-exporter
- https://github.com/thirunar/prometheus-spring-boot-info-exporter
We have few Spring Boot applications that have health check implemented. The response for those checks was changed to JSON format based on @Thiru's suggestion. I now get the following response:
Prometheus server is running on Ubuntu instance. Spring boot services that have to be monitored are running on Windows server 2016. I have installed blackbox-exporter (version 0.12.0.windows-amd64
) on Windows server after seeing this post.
Following change was done on client (Windows server with IP: 172.16.x.yz
) side in blackbox.yml
:
modules:
http_2xx:
prober: http
http:
http_post_2xx:
prober: http
timeout: 5s
http:
method: POST
headers:
Content-Type: application/json
body: '{"status": "UP"}'
...
...
On Prometheus server, following is the content of prometheus.yml
:
...
...
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'blackbox'
metrics_path: /probe
params:
#module: [http_2xx] # Look for a HTTP 200 response.
module: [http_post_2xx] # Look for a HTTP 200 response.
static_configs:
- targets:
- http://172.16.x.yz:6300/serviceA/actuator/health
- http://172.16.x.yz:6340/serviceB/actuator/health
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 172.16.x.yz:9115 # The blackbox exporter's real hostname:port.
After making above changes on client and server, when i restart both the blackbox-exporter
and prometheus
, i see that Prometheus always shows State
as UP even if the two services that the exporter is monitoring go down. Seems Prometheus is displaying the status of the blackbox-exporter
and not for the services. Any suggestion how i can fix that?
I would recommend to use some kind of tools which helps in exporting the spring health as prometheus exporter. Basically, exporter which helps in converting json data from an http url into prometheus metrics using jsonpath like:
- https://github.com/project-sunbird/prometheus-jsonpath-exporter
- https://github.com/thirunar/prometheus-spring-boot-info-exporter
这篇关于为 Spring Boot 健康检查监控配置 Prometheus的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!