---
title: Install and configure OTel Collector Contrib on self-hosted Elasticsearch
source: https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/self-hosted/otel-collector-contrib
---

Use this guide to install and configure OpenTelemetry Collector Contrib to monitor a self-hosted Elasticsearch cluster on a Linux server or VM. Once you configure it, the collector exports your Elasticsearch cluster metrics to New Relic. For host metrics, logs, and custom tags, see [Advanced configuration](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/advanced-configuration).

## Compatibility and requirements [#requirements]

### Supported

-   Elasticsearch 7.16 or later

### 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
-   Elasticsearch cluster admin privileges with `monitor` or `manage` cluster privilege (see [Elasticsearch security privileges](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-privileges.html))
-   Outbound HTTPS (port 443) connectivity to New Relic's [OTLP endpoint](https://docs.newrelic.com/docs/opentelemetry/best-practices/opentelemetry-otlp)
-   An Elasticsearch username and password (if your cluster requires authentication)

## Install OTel Collector Contrib [#install]

Install [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.

## Configure the OTel Collector Contrib for Elasticsearch monitoring [#configure]

Update the collector's default configuration to enable Elasticsearch monitoring.

1.  Back up the collector's default configuration, then open it for editing:

    ```bash
    sudo cp /etc/otelcol-contrib/config.yaml /etc/otelcol-contrib/config.yaml.backup
    sudo nano /etc/otelcol-contrib/config.yaml
    ```

2.  Delete all existing content and replace it with the following configuration for Elasticsearch monitoring.

    ```yaml
    receivers:
      elasticsearch:
        endpoint: "http://<YOUR_ELASTICSEARCH_HOST>:9200"
        collection_interval: 15s
        metrics:
          elasticsearch.os.cpu.usage:
            enabled: true
          elasticsearch.cluster.data_nodes:
            enabled: true
          elasticsearch.cluster.health:
            enabled: true
          elasticsearch.cluster.in_flight_fetch:
            enabled: true
          elasticsearch.cluster.nodes:
            enabled: true
          elasticsearch.cluster.pending_tasks:
            enabled: true
          elasticsearch.cluster.shards:
            enabled: true
          elasticsearch.cluster.state_update.time:
            enabled: true
          elasticsearch.index.documents:
            enabled: true
          elasticsearch.index.operations.merge.current:
            enabled: true
          elasticsearch.index.operations.time:
            enabled: true
          elasticsearch.node.cache.count:
            enabled: true
          elasticsearch.node.cache.evictions:
            enabled: true
          elasticsearch.node.cache.memory.usage:
            enabled: true
          elasticsearch.node.shards.size:
            enabled: true
          elasticsearch.node.cluster.io:
            enabled: true
          elasticsearch.node.documents:
            enabled: true
          elasticsearch.node.disk.io.read:
            enabled: true
          elasticsearch.node.disk.io.write:
            enabled: true
          elasticsearch.node.fs.disk.available:
            enabled: true
          elasticsearch.node.fs.disk.total:
            enabled: true
          elasticsearch.node.http.connections:
            enabled: true
          elasticsearch.node.ingest.documents.current:
            enabled: true
          elasticsearch.node.ingest.operations.failed:
            enabled: true
          elasticsearch.node.open_files:
            enabled: true
          elasticsearch.node.operations.completed:
            enabled: true
          elasticsearch.node.operations.current:
            enabled: true
          elasticsearch.node.operations.get.completed:
            enabled: true
          elasticsearch.node.operations.time:
            enabled: true
          elasticsearch.node.shards.reserved.size:
            enabled: true
          elasticsearch.index.shards.size:
            enabled: true
          elasticsearch.os.cpu.load_avg.1m:
            enabled: true
          elasticsearch.os.cpu.load_avg.5m:
            enabled: true
          elasticsearch.os.cpu.load_avg.15m:
            enabled: true
          elasticsearch.os.memory:
            enabled: true
          jvm.gc.collections.count:
            enabled: true
          jvm.gc.collections.elapsed:
            enabled: true
          jvm.memory.heap.max:
            enabled: true
          jvm.memory.heap.used:
            enabled: true
          jvm.memory.heap.utilization:
            enabled: true
          jvm.threads.count:
            enabled: true
          elasticsearch.index.segments.count:
            enabled: true
          elasticsearch.index.operations.completed:
            enabled: true
          elasticsearch.node.script.cache_evictions:
            enabled: false
          elasticsearch.node.cluster.connections:
            enabled: false
          elasticsearch.node.pipeline.ingest.documents.preprocessed:
            enabled: false
          elasticsearch.node.thread_pool.tasks.queued:
            enabled: false
          elasticsearch.cluster.published_states.full:
            enabled: false
          jvm.memory.pool.max:
            enabled: false
          elasticsearch.node.script.compilation_limit_triggered:
            enabled: false
          elasticsearch.node.shards.data_set.size:
            enabled: false
          elasticsearch.node.pipeline.ingest.documents.current:
            enabled: false
          elasticsearch.cluster.state_update.count:
            enabled: false
          elasticsearch.node.fs.disk.free:
            enabled: false
          jvm.memory.nonheap.used:
            enabled: false
          jvm.memory.pool.used:
            enabled: false
          elasticsearch.node.translog.size:
            enabled: false
          elasticsearch.node.thread_pool.threads:
            enabled: false
          elasticsearch.cluster.state_queue:
            enabled: false
          elasticsearch.node.translog.operations:
            enabled: false
          elasticsearch.memory.indexing_pressure:
            enabled: false
          elasticsearch.node.ingest.documents:
            enabled: false
          jvm.classes.loaded:
            enabled: false
          jvm.memory.heap.committed:
            enabled: false
          elasticsearch.breaker.memory.limit:
            enabled: false
          elasticsearch.indexing_pressure.memory.total.replica_rejections:
            enabled: false
          elasticsearch.breaker.memory.estimated:
            enabled: false
          elasticsearch.cluster.published_states.differences:
            enabled: false
          jvm.memory.nonheap.committed:
            enabled: false
          elasticsearch.node.translog.uncommitted.size:
            enabled: false
          elasticsearch.node.script.compilations:
            enabled: false
          elasticsearch.node.pipeline.ingest.operations.failed:
            enabled: false
          elasticsearch.indexing_pressure.memory.limit:
            enabled: false
          elasticsearch.breaker.tripped:
            enabled: false
          elasticsearch.indexing_pressure.memory.total.primary_rejections:
            enabled: false
          elasticsearch.node.thread_pool.tasks.finished:
            enabled: false

    processors:
      memory_limiter:
        check_interval: 60s
        limit_mib: ${env:NEW_RELIC_MEMORY_LIMIT_MIB:-100}
      cumulativetodelta: {}
      resource/cluster_name_override:
        attributes:
          - key: elasticsearch.cluster.name
            value: "<YOUR_ELASTICSEARCH_CLUSTER_NAME>"
            action: upsert
      resourcedetection:
        detectors: [system]
        system:
          resource_attributes:
            host.name: { enabled: true }
            host.id: { enabled: true }
            os.type: { enabled: true }
      batch:
        timeout: 10s
        send_batch_size: 1024
      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}

    service:
      pipelines:
        metrics/elasticsearch:
          receivers: [elasticsearch]
          processors: [memory_limiter, 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                                                                                                                                                            |
| ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `endpoint`                                                         | Your Elasticsearch cluster's URL.                                                                                                                                      |
| `collection_interval`                                              | The interval between metric scrapes. The default is 15s.                                                                                                               |
| `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). |

3.  Save the configuration file.

You can optionally add secured-cluster authentication, host metrics, log collection, or custom metadata tags. See [Advanced configuration](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/advanced-configuration).

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

Set the credentials and connection details the collector needs to send data to New Relic.

```bash
sudo mkdir -p /etc/systemd/system/otelcol-contrib.service.d
cat <<EOF | sudo tee /etc/systemd/system/otelcol-contrib.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 OTel Collector Contrib [#restart]

Restart the collector to apply your changes:

```bash
sudo systemctl daemon-reload
sudo systemctl restart otelcol-contrib.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: `otelcol-contrib.service` should report `active (running)` (`sudo systemctl status otelcol-contrib.service`), with no connection errors in the logs (`sudo journalctl -u otelcol-contrib.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 with OTel Collector Contrib, 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]

-   [Advanced configuration](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/advanced-configuration)
-   [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)
