spring-boot - 为 Spring Boot 健康检查监控配置 Prometheus

标签 spring-boot prometheus

我们几乎没有实现健康检查的 Spring Boot 应用程序。这些检查的响应已根据@Thiru 的 suggestion 更改为 JSON 格式。 .我现在得到以下回复:

enter image description here

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-exporterprometheus ,我看到普罗米修斯总是显示 State即使导出商正在监控的两项服务出现故障,也会保持正常运行。似乎 Prometheus 正在显示 blackbox-exporter 的状态而不是为了服务。我有什么建议可以解决这个问题吗?

enter image description here

最佳答案

我建议使用某种工具来帮助作为普罗米修斯导出商导出 Spring 健康。基本上,导出器有助于使用 jsonpath 将 json 数据从 http url 转换为 prometheus 指标,例如:

  • https://github.com/project-sunbird/prometheus-jsonpath-exporter
  • https://github.com/thirunar/prometheus-spring-boot-info-exporter
  • 关于spring-boot - 为 Spring Boot 健康检查监控配置 Prometheus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52806576/

    相关文章:

    java - 从外部 jar 中包含 Spring 上下文找不到服务

    将 Spring Boot Starter Web 依赖项与 Mongo Driver 3.11.0 一起使用时出现 java.lang.NoSuchMethodError

    java - 自定义权限评估器 Spring

    java - 忽略在 yaml 配置中为 spring boot admin 应用程序指定的斜杠字符

    grafana - 普罗米修斯:从标签值中提取子字符串?

    普罗米修斯 - 不允许多对多匹配

    java - 分离实现的最佳方法

    yaml - Loki 没有提醒 Alertmanager

    Prometheus 添加指标时清空查询结果

    docker - Openshift监控-cAdvisor + Prometheus-Docker