Currently, I have 2 custom spring artefacts- metrics-util
and web-utils
. metrics-util contains all the functions related to measuring the metrics such as a web-filter to calculate the metrics of all rest controller. Web-utils uses some functions from metrics-util to measure the metrics inside the function.
My main spring program calls web-utils functions within it. And I am using same name with different tags. The issue I am facing is I can see the metrics and the different tags at /actuator/metrics/{metric_name}
but only the first instance of metric name is being displayed at the endpoint where Prometheus scrapes.
Micrometer version:
implementation 'io.micrometer:micrometer-core:1.12.3'
implementation 'io.micrometer:micrometer-registry-prometheus:1.12.3'
My config for registry:
@Configuration
@ComponentScan(basePackages = ["co.hyperface.ark.metricsutil.*"])
class BaseMetricsConfig {
@Bean
MeterRegistry meterRegistry() {
return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT)
}
}
How I'm injecting in my program:
class MetricsUtil {
private MeterRegistry meterRegistry
@Autowired
MetricsUtil (MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry
}
}
Expected result:
For any endpoint, web-filter gets activated first so its callcount{call_type='rest_controller'}
must increase then since I'm calling web-utils function inside that controller, the calls callcount{call_type='external'}
must be increased.
But at the scraping endpoint I'm getting only callcount{call_type='rest_controller'}
. but I'm able to see both of them at /actuator/metrics/callcount
Thanks in advance.
metrics-util contains all the functions related to measuring the metrics such as a web-filter to calculate the metrics of all rest controller. Web-utils uses some functions from metrics-util to measure the metrics inside the function.
You know that if you add Spring Boot Actuator, you will get this for free?
And I am using same name with different tags. The issue I am facing is I can see the metrics and the different tags at /actuator/metrics/{metric_name} but only the first instance of metric name is being displayed at the endpoint where Prometheus scrapes.
This is discouraged by the Prometheus server and not possible with the Prometheus client. Please do not do this. If the tags are different, it is a different metric. If it is the same, the tags should be the same. If you don't have a value or you don't know the value you can always use null
, none
, na
, unknown
, etc.
Solution: you can delete "metrics-util" and "web-utils", add Spring Boot actuator which will do all this (see http_server_requests
metric).