Spring Boot 自定义指标

Spring Boot 自定义指标

阅读本文需要对一些前置技术有所了解,下面列出的一些前置技术是必须要了解的。

  • Prometheus:这是一个时序数据库,我们的指标数据一般保存在这个数据库中。
  • Grafana:借助Grafana可以将Prometheus中的数据以图表的方式展示出来。
  • Micrometer:是一个用于度量应用程序性能和监控的度量库
  • spring-boot-starter-actuator:用于在 Spring Boot 应用程序中添加运行时管理和监控功能

在项目中如果希望自定义一些指标用于监控系统的运行情况,那么可以通过本文中介绍的方法来实现自定义监控指标,我们先从一个简单的例子来介绍如何实现自定义监控指标。

依赖

<dependencies>
    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-actuatorartifactId>
    dependency>
    <dependency>
        <groupId>io.micrometergroupId>
        <artifactId>micrometer-coreartifactId>
        <version>1.11.4version>
    dependency>
    <dependency>
        <groupId>io.micrometergroupId>
        <artifactId>micrometer-registry-prometheusartifactId>
        <version>1.11.4version>
    dependency>
dependencies>

实现

这里实现一个健康检查的指标收集器,如果健康检查正常返回1,如果健康检查异常返回 0

你可能感兴趣的:(spring,boot,java,指标)