服务端性能监控—— Spring Boot Actuator

服务端性能监控—— Spring Boot Actuator介绍

监控后台服务是否正常运行,有很多指标需要我们关注,一是机器本身的状态,比如CPU利用率、磁盘使用率、内存、网络等,通过这些来判断机器是否运行正常。这些是属于机器指标,一般云服务商会提供。今天我们要分析的是程序的性能指标,因为即使机器正常,但程序可能已经挂了。

对java程序来说,我们主要关注JVM的状态是否正常,希望能把一般通过jconsole得到的数据能通过监控自动获取出趋势图。此时我们就需要一个非常强大的模块:Spring Boot Actuator 来帮助获取到应用的统计信息。Spring Boot Actuator不止能提供jvm相关信息,也能对应用相关依赖做健康检查,功能十分强大,接入非常简单。

给一个Maven项目增加Actuator

使用如下依赖

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

介绍Endpoints

Endpoints是Actuator中的端点,每个端点都提供了不同的功能,Actuator内置了很多Endpoints,配置就可以使用。

/health提供了应用健康信息。

/info提供了应用基本信息。

/logfile可以直接查看日志文件等等。

同时我们也可以定义自己的Endpoints,以此来自定义想要的监控项。

查看所有endpoints

启动项目,访问http://localhost:8080/actuator查看,你应该能看到如下列表

{
   
    "_links":{
   
        "self":{
   
            "href":"http://localhost:7777/actuator",
            "templated":false
        },
        "auditevents":{
   
            "href":"http://localhost:7777/actuator/auditevents",
            "templated":false
        },
        "health":{
   
            "href":"http://localhost:7777/actuator/health",
            "templated":false
        },
        "env":{
   
            "href":"http://localhost:7777/actuator/env",
            "templated":false
        }
    }
}

访问/actuator获取到的是当前已开启的endpoints列表,有一些文档说很多endpoints是默认开启的,但从Spring Boot2.0之后,因为安全原因,大部分的endpoints都是默认关闭的了,需要在配置文件中手动开启。

配置endpoints的开关

在配置文件中,可以通过includeexclude配置endpoint在http或jmx中是否开启或关闭,如下。

management:
  endpoints:
    web:
      exposure:
        exclude: shutdown
        include: ["auditevents", "info", "health", "metrics", "loggers", "logfile", "httptrace", "env", "flyway", "mappings",
        "scheduledtasks", "prometheus"]
    jmx:
      exposure:
        include: * #所有
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值