我总是更喜欢使用应用程序的基本 URL 提供上下文路径。现在要配置执行器,我们应该在 pom.xml 中包含以下依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
让它使用 Spring boot 版本所承载的默认版本。
将以下属性放入您的 application.properties
server.servlet.contextPath=/<app-name>
server.port=8080
management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
management.security.enabled=false
management.health.mongo.enabled=false
management.health.redis.enabled=false
management.health.rabbit.enabled=false
management.endpoint.health.show-details=always
#/metrics endpoint configuration
endpoints.metrics.id=metrics
endpoints.metrics.sensitive=false
endpoints.metrics.enabled=true
#/health endpoint configuration (Comment when you are using customized health check)
endpoints.health.id=health
endpoints.health.sensitive=false
endpoints.health.enabled=true
info.app.name=@project.name@
info.app.description=@project.description@
info.app.version=@project.version@
info.app.encoding=@project.build.sourceEncoding@
info.app.java.version=@java.version@
在启动服务器后进行上述配置后,您可以轻松检查以下 http 调用的指标-
# curl http://localhost:8080/myapp/actuator/metrics
{
"names": ["jvm.buffer.memory.used", "jvm.gc.memory.allocated",
"jvm.memory.committed", "jvm.memory.used", "http.server.requests",
"jvm.gc.max.data.size", "logback.events", "system.cpu.count",
"jvm.memory.max", "jvm.buffer.total.capacity", "jvm.buffer.count",
"process.files.max", "jvm.threads.daemon", "process.start.time",
"jvm.gc.live.data.size", "process.files.open", "process.cpu.usage",
"process.uptime", "system.load.average.1m", "jvm.gc.pause",
"system.cpu.usage", "jvm.threads.live", "jvm.classes.loaded",
"jvm.classes.unloaded", "jvm.threads.peak", "jvm.gc.memory.promoted"]
}
详情可以看我的博客here