spring boot 2.X 集成 actuator 监控

105 阅读1分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

 1.引入相关依赖 actuator

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

2.添加相关配置

# 属性列出了公开的端点的ID

management.endpoints.web.exposure.include=*

3.浏览器地址栏输入 :http://127.0.0.1/actuator/  返回以下结果  

   在使用Http访问端点时,需要加上默认/actuator 前缀

{
	links: {
		self: {
			href: "http://127.0.0.1/actuator",
			templated: false,
		},
		auditevents: {
			href: "http://127.0.0.1/actuator/auditevents",
			templated: false,
		},
		beans: {
			href: "http://127.0.0.1/actuator/beans",
			templated: false,
		},
		caches - cache: {
			href: "http://127.0.0.1/actuator/caches/{cache}",
			templated: true,
		},
		caches: {
			href: "http://127.0.0.1/actuator/caches",
			templated: false,
		},
		health - component - instance: {
			href: "http://127.0.0.1/actuator/health/{component}/{instance}",
			templated: true,
		},
		health - component: {
			href: "http://127.0.0.1/actuator/health/{component}",
			templated: true,
		},
		health: {
			href: "http://127.0.0.1/actuator/health",
			templated: false,
		},
		conditions: {
			href: "http://127.0.0.1/actuator/conditions",
			templated: false,
		},
		configprops: {
			href: "http://127.0.0.1/actuator/configprops",
			templated: false,
		},
		env: {
			href: "http://127.0.0.1/actuator/env",
			templated: false,
		},
		env - toMatch: {
			href: "http://127.0.0.1/actuator/env/{toMatch}",
			templated: true,
		},
		info: {
			href: "http://127.0.0.1/actuator/info",
			templated: false,
		},
		loggers: {
			href: "http://127.0.0.1/actuator/loggers",
			templated: false,
		},
		loggers - name: {
			href: "http://127.0.0.1/actuator/loggers/{name}",
			templated: true,
		},
		heapdump: {
			href: "http://127.0.0.1/actuator/heapdump",
			templated: false,
		},
		threaddump: {
			href: "http://127.0.0.1/actuator/threaddump",
			templated: false,
		},
		metrics: {
			href: "http://127.0.0.1/actuator/metrics",
			templated: false,
		},
		metrics - requiredMetricName: {
			href: "http://127.0.0.1/actuator/metrics/{requiredMetricName}",
			templated: true,
		},
		scheduledtasks: {
			href: "http://127.0.0.1/actuator/scheduledtasks",
			templated: false,
		},
		httptrace: {
			href: "http://127.0.0.1/actuator/httptrace",
			templated: false,
		},
		mappings: {
			href: "http://127.0.0.1/actuator/mappings",
			templated: false,
		},
	}
}

    4. 请求解释:

HTTP方法路径描述是否敏感信息
GET/actuator/auditevents显示当前审计信息true
GET/actuator/configprops查看配置属性,包括默认配置, 显示一个所有@ConfigurationProperties的整理列表true
GET/actuator/beansbean及其关系列表, 显示一个应用中所有Spring Beans的完整列表true
GET/actuator/heapdump堆信息true
GET/actuator/env查看所有环境变量true
GET/actuator/env/{name}查看具体变量值true
GET/actuator/health查看应用健康指标, 当使用一个未认证连接访问时显示一个简单的’status’,使用认证连接访问则显示全部信息详情false
GET/actuator/info查看应用信息false
GET/actuator/mappings查看所有url映射, 即所有@RequestMapping路径的整理列表true
GET/actuator/metrics查看应用基本指标true
GET/actuator/metrics/{name}查看具体指标true
POST/actuator/shutdown关闭应用,允许应用以优雅的方式关闭(默认情况下不启用)true
GET/actuator/httptrace查看基本追踪信息,默认为最新的一些HTTP请求true
GET/actuator/scheduledtasks定时任务信息false
GET/actuator/threaddump执行一个线程dumptrue
  1. shutdown 默认关闭 ,添加一下配置 开启shutdown,且只支持post请求
management.endpoint.shutdown.enabled=true

​编辑