一.作用
Actuator提供了很多生产级的特性,比如监控和度量Spring Boot应用程序。Actuator的这些特性可以通过众多REST端点、远程shell和JMX获得。
端点二.例子
比如访问http://localhost:8080/beans,你可以得到上下文bean的Bean ID,资源文件,依赖,作用域.
bean:Spring应用程序上下文中的Bean名称或ID。
resource:.class文件的物理位置,通常是一个URL,指向构建出的JAR文件。这会随着应用程序的构建和运行方式发生变化。
dependencies:当前Bean注入的Bean ID列表。
scope:Bean的作用域(通常是单例,这也是默认作用域)。
type:Bean的Java类型。
- 注:敏感信息访问限制
根据上面表格,鉴权为false
的,表示不敏感,可以随意访问,否则就是做了一些保护,不能随意访问。
endpoints.mappings.sensitive=false
这样需要对每一个都设置,比较麻烦。敏感方法默认是需要用户拥有 ACTUATOR
角色,因此,也可以设置关闭安全限制:
management.security.enabled=false
或者配合 Spring Security
做细粒度控制。
- beans 注册bean
在浏览器(我用的postman)输入http://localhost:8085/beans,你会得到
{
"bean": "assetController", // Bean ID
"aliases": [],
"scope": "singleton", // Bean作用域
"type": "com.bwoil.c2b.service.asset.controller.AssetController", // Java类型
"resource": "file [E:/product/bwoil-development/bwoil-order/bwoil-order-service/target/classes/com/bwoil/c2b/service/asset/controller/AssetController.class]", // 资源文件
"dependencies": [
"assetService"
] // 依赖
}
- autoconfig 自动装配信息
"positiveMatches": { // 成功条件
"EurekaClientAutoConfiguration": [
{
"condition": "OnClassCondition", // 条件类型
"message": "@ConditionalOnClass found required class 'com.netflix.discovery.EurekaClientConfig'; @ConditionalOnMissingClass did not find unwanted class"
},
{
"condition": "OnPropertyCondition",
"message": "@ConditionalOnProperty (eureka.client.enabled) matched"
}
]
}
"negativeMatches": { // 失败条件
"AuditAutoConfiguration#authenticationAuditListener": {
"notMatched": [
{
"condition": "OnClassCondition",
"message": "@ConditionalOnClass did not find required class 'org.springframework.security.authentication.event.AbstractAuthenticationEvent'"
}
],
"matched": []
}
}
- env 环境变量
"profiles": [],
"server.ports": {
"local.server.port": 8085
}
...
可以查看应用属性,环境变量,JVM系统属性,服务器配置等信息
- metrics 运行时度量
{
mem: 198144,
mem.free: 144029, // mem.* 内存
processors: 8,
uptime: 1887794,
instance.uptime: 1871237,
systemload.average: 1.33251953125,
heap.committed: 198144,
heap.init: 131072
...
}
- trace 追踪Web请求
{
"timestamp": 1426378239775,
"info": {
"method": "GET",
"path": "/metrics",
"headers": {
"request": {
"accept": "*/*",
"host": "localhost:8080",
"user-agent": "curl/7.37.1"
},
"response": {
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Cache-Control":
"no-cache, no-store, max-age=0, must-revalidate",
"Pragma": "no-cache",
"Expires": "0",
"X-Frame-Options": "DENY",
"X-Application-Context": "application",
"Content-Type": "application/json;charset=UTF-8",
"Transfer-Encoding": "chunked",
"Date": "Sun, 15 Mar 2015 00:10:39 GMT",
"status": "200"
}
}
}
- dump 导出线程快照
{
"threadName": "container-0",
"threadId": 19,
"blockedTime": -1,
"blockedCount": 0,
"waitedTime": -1,
"waitedCount": 64,
"lockName": null,
"lockOwnerId": -1,
"lockOwnerName": null,
"inNative": false,
"suspended": false,
"threadState": "TIMED_WAITING",
...
}
- health 监控应用程序健康情况
{
"status":"UP",
"diskSpace": {
"status":"UP",
"free":377423302656,
"threshold":10485760
},
"db":{
"status":"UP",
"database":"H2",
"hello":1
}
}
- shutdown 关闭应用程序
{"message":"This endpoint is disabled"}
注:要开启该端点,需将endpoints.shutdown.enabled设置为true
- info 获取应用信息
{
"contactEmail":"support@myreadinglist.com"
}
需要现在application.yml文件配置:
info:
contactEmail: support@myreadinglist.com
以上日记信息可以用MongoDB记录起来.
网友评论