简体   繁体   中英

Publish Micrometer Metrics to Prometheus

I am using Spring Boot v2.1.3 and Micrometer Registry for Prometheus v1.2.1.

I have created a DistributionSummary in my code and added it to PrometheusRegistry. I am using this Metric to store the time taken by the API. Moreover, I have created bucket as per my SLA for ex: 10ms, 20ms and 60ms.

        DistributionSummary summary = DistributionSummary.builder("nb.api.responsetime")
            .sla(10, 20, 60).register(registry);

I am using Spring Actuator to publish the metrics to Prometheus.

The metrics which are available in response of "/actuator/prometheus" for DistributionSummary are only Sum, Max & Count of the metrics.

nb_api_responsetime_max 15.0
nb_api_responsetime_bucket{le="10.0",} 2.0
nb_api_responsetime_bucket{le="20.0",} 5.0
nb_api_responsetime_bucket{le="60.0",} 5.0
nb_api_responsetime_bucket{le="+Inf",} 5.0
nb_api_responsetime_count 5.0
nb_api_responsetime_sum 56.0

I want to show the average of time taken by the API calls in selected amount of time. For ex: Average Time taken by API in last 5 mins.

Following are the required queries:

Avg Response Time per 5 min:

rate(nb_api_responsetime_sum[5m])/rate(nb_api_responsetime_count[5m])

Request Count per Min:

round(rate(nb_api_responsetime_count[1m]) * 60)

SLA Meet Per Min:

sum(rate(nb_api_responsetime_bucket{le="60.0"}[1m])) by (job)
/
sum(rate(nb_api_responsetime_count[1m])) by (job)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM