spring-boot-发布自定义度量信息

1、 CounterService(inc,dec,reset)与GaugeService(submit更新)

@RestController
public class AppleCtrl {

    @Autowired
    private CounterService counterService;
    @Autowired
    private GaugeService gaugeService;
    
    @RequestMapping("/test.do")
    public String ss(){
        counterService.increment("jasmine.count");
        gaugeService.submit("jasmine.time",System.currentTimeMillis());
        return "ok";
    }
}

查看:http://localhost/metrics/counter.jasmine.count
http://localhost/metrics/gauge.jasmine.time
2、自定义

@Component
public class AppleMetrics implements PublicMetrics{

    @Autowired
    private ApplicationContext context;
    
    @Override
    public Collection<Metric<?>> metrics() {
        List<Metric<?>> metrics = new ArrayList<Metric<?>>();
        metrics.add(new Metric<Number>("jasmine.spring.bean.count",context.getBeanDefinitionCount()));
        return metrics;
    }

}


访问:http://localhost/metrics/jasmine.spring.bean.count

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在前后端分离的架构中,前端和后端是独立部署和运行的,因此需要在后端项目中使用spring-boot-starter-actuator来对后端应用进行监控和管理。前端项目可以通过HTTP接口调用actuator的端点来获取应用程序的信息。 首先,你需要在后端的Spring Boot项目中添加spring-boot-starter-actuator的依赖。在你的pom.xml文件中,添加以下依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> ``` 然后,你需要在应用程序的配置文件(例如application.properties或application.yml)中配置actuator的相关属性。例如,你可以设置管理端点的访问路径和权限: ```properties # 设置管理端点的访问路径 management.endpoints.web.base-path=/actuator # 开启所有的管理端点,默认只开启了/health和/info management.endpoints.web.exposure.include=* ``` 配置完成后,你可以启动后端应用程序,并通过HTTP请求访问actuator提供的各种端点来获取应用程序的信息。例如: - `/actuator/health`:应用程序的健康状况 - `/actuator/info`:应用程序的信息 - `/actuator/metrics`:度量指标信息 - `/actuator/env`:运行时环境信息 你可以根据具体需求,选择性地暴露和配置这些端点。同时,你还可以自定义自己的管理端点,以满足特定的监控和管理需求。 在前端项目中,你可以通过发送HTTP请求来调用这些管理端点,获取后端应用程序的信息,从而实现前端对后端应用程序的监控和管理功能。 希望这些信息对你有帮助!如果还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值