将邮件健康指标排除在默认 /执行器 /健康端点中?

发布于 2025-02-12 17:20:59 字数 561 浏览 0 评论 0原文

我有一个Spring Boot应用程序,该应用程序使用执行器具有/执行器/Health端点。我最近在应用程序中添加了Spring-boot-starter-sail,该应用程序自动为邮件服务器添加了健康指示器,因此/cartuator/health如果邮件服务器将报告下降。

我想从/areatuator/health本身中删除该健康指标,并拥有另一个端点/coduator/health/sail/mail以获取完整状态。

我知道我可以通过添加此属性来创建额外的端点:

management.endpoint.health.group.mail.include=mail

但是如何从默认端点删除邮件

我尝试使用Management.health.mail.enabled = false,但是我无法在/cartuator/health/mail endpoint中使用它。

I have a Spring Boot application that uses the actuator to have a /actuator/health endpoint. I recently added spring-boot-starter-mail to the application which automatically adds a health indicator for the mail server so the /actuator/health will report DOWN if the mail server is down.

I would like to remove that health indicator from /actuator/health itself and have another endpoint /actuator/health/mail to get the full status.

I know I can create the extra endpoint by adding this property:

management.endpoint.health.group.mail.include=mail

But how do I remove mail from the default endpoint?

I tried using management.health.mail.enabled=false, but then I can't use it in the /actuator/health/mail endpoint anymore.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

错々过的事 2025-02-19 17:20:59

这应该有效:

1/创建此健康端点扩展类:

public class HealthEndpointCustomExtension extends HealthEndpointWebExtension {

    public HealthEndpointCustomExtension(HealthContributorRegistry registry, HealthEndpointGroups groups, Duration slowIndicatorLoggingThreshold) {
        super(registry, groups, slowIndicatorLoggingThreshold);
    }

    @Override
    protected HealthComponent aggregateContributions(ApiVersion apiVersion, Map<String, HealthComponent> contributions, StatusAggregator statusAggregator, boolean showComponents, Set<String> groupNames) {
        Map<String, HealthComponent> newContributions = new HashMap<>(contributions);
        newContributions.remove("mail");
        return super.aggregateContributions(apiVersion, newContributions, statusAggregator, showComponents,  groupNames);
    }

congregateContributions 方法,其名称建议,对每个健康企业进行了汇总。通过覆盖此方法,您可以从汇总结果中删除“邮件”贡献者。

2/在配置类中声明您的自定义组件:

    @Bean
    HealthEndpointWebExtension healthEndpointWebExtension(HealthContributorRegistry healthContributorRegistry, HealthEndpointGroups groups, HealthEndpointProperties properties) {
        return new HealthEndpointCustomExtension(healthContributorRegistry, groups, properties.getLogging().getSlowIndicatorThreshold());
    }

This should works :

1/ Create this Health endpoint extension class :

public class HealthEndpointCustomExtension extends HealthEndpointWebExtension {

    public HealthEndpointCustomExtension(HealthContributorRegistry registry, HealthEndpointGroups groups, Duration slowIndicatorLoggingThreshold) {
        super(registry, groups, slowIndicatorLoggingThreshold);
    }

    @Override
    protected HealthComponent aggregateContributions(ApiVersion apiVersion, Map<String, HealthComponent> contributions, StatusAggregator statusAggregator, boolean showComponents, Set<String> groupNames) {
        Map<String, HealthComponent> newContributions = new HashMap<>(contributions);
        newContributions.remove("mail");
        return super.aggregateContributions(apiVersion, newContributions, statusAggregator, showComponents,  groupNames);
    }

aggregateContributions method, has its name suggests, does an aggregation of each HealthContributor. By overriding this method you can remove the 'mail' contributor from the aggregated result.

2/ Declare your custom component in a configuration class :

    @Bean
    HealthEndpointWebExtension healthEndpointWebExtension(HealthContributorRegistry healthContributorRegistry, HealthEndpointGroups groups, HealthEndpointProperties properties) {
        return new HealthEndpointCustomExtension(healthContributorRegistry, groups, properties.getLogging().getSlowIndicatorThreshold());
    }
天邊彩虹 2025-02-19 17:20:59

您也可以做Management.health.mail.enabled = false。另请注意,执行器/健康/邮件将返回404,因为它确实已被禁用

You can also do management.health.mail.enabled=false. Also note that actuator/health/mail will return 404 because it has really been disabled

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文