我的Spring Boot应用程序的/ health端点发出有关在同一台机器上运行的Consul服务器的所有信息。如何禁用此功能?

时间:2017-01-12 12:35:36

标签: spring-boot spring-cloud spring-boot-actuator spring-cloud-consul

我启用了/ 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

......这就是健康目前正在发出的:

$ 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"
}

我不介意"description": "Spring Cloud Consul Discovery Client",但"consul""discoveryComposite"下的其他内容是我不希望为{{1}公开的内容}。

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

2 个答案:

答案 0 :(得分:4)

它来自Spring Cloud Commons。

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

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

答案 1 :(得分:1)

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