---
title: Monitor self-hosted Elasticsearch with the Prometheus receiver
source: https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/self-hosted/prometheus-receiver
---

This page configures the OpenTelemetry Collector's Prometheus receiver to monitor a self-hosted Elasticsearch cluster through an existing [Prometheus Elasticsearch exporter](https://github.com/prometheus-community/elasticsearch_exporter). Use this path only if you already run that exporter, or are migrating from a Prometheus-based monitoring stack. If not, use [NRDOT](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/self-hosted/nrdot) or [OTel Collector Contrib](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/self-hosted/otel-collector-contrib) instead, which connect directly to the Elasticsearch API without an extra component.

## Compatibility and requirements [#requirements]

### Supported

-   Elasticsearch 7.16 or later, monitored via `elasticsearch_exporter` 1.x

### You need

-   A New Relic [license key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#ingest-license-key)
-   Root or sudo privileges on the host running the exporter and the collector
-   Outbound HTTPS (port 443) connectivity to New Relic's [OTLP endpoint](https://docs.newrelic.com/docs/opentelemetry/best-practices/opentelemetry-otlp)

## Install NRDOT collector or OTel Collector Contrib [#install]

Install either the [NRDOT collector](https://docs.newrelic.com/docs/opentelemetry/nrdot/nrdot-collector/) or [OpenTelemetry Collector Contrib](https://github.com/open-telemetry/opentelemetry-collector-contrib/releases/latest) and run it as a systemd service. Official `.deb`/`.rpm` packages create the service unit for you.

## Install and configure the Elasticsearch exporter [#install-exporter]

The [Prometheus Elasticsearch exporter](https://github.com/prometheus-community/elasticsearch_exporter) exposes Elasticsearch metrics in Prometheus format on port `9114`.

1.  Download the exporter:

    ```bash
    wget https://github.com/prometheus-community/elasticsearch_exporter/releases/download/v1.8.0/elasticsearch_exporter-1.8.0.linux-amd64.tar.gz
    tar xzf elasticsearch_exporter-*.tar.gz
    cd elasticsearch_exporter-*
    ```

2.  Start the exporter, pointed at your Elasticsearch instance:

    ```bash
    ./elasticsearch_exporter --es.uri=http://<YOUR_ELASTICSEARCH_HOST>:9200
    ```

    For a secured cluster, use `--es.uri=https://<YOUR_ELASTICSEARCH_USERNAME>:<YOUR_ELASTICSEARCH_PASSWORD>@<YOUR_ELASTICSEARCH_HOST>:9200 --es.ssl-skip-verify`. The `--es.ssl-skip-verify` flag turns off TLS certificate verification, so use it only for testing and use a trusted certificate in production.

    This command runs in the foreground, so keep this terminal open and use a second terminal for the next step. The exporter stops when you close the session, so to keep it running, run it as a systemd service or under a process manager.

3.  Verify the exporter is running:

    ```bash
    curl http://localhost:9114/metrics | grep elasticsearch_cluster_health
    ```

    You should see Prometheus-formatted metrics like `elasticsearch_cluster_health_status`. If nothing returns, the exporter isn't reachable. Check its process and the `--es.uri` value before continuing.

## Configure the collector [#configure]

This configuration works with both NRDOT and OTel Collector Contrib. Place it in the appropriate config location for your collector, `/etc/nrdot-collector/config.yaml` for NRDOT or `/etc/otelcol-contrib/config.yaml` for OTel Collector Contrib, replacing its existing contents. This maps the exporter's Prometheus metric names to the OTel-style names that power the New Relic Elasticsearch dashboard.

Before you replace the file, back up the existing configuration for your collector:

```bash
# NRDOT
sudo cp /etc/nrdot-collector/config.yaml /etc/nrdot-collector/config.yaml.backup

# OTel Collector Contrib
sudo cp /etc/otelcol-contrib/config.yaml /etc/otelcol-contrib/config.yaml.backup
```

Then use this configuration:

```yaml
receivers:
  prometheus/elasticsearch:
    config:
      scrape_configs:
        - job_name: 'elasticsearch'
          scrape_interval: 15s
          static_configs:
            - targets: ['localhost:9114']  # <-- elasticsearch_exporter address

processors:
  memory_limiter:
    check_interval: 60s
    limit_mib: ${env:NEW_RELIC_MEMORY_LIMIT_MIB:-100}
  metricstransform/prom_to_otel:
    transforms:
      - include: ^elasticsearch_cluster_health_number_of_data_nodes$
        match_type: regexp
        action: update
        new_name: elasticsearch.cluster.data_nodes
      - include: ^elasticsearch_cluster_health_status$
        match_type: regexp
        action: update
        new_name: elasticsearch.cluster.health
        operations:
          - action: update_label
            label: color
            new_label: status
      - include: ^elasticsearch_cluster_health_number_of_in_flight_fetch$
        match_type: regexp
        action: update
        new_name: elasticsearch.cluster.in_flight_fetch
      - include: ^elasticsearch_cluster_health_number_of_nodes$
        match_type: regexp
        action: update
        new_name: elasticsearch.cluster.nodes
      - include: ^elasticsearch_cluster_health_number_of_pending_tasks$
        match_type: regexp
        action: update
        new_name: elasticsearch.cluster.pending_tasks
      - include: ^elasticsearch_cluster_health_active_shards$
        match_type: regexp
        action: update
        new_name: elasticsearch.cluster.shards
        operations:
          - action: add_label
            new_label: state
            new_value: active
      - include: ^elasticsearch_cluster_health_active_primary_shards$
        match_type: regexp
        action: update
        new_name: elasticsearch.cluster.shards
        operations:
          - action: add_label
            new_label: state
            new_value: active_primary
      - include: ^elasticsearch_cluster_health_initializing_shards$
        match_type: regexp
        action: update
        new_name: elasticsearch.cluster.shards
        operations:
          - action: add_label
            new_label: state
            new_value: initializing
      - include: ^elasticsearch_cluster_health_relocating_shards$
        match_type: regexp
        action: update
        new_name: elasticsearch.cluster.shards
        operations:
          - action: add_label
            new_label: state
            new_value: relocating
      - include: ^elasticsearch_cluster_health_unassigned_shards$
        match_type: regexp
        action: update
        new_name: elasticsearch.cluster.shards
        operations:
          - action: add_label
            new_label: state
            new_value: unassigned
      - include: ^elasticsearch_indices_docs$
        match_type: regexp
        action: insert
        new_name: elasticsearch.node.documents
        operations:
          - action: add_label
            new_label: state
            new_value: active
      - include: ^elasticsearch_indices_docs$
        match_type: regexp
        action: insert
        new_name: elasticsearch.index.documents
        operations:
          - action: add_label
            new_label: state
            new_value: active
          - action: add_label
            new_label: aggregation
            new_value: primary_shards
          - action: add_label
            new_label: elasticsearch.index.name
            new_value: _all
      - include: ^elasticsearch_indices_docs_deleted$
        match_type: regexp
        action: insert
        new_name: elasticsearch.node.documents
        operations:
          - action: add_label
            new_label: state
            new_value: deleted
      - include: ^elasticsearch_indices_fielddata_evictions$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.cache.evictions
        operations:
          - action: add_label
            new_label: cache_name
            new_value: fielddata
      - include: ^elasticsearch_indices_query_cache_evictions$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.cache.evictions
        operations:
          - action: add_label
            new_label: cache_name
            new_value: query
      - include: ^elasticsearch_indices_fielddata_memory_size_bytes$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.cache.memory.usage
        operations:
          - action: add_label
            new_label: cache_name
            new_value: fielddata
      - include: ^elasticsearch_indices_query_cache_memory_size_bytes$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.cache.memory.usage
        operations:
          - action: add_label
            new_label: cache_name
            new_value: query
      - include: ^elasticsearch_transport_rx_size_bytes_total$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.cluster.io
        operations:
          - action: add_label
            new_label: direction
            new_value: received
      - include: ^elasticsearch_transport_tx_size_bytes_total$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.cluster.io
        operations:
          - action: add_label
            new_label: direction
            new_value: sent
      - include: ^elasticsearch_filesystem_data_available_bytes$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.fs.disk.available
      - include: ^elasticsearch_filesystem_data_size_bytes$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.fs.disk.total
      - include: ^elasticsearch_process_open_files_count$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.open_files
      - include: ^elasticsearch_indices_indexing_index_total$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.operations.completed
        operations:
          - action: add_label
            new_label: operation
            new_value: index
      - include: ^elasticsearch_indices_search_query_total$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.operations.completed
        operations:
          - action: add_label
            new_label: operation
            new_value: query
      - include: ^elasticsearch_indices_get_total$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.operations.completed
        operations:
          - action: add_label
            new_label: operation
            new_value: get
      - include: ^elasticsearch_indices_merges_total$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.operations.completed
        operations:
          - action: add_label
            new_label: operation
            new_value: merge
      - include: ^elasticsearch_indices_indexing_index_time_seconds_total$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.operations.time
        operations:
          - action: add_label
            new_label: operation
            new_value: index
          - action: experimental_scale_value
            experimental_scale: 1000
      - include: ^elasticsearch_indices_search_query_time_seconds$
        match_type: regexp
        action: update
        new_name: elasticsearch.node.operations.time
        operations:
          - action: add_label
            new_label: operation
            new_value: query
          - action: experimental_scale_value
            experimental_scale: 1000
      - include: ^elasticsearch_thread_pool_active_count$
        match_type: regexp
        action: insert
        new_name: elasticsearch.node.operations.current
        operations:
          - action: update_label
            label: type
            new_label: operation
      - include: ^elasticsearch_os_cpu_percent$
        match_type: regexp
        action: update
        new_name: elasticsearch.os.cpu.usage
      - include: ^elasticsearch_os_load1$
        match_type: regexp
        action: update
        new_name: elasticsearch.os.cpu.load_avg.1m
      - include: ^elasticsearch_os_load5$
        match_type: regexp
        action: update
        new_name: elasticsearch.os.cpu.load_avg.5m
      - include: ^elasticsearch_os_load15$
        match_type: regexp
        action: update
        new_name: elasticsearch.os.cpu.load_avg.15m
      - include: ^elasticsearch_jvm_gc_collection_seconds_count$
        match_type: regexp
        action: update
        new_name: jvm.gc.collections.count
      - include: ^elasticsearch_jvm_gc_collection_seconds_sum$
        match_type: regexp
        action: update
        new_name: jvm.gc.collections.elapsed
        operations:
          - action: experimental_scale_value
            experimental_scale: 1000
      - include: ^elasticsearch_jvm_memory_max_bytes$
        match_type: regexp
        action: update
        new_name: jvm.memory.heap.max
      - include: ^elasticsearch_jvm_memory_used_bytes$
        match_type: regexp
        action: update
        new_name: jvm.memory.heap.used
      - include: ^elasticsearch_thread_pool_threads_count$
        match_type: regexp
        action: update
        new_name: jvm.threads.count
        operations:
          - action: aggregate_labels
            label_set: [name, cluster]
            aggregation_type: sum
      - include: ^elasticsearch_indices_segments_count$
        match_type: regexp
        action: update
        new_name: elasticsearch.index.segments.count

  filter/allowed_metrics:
    metrics:
      include:
        match_type: strict
        metric_names:
          - elasticsearch.cluster.data_nodes
          - elasticsearch.cluster.health
          - elasticsearch.cluster.in_flight_fetch
          - elasticsearch.cluster.nodes
          - elasticsearch.cluster.pending_tasks
          - elasticsearch.cluster.shards
          - elasticsearch.index.documents
          - elasticsearch.index.segments.count
          - elasticsearch.node.cache.evictions
          - elasticsearch.node.cache.memory.usage
          - elasticsearch.node.cluster.io
          - elasticsearch.node.documents
          - elasticsearch.node.fs.disk.available
          - elasticsearch.node.fs.disk.total
          - elasticsearch.node.open_files
          - elasticsearch.node.operations.completed
          - elasticsearch.node.operations.current
          - elasticsearch.node.operations.time
          - elasticsearch.os.cpu.usage
          - elasticsearch.os.cpu.load_avg.1m
          - elasticsearch.os.cpu.load_avg.5m
          - elasticsearch.os.cpu.load_avg.15m
          - jvm.gc.collections.count
          - jvm.gc.collections.elapsed
          - jvm.memory.heap.max
          - jvm.memory.heap.used
          - jvm.threads.count

  transform/rename_node_name:
    metric_statements:
      - context: datapoint
        statements:
          - set(attributes["elasticsearch.node.name"], attributes["name"]) where attributes["name"] != nil
          - delete_key(attributes, "name") where attributes["elasticsearch.node.name"] != nil

  groupbyattrs/node:
    keys:
      - elasticsearch.node.name
      - elasticsearch.cluster.name

  cumulativetodelta: {}

  resource/cluster_name_override:
    attributes:
      - key: elasticsearch.cluster.name
        value: "<YOUR_ELASTICSEARCH_CLUSTER_NAME>"
        action: upsert

  transform/scope_override:
    metric_statements:
      - context: scope
        statements:
          - set(name, "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/elasticsearchreceiver")
          - set(version, "")

  resourcedetection:
    detectors: [system]
    system:
      resource_attributes:
        host.name:
          enabled: true
        host.id:
          enabled: true
        os.type:
          enabled: true

  batch:
    timeout: 30s
    send_batch_size: 2048
    send_batch_max_size: 4096

  attributes/cardinality_reduction:
    actions:
      - key: process.pid
        action: delete
      - key: process.parent_pid
        action: delete

  transform/metadata_nullify:
    metric_statements:
      - context: metric
        statements:
          - set(description, "")
          - set(unit, "")

exporters:
  otlphttp:
    endpoint: ${env:NEWRELIC_OTLP_ENDPOINT}
    headers:
      api-key: ${env:NEWRELIC_LICENSE_KEY}
    compression: gzip
    timeout: 30s
    retry_on_failure:
      enabled: true
      initial_interval: 5s
      max_interval: 30s
      max_elapsed_time: 300s

service:
  pipelines:
    metrics/elasticsearch:
      receivers: [prometheus/elasticsearch]
      processors:
        - memory_limiter
        - metricstransform/prom_to_otel
        - filter/allowed_metrics
        - transform/rename_node_name
        - groupbyattrs/node
        - transform/scope_override
        - resourcedetection
        - resource/cluster_name_override
        - attributes/cardinality_reduction
        - cumulativetodelta
        - transform/metadata_nullify
        - batch
      exporters: [otlphttp]
```

### Configuration parameters [#configuration-parameters]

The following table describes the key configuration parameters used in the configuration above:

| Parameter                                                          | Description                                                                                                                                                            |
| ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `targets`                                                          | The address of your `elasticsearch_exporter`, updating `localhost:9114` if it's running on a different host or port.                                                   |
| `elasticsearch.cluster.name` (in `resource/cluster_name_override`) | A unique name identifying this cluster in New Relic, replacing `<YOUR_ELASTICSEARCH_CLUSTER_NAME>` with a name that's unique across your account.                      |
| `NEW_RELIC_MEMORY_LIMIT_MIB`                                       | The memory limit, in MiB, for the collector's `memory_limiter` processor, set to fit your environment.                                                                 |
| `NEWRELIC_LICENSE_KEY`                                             | Your New Relic [license key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#ingest-license-key).                                                   |
| `NEWRELIC_OTLP_ENDPOINT`                                           | The New Relic OTLP endpoint for your account's region, per [New Relic OTLP endpoints](https://docs.newrelic.com/docs/opentelemetry/best-practices/opentelemetry-otlp). |

## Set the environment variables [#env-vars]

Replace `<collector-service>` in the commands below with `nrdot-collector` or `otelcol-contrib`, matching the collector you're using. Then set the credentials and connection details the collector needs to send data to New Relic.

```bash
sudo mkdir -p /etc/systemd/system/<collector-service>.service.d
cat <<EOF | sudo tee /etc/systemd/system/<collector-service>.service.d/environment.conf
[Service]
Environment="NEWRELIC_OTLP_ENDPOINT=<YOUR_NEWRELIC_OTLP_ENDPOINT>"
Environment="NEWRELIC_LICENSE_KEY=<YOUR_NEWRELIC_LICENSE_KEY>"
Environment="NEW_RELIC_MEMORY_LIMIT_MIB=100"
EOF
```

## Restart the collector [#restart]

Restart the collector to apply your changes, using the same `<collector-service>` value as in the previous step:

```bash
sudo systemctl daemon-reload
sudo systemctl enable <collector-service>
sudo systemctl restart <collector-service>
```

## Verify data collection [#verify]

Within ~5 minutes of restarting the collector, run this query in New Relic to confirm data is flowing (replace `<YOUR_ELASTICSEARCH_CLUSTER_NAME>` with your cluster's name):

```sql
FROM Metric SELECT count(*)
WHERE metricName LIKE 'elasticsearch.%'
AND elasticsearch.cluster.name = '<YOUR_ELASTICSEARCH_CLUSTER_NAME>'
SINCE 10 minutes ago
```

> #### 💡 TIP
>
> You can also check the collector itself. It should report `active (running)` (`sudo systemctl status <collector-service>`), with no connection errors in the logs (`sudo journalctl -u <collector-service> -f`).

If you don't see data within ~5 minutes, see [Elasticsearch troubleshooting](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/troubleshooting).

## Find and use your data [#find-and-use]

Once New Relic collects your data, you can access Elasticsearch monitoring through the New Relic UI.

To find your Elasticsearch dashboard in New Relic:

1.  Go to **one.newrelic.com > Integrations & Agents**.
2.  Under the **All** tab, click **Dashboards**, then search for **Elasticsearch (OpenTelemetry Collector)** to view the dashboard.

Or, from the left navigation:

1.  Click **Dashboards**.
2.  Search for the **Elasticsearch (OpenTelemetry Collector)** dashboard to view it.

After setting up Elasticsearch monitoring, you can:

-   [Create custom dashboards](https://docs.newrelic.com/docs/query-your-data/explore-query-data/dashboards/introduction-dashboards/) to visualize your Elasticsearch metrics
-   [Set up alerts](https://docs.newrelic.com/docs/alerts/create-alert/create-alert-condition/alert-conditions/) for critical cluster health and performance thresholds
-   [Explore your data](https://docs.newrelic.com/docs/query-your-data/explore-query-data/browse-data/introduction-data-explorer/) using New Relic query capabilities

> #### 💡 TIP
>
> **Correlate APM with Elasticsearch**: To connect your APM application and Elasticsearch cluster, include the resource attribute `es.cluster.name="your-cluster-name"` in your APM metrics. This lets you view APM and Elasticsearch data together in New Relic.

## Related articles [#related-articles]

-   [Correlate APM with Elasticsearch using distributed tracing](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/distributed-tracing)
-   [Elasticsearch metrics reference](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/metrics-reference)
-   [Elasticsearch troubleshooting](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/troubleshooting)
