SpringBoot项目启运行状态监控Actuator

1. 在项目pom中加入Actuator依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.zjw</groupId>
  <artifactId>spring-boot-study</artifactId>
  <version>1.0-SNAPSHOT</version>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.16.RELEASE</version>
  </parent>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
  </dependencies>
</project>

2. 在application.yml中加入Actuator端口等信息

spring:
  application:
    name: spring-boot-study
management:
  port: 9000
  security:
    enabled: false

SpringBoot 1.5.x之后默认开启了Actuator的安全认证,为了在浏览器上展示效果,不做验证,所以将management.security.enabled置为false.

Actuator提供了13个API接口,用于监控运行状态的SpringBoot的状态,如下:

类型API接口描述
GEThttp://localhost:9000/autoconfig自动配置报告,记录了哪些自动配置条件通过了,哪些没有通过
GEThttp://localhost:9000/configprops描述配置属性如何注入Bean
GEThttp://localhost:9000/beans描述应用程序上下文中的全部Bean,以及他们之间的关系
GEThttp://localhost:9000/dump获取线程活动的快照
GEThttp://localhost:9000/env获取全部环境变量
GEThttp://localhost:9000/env/{name}根据名称获取指定的环境变量
GEThttp://localhost:9000/health应用程序健康指数
GEThttp://localhost:9000/info获取应用程序的信息
GEThttp://localhost:9000/mappings描述全部的URI路径,以及他们和控制器(包括actuator端点)的映射关系
GEThttp://localhost:9000/metrics获取应用程序的指标信息,例如内存使用情况,HTTP请求数量等信息
GEThttp://localhost:9000/metrics/{name}获取指定指标
GEThttp://localhost:9000/trace提供基本的HTTP请求跟踪信息
POSThttp://localhost:9000/shutdown关闭应用程序,如果要使这个功能生效,需要在application.yml中打开配置项endpoints.shutdown.enabled为true

3. 使用ssh连接Actuator

使用shell连接Actuator需要在Pom中加入如下依赖:

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

然后重启springboot项目,会在控制台中打印出连接密码:

Using default password for shell access: 0bc9bb95-fcdc-4da2-8aae-2cd245f7894f

可以使用ssh进行连接,如图所示:
在这里插入图片描述
连接上shell之后,可以通过终端查看Actuator的各个端点,SpringBoot提供了四个特有的shell命令,如表格所示:

命令说明
beans列出SpringBoot上下文中所有bean的信息
endpoint调用Actuator端点
metricsSpringBoot的指标信息
autoconfig自动配置说明报告
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值