【问题标题】:How to get the current server timestamp using spring boot actuator如何使用弹簧启动执行器获取当前服务器时间戳
【发布时间】:2019-07-11 18:27:12
【问题描述】:

我正在使用 spring boot 执行器来监控我的微服务的运行状况。我还需要服务器当前时间戳。 info/ 只返回构建的时间戳。相反,我想要服务器当前的时间戳。

【问题讨论】:

  • “当前时间戳”是什么意思?服务器的系统时间?
  • 是的。我的意思是服务器时间

标签: java spring-boot-actuator


【解决方案1】:

https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#production-ready-application-info-custom

您可以通过提供额外的InfoContributor 来简单地添加您需要的值。

@Component
public class TimeInfoContributor implements InfoContributor {

    @Override
    public void contribute(Info.Builder builder) {
        // Calculate your desired timeValue here.
        builder.withDetail("time", timeValue);
    }

}

【讨论】:

  • 谢谢迈克尔。我还需要服务器时间到执行器/健康端点。在自定义健康端点时,我所能找到的只是发送服务是否启动/关闭。此外,我还想返回服务器时间。有什么方法可以实现
  • 您还可以将自定义详细信息添加到任何健康端点。见docs.spring.io/spring-boot/docs/current/api/org/springframework/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-21
  • 1970-01-01
  • 1970-01-01
  • 2020-09-03
  • 2016-12-26
  • 1970-01-01
相关资源
最近更新 更多