This version is still in development and is not considered stable yet. For the latest stable version, please use Micrometer 1.14.0! |
Micrometer Elastic
Elasticsearch is an open source search and analytics platform. Metrics stored in Elasticsearch can be visualized in Kibana.
1. Installing micrometer-registry-elastic
For Gradle, add the following implementation:
implementation 'io.micrometer:micrometer-registry-elastic:latest.release'
For Maven, add the following dependency:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-elastic</artifactId>
<version>${micrometer.version}</version>
</dependency>
2. Configuring
The following example configures an ElasticSearch instance:
ElasticConfig elasticConfig = new ElasticConfig() {
@Override
@Nullable
public String get(String k) {
return null;
}
};
MeterRegistry registry = new ElasticMeterRegistry(elasticConfig, Clock.SYSTEM);
ElasticConfig
is an interface with a set of default methods. If, in the implementation of get(String k)
, rather than returning null
, you instead bind it to a property source, you can override the default configuration. For example, Micrometer’s Spring Boot support binds properties that are prefixed with management.metrics.export.elastic
directly to the ElasticConfig
:
management.metrics.export.elastic:
# You will probably want disable Elastic publishing in a local development profile.
enabled: true
# The interval at which metrics are sent to Elastic. The default is 1 minute.
step: 1m
# The index to store metrics in, defaults to "micrometer-metrics"
index: micrometer-metrics
3. Elastic APM agent integration
If you are using the Elastic APM agent, it can automatically collect metrics from Micrometer MeterRegistry
instances. If you want only metrics collected by the Elastic APM agent and not shipped anywhere else, you can use the SimpleMeterRegistry
. See the Elastic docs for more details.