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
It is recommended to use the BOM provided by Micrometer (or your framework if any), you can see how to configure it here. The examples below assume you are using a BOM.
1.1. Gradle
After the BOM is configured, add the following dependency:
implementation 'io.micrometer:micrometer-registry-elastic'
The version is not needed for this dependency since it is defined by the BOM. |
1.2. Maven
After the BOM is configured, add the following dependency:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-elastic</artifactId>
</dependency>
The version is not needed for this dependency since it is defined by the BOM. |
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.