我们几乎没有实现健康检查的 Spring Boot 应用程序。这些检查的响应已根据@Thiru 的 suggestion 更改为 JSON 格式。 .我现在得到以下回复:
Prometheus 服务器在 Ubuntu 实例上运行。需要监控的spring boot服务运行在windows server 2016上,看到this后,我在windows server上安装了blackbox-exporter(版本0.12.0.windows-amd64
)邮政。
以下更改是在 172.16.x.yz
中的客户端(Windows 服务器 IP: 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"}'
...
...
在 Prometheus 服务器上,以下是
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.
在客户端和服务器上进行上述更改后,当我重新启动
blackbox-exporter
和 prometheus
,我看到普罗米修斯总是显示 State
即使导出商正在监控的两项服务出现故障,也会保持正常运行。似乎 Prometheus 正在显示 blackbox-exporter
的状态而不是为了服务。我有什么建议可以解决这个问题吗?最佳答案
我建议使用某种工具来帮助作为普罗米修斯导出商导出 Spring 健康。基本上,导出器有助于使用 jsonpath 将 json 数据从 http url 转换为 prometheus 指标,例如:
关于spring-boot - 为 Spring Boot 健康检查监控配置 Prometheus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52806576/