簡體   English   中英

彈簧啟動執行器運行狀況端點

[英]Spring boot actuator health endpoint

我已經創建了一個PostgreSQL運行狀況指示器,如下所示:

@Component
public class PostgresHealthIndicator extends AbstractHealthIndicator {

    @Autowired
    DataSource postgresDataSource;

    public DataSourceHealthIndicator dbHealthIndicator() {
        DataSourceHealthIndicator indicator = new DataSourceHealthIndicator(postgresDataSource);
        return indicator;
    }

    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        Health h = dbHealthIndicator().health();
        Status status = h.getStatus();
        if (status != null && "DOWN".equals(status.getCode())) {
            builder.down();
        } else {
            builder.up();
        }
    }
}

在我的Application.java中,我正在掃描此軟件包中的該組件:

@ComponentScan({"com.bp.health"})

在我的application.properties中,我進行了以下設置:

endpoints.health.sensitive=false
endpoints.health.id=health
endpoints.health.enabled=true

當我點擊{url} / health時,我看到:

{“狀態”:“ DOWN”}

我需要怎么做才能顯示自定義健康指標?

您需要進行身份驗證才能查看所有詳細信息。 或者,您可以設置

management.security.enabled=false
endpoints.health.sensitive=false

查看未認證的完整內容

有關此的更多信息,請參見: 生產就緒監控

你為什么要做所有這些? 該代碼甚至不會編譯,並且Spring Boot會默認檢查您的數據源。 如果僅看到狀態,那是因為您未通過身份驗證,請在文檔中查看此表獲取更多詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM