Send Micrometer metrics to Dynatrace
Micrometer is an open-source instrumentation framework for JVM-based application metrics. It is 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:
The Spring Boot BOM specifies a Micrometer version that has been tested with the respective version of Spring Boot. It's therefore enough to specify the name of the dependency without specifying the version. This will result in the correct, matching version being pulled by Gradle or Maven.
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 management.metrics.export.dynatrace
to the Dynatrace configuration object.
Important: All configuration should be made through the properties. Manually creating a Micrometer MeterRegistry
will break the auto-configuration.
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.
For hosts running in an environment where Dynatrace Operator is installed, Dynatrace Operator provides the URI and token to the environment. More information about this feature can be found in the Operator documentation.
- In Micrometer 1.9.0+, they are automatically picked up by the Dynatrace Micrometer registry, and data is exported to Dynatrace without the need for additional configuration.
- Explicitly providing a URI will disable this automatic configuration option and should therefore be avoided if using the Dynatrace Kubernetes Operator autoconfiguration.
HTTP clients connecting to the ActiveGate REST endpoint must trust provided certificates. For details, see Add a custom certificate for ActiveGate.
To ingest metrics from hosts where OneAgent is not installed, you need to use the ingest endpoint of Metrics API v2. To learn how to use the endpoint, see POST ingest data points.
You can use the Spring placeholder notation (for example, api-token: ${YOUR_METRICS_INGEST_API_TOKEN}
), which will automatically read the environment variable and supply it to the Micrometer configuration.
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.
For hosts running in an environment where Dynatrace Operator is installed, Dynatrace Operator provides the URI and token to the environment. More information about this feature can be found in the Operator documentation.
- In Micrometer 1.9.0+, they are automatically picked up by the Dynatrace Micrometer registry, and data is exported to Dynatrace without the need for additional configuration.
- Explicitly providing a URI will disable this automatic configuration option and should therefore be avoided if using the Dynatrace Kubernetes Operator autoconfiguration.
HTTP clients connecting to the ActiveGate REST endpoint must trust provided certificates. For details, see Add a custom certificate for ActiveGate.
To ingest metrics from hosts where OneAgent is not installed, you need to use the ingest endpoint of Metrics API v2. To learn how to use the endpoint, see POST ingest data points.
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 |
Property | Description | Required |
---|---|---|
apiVersion | The version of the Dynatrace API to ingest data to Dynatrace:
| optional |
uri | The ingestion endpoint of the API. | optional |
metricKeyPrefix | The prefix to be added to all ingested metric keys (for example, a namespace). | optional |
enrichWithDynatraceMetadata | Enrich ( If not set, | optional |
defaultDimensions | A list of dimensions to be added to the ingested metrics. Dimensions are defined as key-value pairs. | optional |
useDynatraceSummaryInstruments | Micrometer versions 1.9.x+ Ignore the Dynatrace-specific implementation for summary instruments ( 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 |
|
Metric units
The ingestion protocol currently doesn't support automatic unit setting. You must specify units manually. For more information, see Custom metric metadata.
Capture JVM metrics in Micrometer
By default, JVM metrics are turned off in Micrometer. To learn how to enable them, see Micrometer documentation. Once 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.
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.
Note that the metric key prefix is not taken into consideration here.
Add MeterFilters before you turn on additional metrics, as the meter filter will otherwise be overridden.
You can configure the registry to filter out specific metrics by name and/or tags (for example, metrics that are already captured by OneAgent). To achieve that, use Micrometer's meter filters. You need to add meter filters before you enable capture of JVM metrics, otherwise filters will be overridden.
The metric prefix configured for the Dynatrace registry will be applied after filtering, so meterFilters
have to be specified using the original metric key without this prefix.
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.
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
).