Spring 引导执行器未显示内存详细信息
Spring boot actuator is not displaying the memory details
我正在尝试在 spring boot 2.0.2.RELEASE.
中实现执行器
依赖于 pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<scope>compile</scope>
</dependency>
application.properties
management.server.port = 8082
management.endpoint.health.enabled=true
自定义健康检查class
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component
public class HealthCheck implements HealthIndicator {
@Override
public Health health() {
int errorCode = check(); // perform some specific health check
if (errorCode != 0) {
return Health.down()
.withDetail("Error Code", errorCode).build();
}
return Health.up().build();
}
public int check() {
// Our logic to check health
return 0;
}
}
当我打
http://localhost:8082/actuator/health
在浏览器中,我得到
{"status":"UP"}
我希望得到
{
status: "UP",
diskSpace: {
status: "UP",
total: 240721588224,
free: 42078715904,
threshold: 10485760
}
}
在application.yml中添加以下内容
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
enabled: true
show-details: always
info:
enabled: true
metrics:
enabled: true
threaddump:
enabled: true
通过以下配置,我们可以启用所有组件的详细信息。
management:
endpoint:
health:
show-details: always
要单独获取内存详细信息,您可以指定组件。
curl -i localhost:8082/actuator/health/diskSpace
{
"status": "UP",
"details": {
"total": 131574468608,
"free": 47974543360,
"threshold": 10485760
}
}
我正在尝试在 spring boot 2.0.2.RELEASE.
中实现执行器依赖于 pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<scope>compile</scope>
</dependency>
application.properties
management.server.port = 8082
management.endpoint.health.enabled=true
自定义健康检查class
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component
public class HealthCheck implements HealthIndicator {
@Override
public Health health() {
int errorCode = check(); // perform some specific health check
if (errorCode != 0) {
return Health.down()
.withDetail("Error Code", errorCode).build();
}
return Health.up().build();
}
public int check() {
// Our logic to check health
return 0;
}
}
当我打 http://localhost:8082/actuator/health 在浏览器中,我得到 {"status":"UP"}
我希望得到
{
status: "UP",
diskSpace: {
status: "UP",
total: 240721588224,
free: 42078715904,
threshold: 10485760
}
}
在application.yml中添加以下内容
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
enabled: true
show-details: always
info:
enabled: true
metrics:
enabled: true
threaddump:
enabled: true
通过以下配置,我们可以启用所有组件的详细信息。
management:
endpoint:
health:
show-details: always
要单独获取内存详细信息,您可以指定组件。
curl -i localhost:8082/actuator/health/diskSpace
{
"status": "UP",
"details": {
"total": 131574468608,
"free": 47974543360,
"threshold": 10485760
}
}