Send Micrometer metrics to Dynatrace
Micrometer is an open source instrumentation framework for JVM-based application metrics. It's used by Spring Boot to instrument a wide range of metrics. You can ingest Micrometer and Spring Boot metrics and analyze them with Dynatrace Davis® AI end to end in the context of your trace, log, and diagnostics data. With Dynatrace, you get intelligent AI-based observability and automatic root cause analysis for Spring Boot, 15+ pre-instrumented JVM-based frameworks and servers, and custom metrics.
You can use Micrometer in Dynatrace to:
Ingest pre-instrumented metrics from Spring Boot applications
Ingest pre-instrumented metrics from JVM-based frameworks, servers, and cache systems
Define and ingest custom metrics
Metrics ingested from Micrometer consume DDUs for custom metrics.
There are two ways of using Micrometer:
Prerequisites
-
Micrometer version 1.8.0+
-
optional Spring Boot version 2.6.0+
-
The registry dependency must be added to your project:
1implementation 'io.micrometer:micrometer-registry-dynatrace:latest.release'Replace
{micrometer.version}
with the latest version of Micrometer or a specific version that you want to use. A list of released versions is available on Maven Central. We recommend that you use the latest version.1<dependency>2 <groupId>io.micrometer</groupId>3 <artifactId>micrometer-registry-dynatrace</artifactId>4 <version>{micrometer.version}</version>5</dependency>
Ingestion channels
You can use one of the following ingestion channels to send your Micrometer metrics:
- OneAgent metric API—needs OneAgent installed on the monitored host.
- Metrics API v2.
Dynatrace Micrometer registry
Micrometer uses the concept of a registry to export metrics to monitoring systems.
- For Micrometer version 1.8.0 or later, Dynatrace Registry v2 is available. It exports metrics via the Metrics API v2. All new integrations of Micrometer and Dynatrace must use this version.
- For Micrometer version 1.8.0 or earlier, the legacy Dynatrace Micrometer registry v1 is available. For instructions, see Dynatrace Micrometer registry v1 (legacy) below.
Ingest metrics from Spring Boot apps
Micrometer can be configured via a .properties
or .yaml
file used for Spring Boot configuration.
Spring Boot automatically binds properties with the management.dynatrace.metrics.export
prefix to the Dynatrace configuration object.
All configuration should be made through the property files. Manually creating a Micrometer MeterRegistry
breaks the auto-configuration.
Property names for binding attributes from Spring Boot have changed in Spring Boot version 3.0.0. If you use a Spring Boot version before 3.0.0, use management.metrics.export.dynatrace
instead of management.dynatrace.metrics.export
.
For hosts that are monitored by OneAgent, automatic configuration is available. You don't need to specify the API endpoint to ingest the metric—if the uri parameter is not set in the configuration, the metric will be ingested via the OneAgent metric API.
1management.dynatrace.metrics.export:2 v2:3 metric-key-prefix: "service.component"4 enrich-with-dynatrace-metadata: true5 default-dimensions:6 stack: "prod"7 region: "us-east-1"
1management.dynatrace.metrics.export.v2.metric-key-prefix=service.component2management.dynatrace.metrics.export.v2.enrich-with-dynatrace-metadata=true3management.dynatrace.metrics.export.v2.default-dimensions.stack=prod4management.dynatrace.metrics.export.v2.default-dimensions.region=us-east-1
Ingest metrics directly from Micrometer
For hosts that are monitored by OneAgent, automatic configuration is available. You don't need to specify the API endpoint to ingest the metric—if the uri parameter is not set in the configuration, the metric will be ingested via the OneAgent metric API.
1DynatraceConfig dynatraceConfig = new DynatraceConfig() {2 @Override3 @Nullable4 public String get(String k) {5 // This method can be used for retrieving arbitrary config items;6 // null means accepting the defaults defined in DynatraceConfig7 return null;8 }9};10DynatraceMeterRegistry registry = DynatraceMeterRegistry.builder(config).build();
Verify the metrics
After you have sent your metrics, verify the data in the Data explorer.
Configuration properties
To set up the Dynatrace Micrometer registry, you need the Dynatrace configuration object (DynatraceConfig
). The object contains the parameters of metric ingestion and is used to construct the Dynatrace registry (DynatraceMeterRegistry
), which is registered with Micrometer to ingest metrics to Dynatrace. You can set the following parameters:
Property | Description | Required |
---|---|---|
api-version | The version of the Dynatrace API to ingest data to Dynatrace:
| optional |
uri | The ingestion endpoint of the API. | optional |
metric-key-prefix | The prefix to be added to all ingested metric keys (for example, a namespace). | optional |
enrich-with-dynatrace-metadata | Enrich ( If not set, | optional |
default-dimensions | A list of dimensions to be added to the ingested metrics. Dimensions are defined as key-value pairs. | optional |
use-dynatrace-summary-instruments | Micrometer versions 1.9.x+ Ignore the Dynatrace-specific implementation for summary instruments ( The default ( | optional |
export-meter-metadata | Micrometer versions 1.12.x+ Turn meter metadata export (unit & description) on or off. The default ( | optional |
Additional information
Metric types
All metrics are transformed to follow the Metric ingestion protocol types used by Dynatrace.
Micrometer instrument | Dynatrace metric type |
---|---|
Gauge |
|
Counter |
|
Timer |
|
DistributionSummary |
|
LongTaskTimer |
|
TimeGauge |
|
FunctionCounter |
|
FunctionTimer |
|
Meter metadata
Starting with version 1.12.0 of the Dynatrace Micrometer registry, meter metadata (unit and description) is automatically exported to Dynatrace. No code changes are required to start exporting metadata. To turn off metadata export, use the following configuration:
Meter metadata was introduced with Micrometer 1.12.0, which was first included in Spring Boot 3.2.0. The toggles described below are therefore available from Spring Boot 3.2.0.
1management:2 metrics:3 export:4 dynatrace:5 v2:6 export-meter-metadata: false # default: true
1management.dynatrace.metrics.export.v2.export-meter-metadata=false
For previous versions of Micrometer, you need to specify the metadata manually using the Dynatrace web UI or API For more information, see Custom metric metadata.
Capture JVM metrics in Micrometer
By default, JVM metrics are turned off when running Micrometer without Spring Boot. To learn how to enable them, see the Micrometer documentation. After they are enabled and registered with the Dynatrace registry (DynatraceMeterRegistry
), JVM metrics are created and sent to Dynatrace automatically.
On hosts that are monitored by OneAgent, these metrics might already be captured by OneAgent.
Restrict ingestion of specific metrics
When running Micrometer in Spring Boot, many metrics are automatically created and sent to Dynatrace, including JVM, process, and disk metrics.
To see all metrics created by your Spring Boot application, navigate to the actuator endpoint on your Spring Boot app (/actuator/metrics
). Some of these metrics might already be captured by OneAgent.
Disable metrics with Spring properties
Metrics can be disabled based on their prefix in the Spring Boot configuration. To find out which metrics can be excluded, check your Spring Boot applications actuator endpoint. Be sure to exclude the metric key prefix (if any) when using this feature.
1management.metrics.enable:2 # disable jvm.memory metrics3 jvm.memory: false4 # disable all jvm metrics:5 jvm: false
1# disable jvm.memory metrics2management.metrics.enable.jvm.memory=false3# disable all jvm metrics4management.metrics.enable.jvm=false
It is also possible to disable all metrics first and then only re-enable the desired ones:
1management.metrics.enable:2 # disable all metrics3 all: false4 # re-enable only jvm.* metrics5 jvm: true
1# disable all metrics2management.metrics.enable.all=false3# re-enable jvm.* metrics4management.metrics.enable.jvm=true
Disable metrics in code
Micrometer provides meter filters to disable metrics based on a variety of reasons. Meter filters can also be configured via Spring Boot with the @Configuration
annotation.
1@Configuration(proxyBeanMethods = false)2public class MyMeterRegistryConfiguration {34 @Bean5 public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {6 return registry -> registry.config()7 .meterFilter(MeterFilter.denyNameStartsWith("jvm.gc"));8 }9}
The metric prefix configured for the Dynatrace registry will be applied after filtering, so properties to enable or disable metrics have to be specified using the original metric key without this prefix.
Add MeterFilters before you turn on additional metrics, as the meter filter will otherwise be overridden.
Troubleshooting with logs
Spring handles the logging when using Micrometer in the Spring Boot context. The log level for the Micrometer Dynatrace registry can be set via configuration properties.
1logging.level.io.micrometer.dynatrace: DEBUG
1logging.level.io.micrometer.dynatrace=DEBUG
Dynatrace summary instruments
Starting with Micrometer version 1.9.x, specialized instruments are used in the Dynatrace meter registry for certain summary instruments (DynatraceTimer
and DynatraceDistributionSummary
). Their purpose is to get around a peculiarity in how Micrometer records metrics, which, in some cases, led to metrics being rejected by Dynatrace for having an invalid format. The specialized instruments, tailored to Dynatrace metrics ingestion, prevent the creation of invalid metrics.
They are available from version 1.9.0 and are used as a drop-in replacement by default. No action is needed from users upgrading to 1.9.0.
- If there's a discrepancy in the observed metrics, it's possible to return to the previous behavior by setting the
useDynatraceSummaryInstruments
toggle tofalse
.
Dynatrace Micrometer registry v1 (legacy)
If the apiVersion property is set to V1
, the registry sends data via the Timeseries API v1. For backward compatibility, it defaults to V1
if a deviceId is specified, because this property is required in V1
and is not used in V2
.
Existing setups will continue to work when updating to newer versions of Micrometer. The reported metrics will be assigned to custom devices in Dynatrace.
For the V1
API, you only need to specify the base URL of your environment (for example, https://mySampleEnv.live.dynatrace.com
).
1management.dynatrace.metrics.export:2 # For v1 export, do not append a path to the endpoint URL. For example:3 # For SaaS: https://{your-environment-id}.live.dynatrace.com4 # For Managed deployments: https://{your-domain}/e/{your-environment-id}5 uri: https://{your-environment-id}.live.dynatrace.com67 # Should be read from a secure source8 api-token: MY_TOKEN910 # When setting the device id, metrics will be exported to the v1 timeseries endpoint11 # Using just device-id (without the v1 prefix) is deprecated, but will work to maintain backwards compatibility.12 v1:13 device-id: sample1415 # To disable Dynatrace publishing (for example, in a local development profile), use:16 # enabled: false1718 # The interval at which metrics are sent to Dynatrace. The default is 1 minute.19 step: 1m
1DynatraceConfig dynatraceConfig = new DynatraceConfig() {2 @Override3 public String uri() {4 // The Dynatrace environment URI without any path. For example:5 // https://{your-environment-id}.live.dynatrace.com6 return MY_DYNATRACE_URI;7 }89 @Override10 public String apiToken() {11 // Should be read from a secure source12 return MY_TOKEN;13 }1415 @Override16 public String deviceId() {17 return MY_DEVICE_ID;18 }1920 @Override21 @Nullable22 public String get(String k) {23 return null;24 }25};26DynatraceMeterRegistry registry = DynatraceMeterRegistry.builder(config).build();27// Add the Dynatrace registry to Micrometers global registry.28Metrics.addRegistry(registry);