【发布时间】:2019-12-27 15:59:37
【问题描述】:
我正在现有的 Spring Boot 应用程序中设置 Spring Actuator。一切正常,除了/metrics 端点返回的指标中缺少 JVM 指标(CPU、内存、GC、..)。
我正在使用 Spring Boot 2.1.4。我明确配置了GlobalMethodSecurity 并排除了SecurityAutoConfiguration。
这是我的安全配置:
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {
private final IAuthService authService;
@Autowired
public MethodSecurityConfig(IAuthService authService) {
this.authService = authService;
}
@Override
protected MethodSecurityExpressionHandler createExpressionHandler() {
return new CustomMethodSecurityExpressionHandler(authService);
}
}
虽然这些是我正在使用的指标属性:
management:
security:
enabled: false
server:
address: 0.0.0.0
port: 8080
endpoints:
web:
exposure.include: metrics,prometheus
exposure.exclude:
metrics:
enable.jvm: true
使用此配置,可用的指标是:
{
"names": [
"jdbc.connections.active",
"jdbc.connections.max",
"jdbc.connections.min",
"tomcat.global.sent",
"tomcat.sessions.created",
"tomcat.global.request.max",
"hikaricp.connections.idle",
"hikaricp.connections.pending",
"tomcat.global.request",
"tomcat.sessions.expired",
"hikaricp.connections",
"tomcat.global.received",
"hikaricp.connections.active",
"hikaricp.connections.creation",
"tomcat.sessions.rejected",
"tomcat.threads.config.max",
"hikaricp.connections.max",
"hikaricp.connections.min",
"tomcat.global.error",
"tomcat.sessions.active.current",
"tomcat.sessions.alive.max",
"hikaricp.connections.usage",
"tomcat.threads.current",
"hikaricp.connections.timeout",
"tomcat.sessions.active.max",
"hikaricp.connections.acquire",
"tomcat.threads.busy"
]
}
如果我暂时删除 @EnableGlobalMethodSecurity,可用指标变为:
{
"names": [
"jvm.threads.states",
"jdbc.connections.active",
"process.files.max",
"jvm.memory.used",
"jvm.gc.memory.promoted",
"jvm.memory.max",
"system.load.average.1m",
"jvm.gc.max.data.size",
"jdbc.connections.max",
"jdbc.connections.min",
"jvm.memory.committed",
"system.cpu.count",
"tomcat.global.sent",
"jvm.buffer.memory.used",
"tomcat.sessions.created",
"jvm.threads.daemon",
"system.cpu.usage",
"jvm.gc.memory.allocated",
"tomcat.global.request.max",
"hikaricp.connections.idle",
"hikaricp.connections.pending",
"tomcat.global.request",
"tomcat.sessions.expired",
"hikaricp.connections",
"jvm.threads.live",
"jvm.threads.peak",
"tomcat.global.received",
"hikaricp.connections.active",
"hikaricp.connections.creation",
"process.uptime",
"tomcat.sessions.rejected",
"process.cpu.usage",
"tomcat.threads.config.max",
"jvm.classes.loaded",
"hikaricp.connections.max",
"hikaricp.connections.min",
"jvm.classes.unloaded",
"tomcat.global.error",
"tomcat.sessions.active.current",
"tomcat.sessions.alive.max",
"jvm.gc.live.data.size",
"log4j2.events",
"hikaricp.connections.usage",
"tomcat.threads.current",
"jvm.gc.pause",
"hikaricp.connections.timeout",
"process.files.open",
"jvm.buffer.count",
"jvm.buffer.total.capacity",
"tomcat.sessions.active.max",
"hikaricp.connections.acquire",
"tomcat.threads.busy",
"process.start.time"
]
}
我希望方法的安全性不会影响 JVM 指标的发布。 我应该如何配置 Actuator/Security 以获得所有指标?
提前感谢您的帮助!
【问题讨论】:
标签: java spring spring-boot spring-security spring-boot-actuator