3

我启用了 /health 端点,但我只是不希望它列出 Consul 在同一台机器上监控的所有服务。

这是我的 application.properties:

# Enable just the health endpoint.
endpoints.health.enabled=true

# Disable all default endpoints and Spring Cloud endpoints.
endpoints.enabled=false
endpoints.consul.enabled=false
endpoints.pause.enabled=false
endpoints.resume.enabled=false
endpoints.refresh.enabled=false
endpoints.restart.enabled=false
endpoints.shutdown.enabled=false
endpoints.env.enabled=false

management.health.db.enabled=false
management.health.diskspace.enabled=false
management.health.defaults.enabled=false

...这就是 /health 当前发出的内容:

$ curl -o- http://localhost:8080/health | python -m json.tool
{
    "consul": {
        "advertiseAddress": "10.10.10.10", 
        "bindAddress": "10.10.10.10", 
        "clientAddress": "127.0.0.1", 
        "datacenter": "DC", 
        "domain": "consul.", 
        "nodeName": "mynode", 
        "services": {
            "myservice1": [
                "tag1"
            ], 
            "myservice2": [
                "tag1", 
                "tag2"
            ]
        }, 
        "status": "UP"
    }, 
    "description": "Spring Cloud Consul Discovery Client", 
    "discoveryComposite": {
        "description": "Spring Cloud Consul Discovery Client", 
        "discoveryClient": {
            "description": "Spring Cloud Consul Discovery Client", 
            "services": [
                "myservice1",
                "myservice2"
            ], 
            "status": "UP"
        }, 
        "status": "UP"
    }, 
    "status": "UP"
}

我不介意and"description": "Spring Cloud Consul Discovery Client"下的其余内容是我不想暴露的。"consul""discoveryComposite"/health

什么可以将这些信息添加到此端点?

4

3 回答 3

11

它来自 Spring Cloud Commons。

禁用discoveryComposite设置属性spring.cloud.discovery.client.composite-indicator.enabled=false

设置management.health.consul.enabled=false为另一个。

于 2017-01-12T19:15:08.657 回答
3

在 SpringBoot 2.3.x 中禁用复合输出

  • 只需使用以下密钥:
spring:
  cloud:
    discovery:
      client:
        composite-indicator:
          enabled: false
  • 之后,发现的输出并没有打印在 healthcheck 的状态中
于 2021-09-20T10:39:42.823 回答
2

为可能遇到相同问题的其他人回答我自己的问题:management.security.enabled=false在我没有注意到的应用程序启动期间在其中一个 Spring 配置文件中设置。根据此处的文档:http: //docs.spring.io/spring-boot/docs/current/reference/html/production-ready-monitoring.html#production-ready-health-access-restrictions我需要设置endpoints.health.sensitive=true为只报告状态。添加此令牌解决了该问题。

于 2017-04-05T04:40:33.383 回答