为 Spring Boot 健康检查监控配置 Prometheus [英] Configuring Prometheus for Spring Boot health check monitoring

查看:242
本文介绍了为 Spring Boot 健康检查监控配置 Prometheus的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们几乎没有实现健康检查的 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 指标,例如:

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:

这篇关于为 Spring Boot 健康检查监控配置 Prometheus的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆