Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Micrometer - Add default prefix in metric name

Tags:

micrometer

In micrometer, we can create a new gauge doing something like

myMeterRegistry.gauge("my_metric", 69);

See the code here https://github.com/micrometer-metrics/micrometer/blob/master/micrometer-core/src/main/java/io/micrometer/core/instrument/MeterRegistry.java#L468

Would be possible to include a "prefix" name by default for my myMeterRegistry object?

Manually, it should like:

myeterRegistry.gauge("myprefix_my_metric", 69);

My goal is that every developer that creates a gauge metric in my application does not have to take care of adding the "myprefix_" at the beginning of the metric name

like image 746
Lobo Avatar asked Mar 06 '20 15:03

Lobo


People also ask

What are Micrometer metrics?

Micrometer is a simple application metrics facade for the JVM. It has become the defacto standard in the Java ecosystem and is integrated into SpringBoot. Read more on Micrometer at micrometer.io. Instana supports Micrometer without any additional configuration.

What is MeterRegistry?

MeterRegistry In Micrometer, a MeterRegistry is the core component used for registering meters. We can iterate over the registry and further each meter's metrics to generate a time series in the backend with combinations of metrics and their dimension values. The simplest form of the registry is SimpleMeterRegistry.

What is spring Micrometer?

What is it? Micrometer is a dimensional-first metrics collection facade whose aim is to allow you to time, count, and gauge your code with a vendor neutral API. Through classpath and configuration, you may select one or several monitoring systems to export your metrics data to. Think of it like SLF4J, but for metrics!

What are spring boot metrics?

Spring Boot provides a metrics endpoint that can be used diagnostically to examine the metrics collected by an application. The endpoint is not available by default and must be exposed, see exposing endpoints for more details. Navigating to /actuator/metrics displays a list of available meter names.


1 Answers

A MeterFilter would let you do that (but don't!):

new MeterFilter() {
    @Override
    public Meter.Id map(Meter.Id id) {
      return id.withName("myprefix." + id.getName());
    }
}

However a common prefix is typically a smell of an incorrect dimensionality. Usually users try to add a region, host, or the application's name as a prefix. Those are better provided as tags since then you can aggregate across systems and use common dashboards.

The commonTags approach is recommended:

registry.config().commonTags("team", "myteam", "region", "us-east-1");

For hierarchical meter registries, tags will be included in the name as a prefix.

like image 111
checketts Avatar answered Sep 18 '22 19:09

checketts