Micronaut: How to get metrics in the Prometheus format?

我与影子孤独终老i 提交于 2019-12-05 01:06:12

问题


How should I configure the Micronaut to get the /metrics in the Prometheus format ?

Used: micronaut 1.0.0.M3

Now:

micronaut:
...
  metrics:
    enabled: true
    export:
      prometheus:
        enabled: true

and result: metrics name list

{"names":["jvm.memory.max","executor.pool.size"...]}

I need to get: metrics in the prometheus format(formats)


回答1:


At the moment, we solved the problem as follows.

  1. Added a new endpoint. Or create a controller with a mapping on /metrics.
  2. The new endpoint added a return of scrape().
  3. Correlated endpoint with /prometheus (new endpoint can not be mapped on /metrics).
  4. Disconnected endpoint metrics which by default.

Config:

micronaut:   
  ...   
  metrics:
    enabled: true
    export:
      prometheus:
        enabled: true 
... 
endpoints:
...
  metrics:
    enabled: false
  prometheus:
    enabled: true



回答2:


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()
    }
}



回答3:


Haven't tested this out but based on the following:

https://github.com/micronaut-projects/micronaut-core/blob/master/configurations/micrometer-registry-prometheus/src/main/java/io/micronaut/configuration/metrics/micrometer/prometheus/PrometheusMeterRegistryFactory.java

Your yaml should look like

metrics:
  prometheus:
    enabled: true

don't believe the export comes into play.




回答4:


Micronaut Micrometer has an PrometheusEndpoint from version 1.1 that will return in Prometheus format from /prometheus and can be enabled in application.yml by:

endpoints:
  prometheus:
    sensitive: false

In combination with

micronaut:
  metrics:
    enabled: true
    export:
      prometheus:
        enabled: true
        step: PT1M
        descriptions: true

(The documentation is missing the endpoint config but will be changed in the new release)



来源:https://stackoverflow.com/questions/51892700/micronaut-how-to-get-metrics-in-the-prometheus-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!