我编写了一个非常基本的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部署了堆栈。
我的普罗米修斯配置如下所示:
- 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
?
答案 0 :(得分:1)
Serverset发现是particular way of using Zookeeper,您的应用程序没有关注。在这种情况下,您可能需要file service discovery。
答案 1 :(得分:0)
Serverset 使用配置如下:
{"serviceEndpoint":{"host":"localhost","port":9100},"additionalEndpoints":{},"status":"ALIVE"}