Prometheus:发现服务地址为空?

Prometheus: Address of discovered service is empty?

我编写了一个非常基本的 Spring Boot 2 应用程序,它连接到 Zookeeper 以进行服务发现(通过使用 spring-cloud-starter-zookeeper-discovery)。

应用程序在 /services/example-service 注册并具有以下值:

{"name":"example-service","id":"cb14ad15-4d33-4f1c-a420-29980ddf2fa8","address":"bf3fb9191373","port":8080,"sslPort":null,"payload":{"@class":"org.springframework.cloud.zookeeper.discovery.ZookeeperInstance","id":"application-1","name":"example-service","metadata":{}},"registrationTimeUTC":1524120820273,"serviceType":"DYNAMIC","uriSpec":{"parts":[{"value":"scheme","variable":true},{"value":"://","variable":false},{"value":"address","variable":true},{"value":":","variable":false},{"value":"port","variable":true}]}}

该地址是一个 id,因为我已经使用 Docker 部署了堆栈。

我的 Prometheus 配置如下所示:

- job_name: 'example-service'
  metrics_path: '/actuator/prometheus'
  serverset_sd_configs:
  - servers:
    - zookeeper:2181
    paths:
    - '/services/example-service'

Prometheus 的服务发现页面显示了以下发现的标签:

__address__=":0"  __meta_serverset_endpoint_host=""  __meta_serverset_endpoint_port="0" __meta_serverset_path="/services/example-service/cb14ad15-4d33-4f1c-a420-29980ddf2fa8"  __meta_serverset_shard="0"  __meta_serverset_status="" __metrics_path__="/actuator/prometheus"  __scheme__="http"  job="example-service"

知道为什么 __address__:0 吗?

服务器集发现是 particular way of using Zookeeper, which your application is not following. In this case you probably want file service discovery

Serverset 使用配置如下:

{"serviceEndpoint":{"host":"localhost","port":9100},"additionalEndpoints":{},"status":"ALIVE"}