Class ElasticsearchMetricExporter

Object
ElasticsearchMetricExporter
All Implemented Interfaces:
AggregationTemporalitySelector, DefaultAggregationSelector, MetricExporter, Closeable, AutoCloseable

public final class ElasticsearchMetricExporter extends Object implements MetricExporter
Push Metric Exporter to ElasticSearch.

It is based on Java HttpClient and sends all metrics using ElastiSearch Bulk API

Measurements are aggregated with AggregationTemporality.DELTA

Currently supporter metric types:

  • MetricDataType.LONG_SUM
  • MetricDataType.HISTOGRAM

Export schema is based on field names given in ExportSchema.

If ElasticSearch has self-signed SSL certificates by default Java will not allow to connect to it. Use ElasticsearchMetricExporter(URI, Optional, Duration, boolean) with insecure set to "true".

Usage


 var metricReader = PeriodicMetricReader
   .builder(new ElasticsearchMetricExporter(
     URI.create("https://localhost:9200/mymetrics"), Optional.of(new Credentials("elastic", "pass"))))
   .setInterval(Duration.ofSeconds(3))
   .build();
 var sdkMeterProvider = SdkMeterProvider.builder()
   .registerMetricReader(metricReader).build();
 OpenTelemetrySdk.builder()
   .setMeterProvider(sdkMeterProvider)
   .buildAndRegisterGlobal();
 
See Also:
  • Constructor Details

    • ElasticsearchMetricExporter

      public ElasticsearchMetricExporter(URI elasticSearch)
      Parameters:
      elasticSearch - URI to the ElasticSearch index where metrics will be exported. Credentials can be part of the URL. Example http://user:password@localhost:9200/customers They are optional to allow anonymous access if it is enabled on ElasticSearch.
    • ElasticsearchMetricExporter

      public ElasticsearchMetricExporter(URI elasticSearch, Optional<ElasticsearchMetricExporter.Credentials> credentials)
      Parameters:
      credentials - ElasticSearch user and password. They are optional to allow anonymous access if it is enabled on ElasticSearch.
    • ElasticsearchMetricExporter

      public ElasticsearchMetricExporter(URI elasticSearch, Optional<ElasticsearchMetricExporter.Credentials> credentials, Duration timeout, boolean insecure)
      Parameters:
      insecure - allow connections to ElasticSearch with self-signed SSL certificates
  • Method Details

    • export

      public CompletableResultCode export(Collection<MetricData> metrics)
      Specified by:
      export in interface MetricExporter
    • flush

      public CompletableResultCode flush()
      Specified by:
      flush in interface MetricExporter
    • shutdown

      public CompletableResultCode shutdown()
      Specified by:
      shutdown in interface MetricExporter
    • getAggregationTemporality

      public AggregationTemporality getAggregationTemporality(InstrumentType instrumentType)
      Specified by:
      getAggregationTemporality in interface AggregationTemporalitySelector