一、spring相关版本
- spring-boot
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath />
</parent>
- spring-cloud
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RC2</spring-cloud.version>
</properties>
二、spring-cloud监控配置
1. 加入依赖
<!-- 监控依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2. application.yml配置
在application.yml增加自己需要的配置
#启用监控
management:
endpoints:
web:
exposure:
include:
- "*" # 开放所有端点health,info,metrics,通过actuator/+端点名就可以获取相应的信息。默认打开health和info
endpoint:
health:
show-details: always #未开启actuator/health时,我们获取到的信息是{"status":"UP"},status的值还有可能是 DOWN。开启后打印详细信息
3. 访问路径
localhost根据自己部署的服务器IP、主机名访问。 info、health为默认开放,metrics默认不开放
http://localhost:20000/actuator/info 心跳检查
http://localhost:20000/actuator/health 健康检查
http://localhost:20000/actuator/metrics 指标
4.响应数据
helth
- 默认
{
"status": "UP"
}
- show-details: always
{
"status": "UP",
"details": {
"diskSpace": {
"status": "UP",
"details": {
"total": 891490922496,
"free": 360835141632,
"threshold": 10485760
}
},
"refreshScope": {
"status": "UP"
},
"discoveryComposite": {
"status": "UP",
"details": {
"discoveryClient": {
"status": "UP",
"details": {
"services": [
]
}
},
"eureka": {
"description": "Remote status from Eureka server",
"status": "UNKNOWN",
"details": {
"applications": {
}
}
}
}
},
"hystrix": {
"status": "UP"
}
}
}
metrics指标的响应信息
{
"names": [
"jvm.memory.max",
"tomcat.threads.busy",
"jvm.threads.states",
"jvm.gc.memory.promoted",
"tomcat.cache.hit",
"tomcat.servlet.error",
"tomcat.cache.access",
"jvm.memory.used",
"jvm.gc.max.data.size",
"jvm.gc.pause",
"jvm.memory.committed",
"system.cpu.count",
"logback.events",
"jvm.buffer.memory.used",
"tomcat.sessions.created",
"jvm.threads.daemon",
"system.cpu.usage",
"jvm.gc.memory.allocated",
"tomcat.global.sent",
"tomcat.sessions.expired",
"tomcat.global.request.max",
"jvm.threads.live",
"jvm.threads.peak",
"tomcat.global.request",
"process.uptime",
"tomcat.sessions.rejected",
"tomcat.global.received",
"process.cpu.usage",
"jvm.classes.loaded",
"jvm.classes.unloaded",
"tomcat.sessions.active.current",
"tomcat.threads.config.max",
"tomcat.sessions.alive.max",
"jvm.gc.live.data.size",
"tomcat.servlet.request.max",
"tomcat.global.error",
"tomcat.servlet.request",
"jvm.buffer.count",
"tomcat.threads.current",
"jvm.buffer.total.capacity",
"tomcat.sessions.active.max",
"process.start.time"
]
}