Back to Logstash

Monitoring Logstash with OpenTelemetry

docs/reference/monitoring-with-opentelemetry.md

9.5.011.5 KB
Original Source

Monitoring Logstash with OpenTelemetry

Logstash can export metrics to any OpenTelemetry Protocol (OTLP) compatible backend, like Elastic, Prometheus, and others.

Overview

The OpenTelemetry metrics exporter sends Logstash runtime metrics directly using the OpenTelemetry Protocol (OTLP). This provides a standardized way to collect and export metrics without requiring an intermediate collector, though you can also route metrics through an OpenTelemetry Collector if needed.

Configuration

To enable OpenTelemetry metrics export, add the following settings to your logstash.yml file:

yaml
otel.metrics.enabled: true
otel.exporter.otlp.endpoint: "http://localhost:4317"
otel.metric.export.interval: "10s"
otel.exporter.otlp.protocol: "grpc"

Settings

SettingDescriptionDefault
otel.metrics.enabledEnable or disable OpenTelemetry metrics export.false
otel.exporter.otlp.endpointOTLP metrics endpoint URL. For gRPC, the default port is 4317. For HTTP the default port is 4318. When using the HTTP protocol, /v1/metrics is automatically appended if not already present, and the default port (80 for http://, 443 for https://) is added if no port is specified.http://localhost:4317
otel.metric.export.intervalExport interval with time unit. Controls how frequently metrics are sent to the endpoint. For example: 10s or 1m."10s"
otel.exporter.otlp.protocolProtocol to use for OTLP export. Valid values are grpc and http.grpc
otel.exporter.otlp.headersHTTP headers as comma-separated key=value pairs to include in every OTLP request. Example: Authorization=ApiKey xxx or Authorization=Bearer xxx,X-Custom=foo.Not applicable
otel.resource.attributesAdditional resource attributes as comma-separated key=value pairs. Example: environment=production,cluster=us-west.Not applicable
otel.service.nameService name for metrics.logstash
otel.exporter.otlp.certificatePath to a PEM-encoded trusted CA certificate for verifying the OTLP endpoint's TLS certificate. Required when the endpoint uses a self-signed or private CA.Not applicable
otel.exporter.otlp.client.keyPath to a PEM-encoded client private key for mutual TLS (mTLS). Must be set together with otel.exporter.otlp.client.certificate.Not applicable
otel.exporter.otlp.client.certificatePath to a PEM-encoded client certificate for mutual TLS (mTLS). Must be set together with otel.exporter.otlp.client.key.Not applicable

Configuration precedence

OpenTelemetry settings can be configured using Java system properties or by editing the logstash.yml file. The resolution order is:

  1. Java system properties (highest priority). For example, -Dotel.service.name=my-service
  2. logstash.yml (lowest priority)

Supported system properties and their Logstash setting equivalents:

System Propertylogstash.yml Setting
otel.service.nameotel.service.name
otel.exporter.otlp.endpointotel.exporter.otlp.endpoint
otel.exporter.otlp.protocolotel.exporter.otlp.protocol
otel.metric.export.intervalotel.metric.export.interval
otel.resource.attributesotel.resource.attributes
otel.exporter.otlp.headersotel.exporter.otlp.headers
otel.exporter.otlp.certificateotel.exporter.otlp.certificate
otel.exporter.otlp.client.keyotel.exporter.otlp.client.key
otel.exporter.otlp.client.certificateotel.exporter.otlp.client.certificate

Sending metrics to Elastic Cloud

To send metrics directly to the Elastic Cloud Managed OTLP Endpoint:

  1. Get your Elastic Cloud OTLP endpoint from your deployment's settings.
  2. Create an API key with appropriate permissions.
  3. Configure Logstash:
yaml
otel.metrics.enabled: true
otel.exporter.otlp.endpoint: "https://your-deployment.apm.us-central1.gcp.cloud.es.io:443"
otel.exporter.otlp.protocol: "http"
otel.exporter.otlp.headers: "Authorization=ApiKey your-base64-encoded-api-key"

Sending metrics to an OpenTelemetry Collector

You can also send metrics to an OpenTelemetry Collector, which can then forward them to multiple backends:

yaml
otel.metrics.enabled: true
otel.exporter.otlp.endpoint: "http://otel-collector:4317"
otel.exporter.otlp.protocol: "grpc"

Example OpenTelemetry Collector configuration to forward to Elasticsearch:

yaml
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318

processors:
  batch:

exporters:
  elasticsearch:
    endpoints: ["https://your-elasticsearch-host:9200"]
    api_key: "your-api-key"
    mapping:
      mode: otel

service:
  pipelines:
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [elasticsearch]

Exported metrics

Logstash exports the following metrics via OpenTelemetry:

Global metrics

Metric nameTypeUnitDescription
logstash.events.inCounter{event}Total events received across all pipelines
logstash.events.outCounter{event}Total events output across all pipelines
logstash.events.filteredCounter{event}Total events filtered across all pipelines
logstash.queue.eventsGauge{event}Total events currently in queues

Pipeline metrics

Pipeline metrics include a pipeline.id attribute to identify the pipeline.

Metric nameTypeUnitDescription
logstash.pipeline.events.inCounter{event}Events received by pipeline
logstash.pipeline.events.outCounter{event}Events output by pipeline
logstash.pipeline.events.filteredCounter{event}Events filtered by pipeline
logstash.pipeline.queue.eventsGauge{event}Events in pipeline queue

Persistent queue metrics

These metrics are available when using persistent queues (queue.type: persisted).

Metric nameTypeUnitDescription
logstash.pipeline.queue.capacity.page_capacityGaugeBySize of each queue page in bytes
logstash.pipeline.queue.capacity.max_sizeGaugeByMaximum queue size limit in bytes
logstash.pipeline.queue.capacity.max_unread_eventsGauge{event}Maximum unread events allowed
logstash.pipeline.queue.capacity.sizeGaugeByCurrent persisted queue size in bytes
logstash.pipeline.queue.data.free_spaceGaugeByFree disk space where queue is stored

Dead letter queue metrics

Metric nameTypeUnitDescription
logstash.pipeline.dlq.queue_sizeGaugeByCurrent dead letter queue size in bytes
logstash.pipeline.dlq.max_queue_sizeGaugeByMaximum DLQ size limit in bytes
logstash.pipeline.dlq.dropped_eventsGauge{event}Events dropped when DLQ is full
logstash.pipeline.dlq.expired_eventsGauge{event}Events expired and removed from DLQ

Plugin metrics

Plugin metrics include pipeline.id, plugin.type, and plugin.id attributes.

Metric nameTypeUnitDescription
logstash.plugin.events.inCounter{event}Events received by plugin
logstash.plugin.events.outCounter{event}Events output by plugin
logstash.plugin.events.durationCountermsTime spent processing events

JVM metrics

Metric nameTypeUnitDescription
logstash.jvm.uptimeGaugemsJVM uptime since start
logstash.jvm.mem.heap.usedGaugeByHeap memory currently used
logstash.jvm.mem.heap.committedGaugeByHeap memory committed to the JVM
logstash.jvm.mem.heap.maxGaugeByMaximum heap memory available
logstash.jvm.mem.heap.used_percentGauge%Heap memory used as a percentage of max
logstash.jvm.mem.non_heap.usedGaugeByNon-heap memory currently used
logstash.jvm.mem.non_heap.committedGaugeByNon-heap memory committed to the JVM
logstash.jvm.gc.collection_countCounter{collection}Number of GC collections. Includes a gc.generation attribute (young or old).
logstash.jvm.gc.collection_timeCountermsTotal time spent in GC. Includes a gc.generation attribute (young or old).
logstash.jvm.threads.countGauge{thread}Current number of JVM threads
logstash.jvm.threads.peak_countGauge{thread}Peak number of JVM threads since start
logstash.jvm.process.open_file_descriptorsGauge{file_descriptor}Number of open file descriptors
logstash.jvm.process.max_file_descriptorsGauge{file_descriptor}Maximum number of file descriptors
logstash.jvm.process.cpu.percentGauge%Process CPU usage
logstash.jvm.process.cpu.totalCountermsTotal CPU time consumed by the process

Cgroup metrics (Linux only)

These metrics are available when running on Linux with cgroups enabled, for example in containers.

Metric nameTypeUnitDescription
logstash.os.cgroup.cpuacct.usageCounternsTotal CPU time consumed
logstash.os.cgroup.cpu.cfs_periodGaugeusCFS scheduling period
logstash.os.cgroup.cpu.cfs_quotaGaugeusCFS scheduling quota
logstash.os.cgroup.cpu.stat.elapsed_periodsCounter{period}Number of elapsed CFS periods
logstash.os.cgroup.cpu.stat.nr_times_throttledCounter{occurrence}Number of times throttled
logstash.os.cgroup.cpu.stat.time_throttledCounternsTotal time throttled

Resource attributes

The following resource attributes are automatically added to all metrics:

AttributeDescription
service.nameDefaults to logstash; configurable via otel.service.name
service.instance.idThe Logstash node ID
host.nameThe Logstash node name (node.name)
data_stream.datasetAlways logstash; the Elastic ingest endpoint appends .otel, resulting in logstash.otel

Additional resource attributes can be added using the otel.resource.attributes setting.

Viewing metrics in Kibana

When sending metrics to Elastic Cloud via the native OTLP endpoint, metrics are stored in APM data streams (.ds-metrics-apm.app.logstash-*). You can view them in:

  1. Find your Logstash service under Observability → APM → Services.
  2. Query metrics directly in Observability → Metrics Explorer.
  3. Search the metrics-apm.app.logstash-* data view using Discover.

When using an OpenTelemetry Collector with the Elasticsearch exporter, create a data view matching your configured index pattern. For example, metrics-otel-*.

Troubleshooting

Enable debug logging

To see detailed OpenTelemetry SDK logs, add the following to config/log4j2.properties:

properties
logger.otel.name = io.opentelemetry
logger.otel.level = debug

Common issues

Connection refused errors

Verify the endpoint is accessible:

  • For gRPC (default): Port 4317
  • For HTTP: Port 4318 with /v1/metrics path automatically appended
  • If no port is specified, defaults are used: 80 for http://, 443 for https://

Authentication errors

Ensure the otel.exporter.otlp.headers is correctly formatted:

  • For API keys: ApiKey base64-encoded-key
  • For Bearer tokens: Bearer your-token

Metrics not appearing

  • Check that otel.metrics.enabled is set to true
  • Verify the export interval hasn't been set too high
  • Check Logstash logs for export errors