Spring boot 为Spring Boot健康检查监控配置Prometheus
我们很少有Spring引导应用程序实现了健康检查。这些检查的响应根据@Thiru的更改为JSON格式。我现在得到以下答复: 普罗米修斯服务器正在Ubuntu实例上运行。必须监控的Spring引导服务正在Windows server 2016上运行。在看到帖子后,我已经在windows服务器上安装了blackbox exporter(版本Spring boot 为Spring Boot健康检查监控配置Prometheus,spring-boot,prometheus,Spring Boot,Prometheus,我们很少有Spring引导应用程序实现了健康检查。这些检查的响应根据@Thiru的更改为JSON格式。我现在得到以下答复: 普罗米修斯服务器正在Ubuntu实例上运行。必须监控的Spring引导服务正在Windows server 2016上运行。在看到帖子后,我已经在windows服务器上安装了blackbox exporter(版本0.12.0.windows-amd64) 在blackbox.yml中的客户端(具有IP:172.16.x.yz的Windows服务器)上进行了以下更改: m
0.12.0.windows-amd64
)
在blackbox.yml
中的客户端(具有IP:172.16.x.yz的Windows服务器)上进行了以下更改:
modules:
http_2xx:
prober: http
http:
http_post_2xx:
prober: http
timeout: 5s
http:
method: POST
headers:
Content-Type: application/json
body: '{"status": "UP"}'
...
...
...
...
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.
在Prometheus服务器上,以下是Prometheus.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"}'
...
...
...
...
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.
在客户端和服务器上进行上述更改后,当我重新启动blackbox exporter
和prometheus
时,我看到prometheus始终显示状态
,即使exporter正在监视的两个服务停止运行。普罗米修斯似乎正在显示黑匣子导出器的状态,而不是服务的状态。有什么建议我可以解决这个问题吗
我建议使用一些工具,以普罗米修斯出口商的身份导出spring health。基本上,exporter可以帮助使用jsonpath将json数据从http url转换为prometheus度量,如:
在我看来,普罗米修斯的目标实际上表明刮伤目标处于上升或下降状态。这与healthcheck端点状态无关。您只能在probe_success metrics(1向上,0向下)中检查healthcheck端点状态。您可以查看以下屏幕截图。
对不起,我的英语不好
谢谢您的回复。请检查我的帖子中的更新部分,您是否在spring boot中启用了执行器?它的健康端点是JSON。上面提到的两种解决方案都只适用于JSON输出。在这两种情况下都会生成警报。要制作prometheus spring boot exporter
/prometheus jsonpath exporter
,您必须在应用程序中使用执行器。请遵循(此)[链接中的步骤。这将为您提供/health
端点,prometheus spring boot exporter
将从中删除度量。感谢您的输入。我们将尝试修复它