我有以下 servlet:
@Servlet(\path : String -> path.matches("/metrics"))
class MetricsServlet_De extends HttpServlet {
private var prometheusMeterRegistry : PrometheusMeterRegistry
override function init() {
configureMetrics()
}
protected override function doGet(request : HttpServletRequest, response : HttpServletResponse) {
response.ContentType = TextFormat.CONTENT_TYPE_004
response.setStatus(HttpServletResponse.SC_OK)
prometheusMeterRegistry.scrape(response.Writer)
}
private function configureMetrics() : PrometheusMeterRegistry {
prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
new ClassLoaderMetrics().bindTo(prometheusMeterRegistry)
new JvmMemoryMetrics().bindTo(prometheusMeterRegistry)
new JvmGcMetrics().bindTo(prometheusMeterRegistry)
new ProcessorMetrics().bindTo(prometheusMeterRegistry)
new JvmThreadMetrics().bindTo(prometheusMeterRegistry)
var toDoubleFunction : ToDoubleFunction<GameMetrics> = \status -> status.GameFinished
Gauge.builder("game_status", new GameMetrics(), toDoubleFunction)
.description("Return Game status")
.register(prometheusMeterRegistry)
return prometheusMeterRegistry
}
}
在第一次调用 Servlet 时,GameMetrics.GameFinished()
会调用并正确显示一个值。对于所有对 servletGameMetrics.GameFinished()
的后续调用,不再调用并返回 NaN。
我无法弄清楚我做错了什么。
此致