SpringBoot Actuator指标监控

发布于:2022-10-12 ⋅ 阅读:(198) ⋅ 点赞:(0)

简介

未来每一个微服务在云上部署以后,我们都需要对其进行监控、追踪、审计、控制等。SpringBoot就抽取了Actuator场景,使得我们每个微服务快速引用即可获得生产级别的应用监控、审计等功能。

监控的意义:

监控服务状态是否宕机
监控服务运行指标(内存、虚拟机、线程、请求等)
监控日志
管理服务(服务下线)

pom.xml引入场景
在这里插入图片描述

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

在application.yml配置指标监控相关设置

management:
  endpoints:
    enabled-by-default: true #暴露所有端点信息,false是关闭
    web:
      exposure:
        include: '*'  #以web方式暴露
        
#开启与禁用Endpoints(端点)
  endpoint:
    health: #开启health端点
      show-details: always  #显示详细信息
      enabled: true
    info:   #开启info端点
      enabled: true
    beans:  #关闭beans端点
      enabled: false

访问路径:http://localhost:8080/actuator
http://localhost:8080/actuator/beans
http://localhost:8080/actuator/health
http://localhost:8080/actuator/metrics
等 http://localhost:8080/actuator/**访问路径

定制Endpoint

/**
 * 自定义端点
 */
@Component
@Endpoint(id = "container")
public class myEndpoint {
    
    @ReadOperation  //读
    public Map getDockerInfo(){
        return Collections.singletonMap("info","docker started...");
    }

    @WriteOperation  //写
    private void restartDocker(){
        System.out.println("docker restarted....");
    }

}

可通过http://localhost:8080/actuator/container访问,@Endpoint(id = “container”)为端点名称
SpringBoot Actuator指标监控:可参考
可视化:可参考

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到