如何以编程方式从spring-boot-actuator获取指标?
我们在生产中有spring应用。它不是Spring-boot。我发现这个职位就如何在非Spring Boot应用程序使用Spring Boot器。
但是,对我们的要求是从/ metrics端点聚合数据并对其进行一些分析并报告状态指示器。
例如,我们可能使用堆参数
{"heap.committed":480768,"heap.init":262144,"heap.used":294461,"heap":3728384,"threads.peak":37}
来指示应用程序的状态-
FATAL,WARN或HEALTHY。
这只是一个例子。我们的要求比较复杂。实际上,我们已经有一个status
endpoint要添加更多信息的地方(基于的数据/metrics
和的/health
端点spring-boot-actuator
)。
我想实现此目的的一种方法是对应用程序进行REST调用,/metrics
并/health
在其中进行调用,收集数据,对其进行汇总并返回响应。我不建议这样做。
如果有一个可以直接提取这些参数的bean,我将对其进行自动布线并在需要时即时进行计算。(实际上,我将安排定期进行计算)。
我对从返回的所有属性感兴趣/metrics
。同时,我也有兴趣从以下/health
。
{"diskSpace":{"status":"UP","free":386186194944,"threshold":10485760}}
我应该自动连接哪些bean并免费获得这些属性!
谢谢
这个帖子有@Autowired MetricRepository
。但是由于某种原因,它仅返回自定义计数器属性。它不返回堆,内存信息等,例如:
Reporting metric counter.calls.get_greeting=4 Reporting metric
counter.calls.get_greeting.1=1 Reporting metric counter.calls.get_greeting.2=1
Reporting metric counter.calls.get_greeting.3=1 Reporting metric
counter.calls.get_greeting.4=1 Reporting metric
counter.status.200.greeting.number=4 Reporting metric counter.status.404.star-
star=1
回答:
的输出由/metrics
产生MetricsEndpoint
。它可以作为Bean获得@Autowired
。调用invoke
它可以为您提供所需的数据。
您可以做同样的/health
使用HealthEndpoint
。
以上是 如何以编程方式从spring-boot-actuator获取指标? 的全部内容, 来源链接: utcz.com/qa/416656.html