【问题标题】:Spring boot actuator metrics for Prometheus in Consul ConnectConsul Connect 中 Prometheus 的 Spring Boot 执行器指标
【发布时间】:2021-11-12 01:40:47
【问题描述】:

我有一个 Spring Boot 应用程序在启用 Consul Connect 的 Nomad 集群中运行。

network {
  mode = "bridge"
}

service {
  name = "api"
  port = "9966"

  connect {
    sidecar_service {}
  }
}

没有定义端口映射,API 只能在 consul 服务网格内通过代理访问。现在我让 prometheus 在同一个集群中运行。 prometheus 如何发现单个 API 实例并从中提取指标。我使用了以下配置。但是如果没有主机级别的映射端口,它就无法访问单个 API 实例。

- job_name: 'actuator'
    metrics_path: /api/actuator/prometheus
    consul_sd_configs:
    - server: '{{ env "NOMAD_IP_prometheus_ui" }}:8500'
      services: ['api']

如何解决这个问题?从在没有主机端口映射的服务网格中运行的 Spring Boot 应用程序中抓取指标的一般做法是什么?

【问题讨论】:

    标签: spring-boot prometheus consul service-discovery


    【解决方案1】:

    终于找到了。 Nomad 可以选择通过另一个 sidecar 代理公开特定端点,而无需 mTLS 身份验证。此选项的用例专门用于运行状况检查或指标。

    https://www.nomadproject.io/docs/job-specification/expose#expose-examples

    connect 中的 expose 节有助于实现这一点。

    connect {
            sidecar_service {
              proxy {
                expose {
                  path {
                    path             =  "/actuator/prometheus"
                    protocol         =  "http"
                    local_path_port  =  9966
                    listener_port    =  "metrics"
                  }
                }
              }
            }
          }
    

    【讨论】:

    • 公开路径参数在 consul.io/docs/connect/registration/…> 也有更详细的说明。我应该注意,这些端口是使用为应用程序的服务流量部署的同一个 sidecar 代理公开的。 Consul 不需要单独的代理进程来公开这些端口。
    猜你喜欢
    • 2018-07-23
    • 2018-11-29
    • 2015-07-04
    • 2019-08-09
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    • 2021-05-07
    • 2022-01-17
    相关资源
    最近更新 更多