Micronaut:如何获取Prometheus格式的指标? [英] Micronaut: How to get metrics in the Prometheus format?
本文介绍了Micronaut:如何获取Prometheus格式的指标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我应该如何配置Micronaut以获得Prometheus格式的/metrics
?
How should I configure the Micronaut to get the /metrics
in the Prometheus format ?
已使用: micronaut 1.0.0.M3
现在:
micronaut:
...
metrics:
enabled: true
export:
prometheus:
enabled: true
和结果:指标名称列表
{"names":["jvm.memory.max","executor.pool.size"...]}
我需要获取:普罗米修斯格式的指标(格式)
I need to get: metrics in the prometheus format(formats)
推荐答案
为了搭载其他答案,以下是Micronaut端点,它以我们所需的格式提供了Prometheus指标:
To piggyback on the other answers, here is an Micronaut endpoint that provides the Prometheus metrics in the format we needed:
package your.package.name
import io.micrometer.prometheus.PrometheusMeterRegistry
import io.micronaut.management.endpoint.annotation.Endpoint
import io.micronaut.management.endpoint.annotation.Read
@Endpoint(id = "prometheus", value = "/prometheus", defaultEnabled = true,
defaultSensitive = false)
class PrometheusController(val prometheusMeterRegistry: PrometheusMeterRegistry) {
@Read
fun scrape(): String {
return prometheusMeterRegistry.scrape()
}
}
这篇关于Micronaut:如何获取Prometheus格式的指标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文