学习springboot2 actuator模块的内容,记录一下问题.
actuator功能 : 对执行系统的监控和功能统计,监控采集自己系统的各种指标
开始使用actuator,看了网上的操作简单的一逼,简单归简单,自己练练手理解理解呗
---------------------------------------------------------------------------------------------------------
试一试
引入maven依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
可以了,跑起来试试:
理想->访问 http://localhost:8080/health 浏览器显示以下json
{
"status": "UP",
"diskSpace": {
"status": "UP",
"total": 131200434816,
"free": 253870264444,
"threshold": 01483760
}
}
现实-> 访问 http://localhost:8080/health 浏览器显示以下
打脸的 404,灰色的现实.
PS: springboot2之前没有接触这些好玩东西,springboot2版本时候开始上手,对于这些跟随资料理解练手的打脸现象很是懵逼,于是开始有想法记录,写博客
瞎想: 对于什么都没有写,只加入了依赖出了问题,还是404的问题,就想之前的资料,是不是升级了以后有改动层次或者是弃用,合并各种改动呢?
来一份别人的,是别人的控制台信息:
来一份本座的控制台信息:
上面信息说暴露端点有2个 endpoint(s), 根路径是 '/actuator'
目前现在可以访问 /actuator/health 和 /actuator/info 和/actuator,请求方式是GET
再试试呗,访问如下: 访问 http://localhost:8080/actuator/health
{
status: "UP"
}
PS: 刚才注意到本座的控制台的Mapped就两个,别人的都暴露出来了,可能需要加什么约定,后面再说.
我也想要,问题
我怎么只有一个UP,见了鬼了,其他信息呢? 查询资料,需要在application.yml中配置一下
发现springboot2之前的信息都过时了,懵逼
点击进入
进去json文件, spring-configuration-metadata.json
里面说明了这些都已经被弃用 deprecated: true 列表,网上也看不到明确资料,干脆去官网上去找找发现
springboot2变动文档 地址:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide
官方actuatorAPI文档 地址:
https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/actuator-api/html/
搞定
官方文档上说endpoints都归在management下,show-details是health的详细信息设置
application.yml 配置如下: 显示health详细信息
management:
endpoint:
health:
show-details: always
运行结果如下:
{
status: "UP",
details: {
db: {
status: "UP",
details: {
datasourceCat: {
status: "UP",
details: {
database: "MySQL",
hello: 1
}
},
datasourceDog: {
status: "UP",
details: {
database: "MySQL",
hello: 1
}
}
}
},
diskSpace: {
status: "UP",
details: {
total: 280248709120,
free: 268942974976,
threshold: 10485760
}
}
}
}
遇到相同问题的同学可以看下文档,上面都有说明以及操作
本次学习最后的配置yml:
management:
endpoint:
health:
show-details: always
server:
servlet:
context-path: /cat
port: 8081
endpoints:
web:
base-path: /tom
exposure:
include: '*'
server.servlet.context-path: /cat 必须在指定 server.port端口才会有效果
endpoints.web.base-path: /tom 可以替换原来的/actuator访问路径,也可以设置/ 自定义访问
include: '*' 是打开所有的端点 ,还有一个shutdown端点需要另外打开,再说
测试: 访问浏览器 http://localhost:8081/cat/tom -- 以及json数据返回:
{
_links: {
self: {
href: "http://localhost:8081/cat/tom",
templated: false
},
auditevents: {
href: "http://localhost:8081/cat/tom/auditevents",
templated: false
},
beans: {
href: "http://localhost:8081/cat/tom/beans",
templated: false
},
health: {
href: "http://localhost:8081/cat/tom/health",
templated: false
},
conditions: {
href: "http://localhost:8081/cat/tom/conditions",
templated: false
},
configprops: {
href: "http://localhost:8081/cat/tom/configprops",
templated: false
},
env: {
href: "http://localhost:8081/cat/tom/env",
templated: false
},
env - toMatch: {
href: "http://localhost:8081/cat/tom/env/{toMatch}",
templated: true
},
info: {
href: "http://localhost:8081/cat/tom/info",
templated: false
},
loggers: {
href: "http://localhost:8081/cat/tom/loggers",
templated: false
},
loggers - name: {
href: "http://localhost:8081/cat/tom/loggers/{name}",
templated: true
},
heapdump: {
href: "http://localhost:8081/cat/tom/heapdump",
templated: false
},
threaddump: {
href: "http://localhost:8081/cat/tom/threaddump",
templated: false
},
metrics: {
href: "http://localhost:8081/cat/tom/metrics",
templated: false
},
metrics - requiredMetricName: {
href: "http://localhost:8081/cat/tom/metrics/{requiredMetricName}",
templated: true
},
scheduledtasks: {
href: "http://localhost:8081/cat/tom/scheduledtasks",
templated: false
},
httptrace: {
href: "http://localhost:8081/cat/tom/httptrace",
templated: false
},
mappings: {
href: "http://localhost:8081/cat/tom/mappings",
templated: false
}
}
}
------------------------------------------------华丽的底线-----------------------------------------------