SpringCloud入门——Actuator健康监控
一、开启监控
开启Actuator只需要在pom文件中,添加actuator依赖。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
重启服务,打开对应端口/actuator路径,例如http://localhost:8082/actuator,可以看到可以访问的端点。
现在只开启了health节点和info节点。health里面只有status信息。UP说明这个节点是启动的。
二、开启监控端点信息
当前提供的监控信息无法满足我们的需求,需要我们在配置文件中进行配置。
*代表所有节点都加载/actuator返回json
#开启所有端点
management.endpoints.web.exposure.include=*
1、开启所有端点
{
"_links": {
"self": {
"href": "http://localhost:8082/actuator",
"templated": false
},
"archaius": {
"href": "http://localhost:8082/actuator/archaius",
"templated": false
},
//bean信息
"beans": {
"href": "http://localhost:8082/actuator/beans",
"templated": false
},
"caches": {
"href": "http://localhost:8082/actuator/caches",
"templated": false
},
"caches-cache": {
"href": "http://localhost:8082/actuator/caches/{cache}",
"templated": true
},
"health-path": {
"href": "http://localhost:8082/actuator/health/{*path}",
"templated": true
},
"health": {
"href": "http://localhost:8082/actuator/health",
"templated": false
},
//获取应用自定义的信息
"info": {
"href": "http://localhost:8082/actuator/info",
"templated": false
},
"conditions": {
"href": "http://localhost:8082/actuator/conditions",
"templated": false
},
//获取应用中配置的属性信息报告
"configprops": {
"href": "http://localhost:8082/actuator/configprops",
"templated": false
},
"env-toMatch": {
"href": "http://localhost:8082/actuator/env/{toMatch}",
"templated": true
},
//获取应用所有可用的环境属性报告
"env": {
"href": "http://localhost:8082/actuator/env",
"templated": false
},
"loggers-name": {
"href": "http://localhost:8082/actuator/loggers/{name}",
"templated": true
},
"loggers": {
"href": "http://localhost:8082/actuator/loggers",
"templated": false
},
"heapdump": {
"href": "http://localhost:8082/actuator/heapdump",
"templated": false
},
//返回程序运行中的线程信息
"threaddump": {
"href": "http://localhost:8082/actuator/threaddump",
"templated": false
},
"metrics-requiredMetricName": {
"href": "http://localhost:8082/actuator/metrics/{requiredMetricName}",
"templated": true
},
//返回应用的各类重要度量指标信息
"metrics": {
"href": "http://localhost:8082/actuator/metrics",
"templated": false
},
"scheduledtasks": {
"href": "http://localhost:8082/actuator/scheduledtasks",
"templated": false
},
//获取应用所有Spring Web的控制器映射关系报告
"mappings": {
"href": "http://localhost:8082/actuator/mappings",
"templated": false
},
"refresh": {
"href": "http://localhost:8082/actuator/refresh",
"templated": false
},
"features": {
"href": "http://localhost:8082/actuator/features",
"templated": false
},
"service-registry": {
"href": "http://localhost:8082/actuator/service-registry",
"templated": false
}
}
}
2、开启shutdown端点
用来关闭服务,开启远程关闭功能。
上面开启所有端点也不会打开shutdown端点,需要配置文件单独配置。
management.endpoint.shutdown.enabled=true
/actuator/shutdown 只支持POST请求。
3、查看重要度量指标信息
"metrics-requiredMetricName": {
"href": "http://localhost:8082/actuator/metrics/{requiredMetricName}",
"templated": true
},
//返回应用的各类重要度量指标信息
"metrics": {
"href": "http://localhost:8082/actuator/metrics",
"templated": false
},
先通过http://localhost:8082/actuator/metrics应用的各类重要度量指标信息。
{
"names": [
"http.server.requests",
"jvm.buffer.count",
"jvm.buffer.memory.used",
"jvm.buffer.total.capacity",
"jvm.classes.loaded",
"jvm.classes.unloaded",
"jvm.gc.live.data.size",
"jvm.gc.max.data.size",
"jvm.gc.memory.allocated",
"jvm.gc.memory.promoted",
"jvm.gc.pause",
"jvm.memory.committed",
"jvm.memory.max",
"jvm.memory.used",
"jvm.threads.daemon",
"jvm.threads.live",
"jvm.threads.peak",
"jvm.threads.states",
"logback.events",
"process.cpu.usage",
"process.start.time",
"process.uptime",
"system.cpu.count",
"system.cpu.usage",
"tomcat.sessions.active.current",
"tomcat.sessions.active.max",
"tomcat.sessions.alive.max",
"tomcat.sessions.created",
"tomcat.sessions.expired",
"tomcat.sessions.rejected"
]
}
然后通过http://localhost:8082/actuator/metrics/{requiredMetricName}查看对应指标详细数据,比如我们要查看jvm内存使用情况,就通过http://localhost:8082/actuator/metrics/jvm.memory.used查看。
{
"name": "jvm.memory.used",
"description": "The amount of used memory",
"baseUnit": "bytes",
"measurements": [
{
"statistic": "VALUE",
"value": 63845552
}
],
"availableTags": [
{
"tag": "area",
"values": [
"heap",
"nonheap"
]
},
{
"tag": "id",
"values": [
"Survivor Space",
"Eden Space",
"Metaspace",
"Code Cache",
"Tenured Gen"
]
}
]
}
4、系统环境变量
http://localhost:8082/actuator/env