spring boot 2.X 集成 actuator 监控

1.引入相关依赖 actuator

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

<!-- prometheus依赖 -->
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

2.添加相关配置

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

 
# 指定监控的端口,如果端口被占用,可以换成其他端口,由于统一配置,可在 k8s 负载均衡中配置[VIP:9002] 映射到 [RS:此端口]
management.server.port=9002
 
# 暴露指定端点,* 暴露所有,可选:env,info,config,health
management.endpoints.web.exposure.include=*
 
# 暴露监控标签,默认和服务名称一致即可,如需变更可自定义
management.metrics.tags.application=${spring.application.name}

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

5. shutdown 默认关闭 ,添加一下配置 开启shutdown,且只支持post请求

management.endpoint.shutdown.enabled=true

http://localhost:9002/actuator/prometheus 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

潇凝子潇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值