Customizing Individual Metrics
If you need to apply customizations to specific Meter
instances, you can use the io.micrometer.core.instrument.config.MeterFilter
interface.
For example, if you want to rename the mytag.region
tag to mytag.area
for all meter IDs beginning with com.example
, you can do the following:
-
Java
-
Kotlin
import io.micrometer.core.instrument.config.MeterFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
public class MyMetricsFilterConfiguration {
@Bean
public MeterFilter renameRegionTagMeterFilter() {
return MeterFilter.renameTag("com.example", "mytag.region", "mytag.area");
}
}
import io.micrometer.core.instrument.config.MeterFilter
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
@Configuration(proxyBeanMethods = false)
class MyMetricsFilterConfiguration {
@Bean
fun renameRegionTagMeterFilter(): MeterFilter {
return MeterFilter.renameTag("com.example", "mytag.region", "mytag.area")
}
}
By default, all MeterFilter beans are automatically bound to the Spring-managed MeterRegistry .
Make sure to register your metrics by using the Spring-managed MeterRegistry and not any of the static methods on Metrics .
These use the global registry that is not Spring-managed.
|
Common Tags
Common tags are generally used for dimensional drill-down on the operating environment, such as host, instance, region, stack, and others. Commons tags are applied to all meters and can be configured, as the following example shows:
-
Properties
-
YAML
management.metrics.tags.region=us-east-1
management.metrics.tags.stack=prod
management:
metrics:
tags:
region: "us-east-1"
stack: "prod"
The preceding example adds region
and stack
tags to all meters with a value of us-east-1
and prod
, respectively.
The order of common tags is important if you use Graphite.
As the order of common tags cannot be guaranteed by using this approach, Graphite users are advised to define a custom MeterFilter instead.
|
Per-meter Properties
In addition to MeterFilter
beans, you can apply a limited set of customization on a per-meter basis using properties.
Per-meter customizations are applied, using Spring Boot’s PropertiesMeterFilter
, to any meter IDs that start with the given name.
The following example filters out any meters that have an ID starting with example.remote
.
-
Properties
-
YAML
management.metrics.enable.example.remote=false
management:
metrics:
enable:
example:
remote: false
The following properties allow per-meter customization:
Property | Description |
---|---|
|
Whether to accept meters with certain IDs.
Meters that are not accepted are filtered from the |
|
Whether to publish a histogram suitable for computing aggregable (across dimension) percentile approximations. |
|
Publish fewer histogram buckets by clamping the range of expected values. |
|
Publish percentile values computed in your application |
|
Give greater weight to recent samples by accumulating them in ring buffers which rotate after a configurable expiry, with a configurable buffer length. |
|
Publish a cumulative histogram with buckets defined by your service-level objectives. |
For more details on the concepts behind percentiles-histogram
, percentiles
, and slo
, see the “Histograms and percentiles” section of the Micrometer documentation.