Spring Boot 执行器 - 实现自定义指标 [英] Spring boot actuator - Implement custom metrics

查看:55
本文介绍了Spring Boot 执行器 - 实现自定义指标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用执行器为我的 Spring Boot Rest Web 服务实现自定义指标或统计信息,但我找不到简单的教程.例如:

I would like to implement custom metric or statistics to my spring boot rest web service using actuator but i am not able to find simple tutorials. For example:

  • 如何显示某个控制器被调用了多少次以及填充了哪些确切的参数字段?
  • 如何创建一个指标,当它的 URL 被调用时,它会运行特定的查询并返回一个带有一些结果的 json

推荐答案

对于第二点,解决方案是创建一个端点类(它可以是也可以不是休息控制器类).例如:

For point two the solution is to create an endpoint class (it can be or not a rest controller class). For example:

@Component
@RestControllerEndpoint(id = "pfm-statistics")
public class StatisticsEndpoint {
  @GetMapping(value = "/", produces = "application/vnd.openxmlformats- 
     officedocument.spreadsheetml.sheet")
  @ResponseBody
  public byte[] generateStatisticsAsExcel() {
 ...

请注意,ID 是要从 URL 调用的路径.我们也可以创建一个简单的端点,如果需要,只返回一个字符串.在这种情况下,我们可以使用@Endpoint 代替@RestControllerEndpoint 注释,作为旁注,id 应始终包含破折号

Note that the ID is the path to be called from URL. We can create a simple endpoint too and just return a string if we want. In this case instead of @RestControllerEndpoint annotation we can use @Endpoint, as a side note, the id should always contain dash

这篇关于Spring Boot 执行器 - 实现自定义指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆