---
title: Advanced configuration for Elasticsearch monitoring
source: https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/advanced-configuration
---

This page covers optional configuration for Elasticsearch monitoring beyond the minimum setup: secured clusters, host metrics, log collection, and custom metadata tags.

## Secured Elasticsearch with authentication and SSL [#secured]

Add authentication and TLS to your Elasticsearch connection when your cluster requires them.

### Requirements [#secured-requirements]

-   An Elasticsearch user with the `monitor` or `manage` cluster privilege, and valid credentials for that user.

For secured Elasticsearch with authentication and SSL, modify the receiver configuration:

**NRDOT**

```yaml
receivers:
  elasticsearch:
    endpoint: "https://<YOUR_ELASTICSEARCH_HOST>:9200"
    username: "<YOUR_ELASTICSEARCH_USERNAME>"
    password: "<YOUR_ELASTICSEARCH_PASSWORD>"
    tls:
      insecure_skip_verify: false
    collection_interval: 15s
```

**OTel Collector Contrib**

```yaml
receivers:
  elasticsearch:
    endpoint: "https://<YOUR_ELASTICSEARCH_HOST>:9200"
    username: "<YOUR_ELASTICSEARCH_USERNAME>"
    password: "<YOUR_ELASTICSEARCH_PASSWORD>"
    tls:
      insecure_skip_verify: false
    collection_interval: 15s
```

**Kubernetes: NRDOT (manifest or Helm)**

```yaml
receivers:
  receiver_creator/elasticsearch:
    watch_observers: [k8s_observer]
    receivers:
      elasticsearch:
        rule: type == "pod" && labels["app"] == "elasticsearch"
        config:
          endpoint: 'https://`endpoint`:9200'
          username: "<YOUR_ELASTICSEARCH_USERNAME>"
          password: "<YOUR_ELASTICSEARCH_PASSWORD>"
          tls:
            insecure_skip_verify: false
```

**Kubernetes: OTel Collector Contrib**

```yaml
receivers:
  receiver_creator/elasticsearch:
    watch_observers: [k8s_observer]
    receivers:
      elasticsearch:
        rule: type == "pod" && labels["app"] == "elasticsearch"
        config:
          endpoint: 'https://`endpoint`:9200'
          username: "<YOUR_ELASTICSEARCH_USERNAME>"
          password: "<YOUR_ELASTICSEARCH_PASSWORD>"
          tls:
            insecure_skip_verify: false
```

### Configuration parameters [#secured-configuration-parameters]

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

| Parameter                  | Description                                                                               |
| -------------------------- | ----------------------------------------------------------------------------------------- |
| `endpoint`                 | Your Elasticsearch cluster's URL. Use `https://` for a secured cluster.                   |
| `username`                 | An Elasticsearch user with the `monitor` or `manage` cluster privilege.                   |
| `password`                 | The password for that user.                                                               |
| `tls.insecure_skip_verify` | Whether to verify Elasticsearch's TLS certificate. Set to `false` to enable verification. |
| `collection_interval`      | The interval between metric scrapes. Default: `15s`.                                      |
| `rule` (Kubernetes only)   | The pod-matching rule used for auto-discovery.                                            |

## Collect host metrics [#host-metrics]

To collect host metrics, add the `hostmetrics` receiver:

**NRDOT**

```yaml
receivers:
  hostmetrics:
    collection_interval: 60s
    scrapers:
      cpu:
        metrics:
          system.cpu.utilization: { enabled: true }
          system.cpu.time: { enabled: true }
      load:
        metrics:
          system.cpu.load_average.1m: { enabled: true }
          system.cpu.load_average.5m: { enabled: true }
          system.cpu.load_average.15m: { enabled: true }
      memory:
        metrics:
          system.memory.usage: { enabled: true }
          system.memory.utilization: { enabled: true }
      disk:
        metrics:
          system.disk.io: { enabled: true }
          system.disk.operations: { enabled: true }
      filesystem:
        metrics:
          system.filesystem.usage: { enabled: true }
          system.filesystem.utilization: { enabled: true }
      network:
        metrics:
          system.network.io: { enabled: true }
          system.network.packets: { enabled: true }
      process:
        metrics:
          process.cpu.utilization:
            enabled: true
```

And add to the service pipelines:

```yaml
service:
  pipelines:
    metrics/host:
      receivers: [hostmetrics]
      processors: [memory_limiter, resourcedetection, batch]
      exporters: [otlphttp]
```

**OTel Collector Contrib**

```yaml
receivers:
  hostmetrics:
    collection_interval: 60s
    scrapers:
      cpu:
        metrics:
          system.cpu.utilization: { enabled: true }
          system.cpu.time: { enabled: true }
      load:
        metrics:
          system.cpu.load_average.1m: { enabled: true }
          system.cpu.load_average.5m: { enabled: true }
          system.cpu.load_average.15m: { enabled: true }
      memory:
        metrics:
          system.memory.usage: { enabled: true }
          system.memory.utilization: { enabled: true }
      disk:
        metrics:
          system.disk.io: { enabled: true }
          system.disk.operations: { enabled: true }
      filesystem:
        metrics:
          system.filesystem.usage: { enabled: true }
          system.filesystem.utilization: { enabled: true }
      network:
        metrics:
          system.network.io: { enabled: true }
          system.network.packets: { enabled: true }
      process:
        metrics:
          process.cpu.utilization:
            enabled: true
```

And add to the service pipelines:

```yaml
service:
  pipelines:
    metrics/host:
      receivers: [hostmetrics]
      processors: [memory_limiter, resourcedetection, batch]
      exporters: [otlphttp]
```

### Configuration parameters [#host-metrics-configuration-parameters]

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

| Parameter             | Description                                                                                                                                                                       |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `collection_interval` | The interval between host metric scrapes. Default: `60s`.                                                                                                                         |
| `scrapers`            | The host-level metric categories to collect (`cpu`, `load`, `memory`, `disk`, `filesystem`, `network`, `process`). Disable any metric you don't need by setting `enabled: false`. |

## Collect Elasticsearch logs [#logs]

### Requirements [#logs-requirements]

-   Read access to your Elasticsearch log files, for whichever account runs the collector service:
    -   Linux host: read permission on `/var/log/elasticsearch/`
    -   Docker: read permission on `/var/lib/docker/containers/` (root, or Docker group membership)

To collect Elasticsearch logs, add the `filelog` receiver.

**NRDOT**

Ensure the account running the collector service (`nrdot-collector`) has read access to your Elasticsearch log files.

**If Elasticsearch runs on a Linux host, use this configuration:**

```yaml
receivers:
  filelog:
    include:
      - /var/log/elasticsearch/elasticsearch.log
      - /var/log/elasticsearch/*.log
```

**If Elasticsearch runs in Docker, use this configuration:**

```yaml
receivers:
  filelog:
    include:
      - /var/lib/docker/containers/*/*.log
    operators:
      - type: move
        from: attributes.log
        to: body
```

And add to the service pipelines:

```yaml
service:
  pipelines:
    logs:
      receivers: [filelog]
      processors: [resource/cluster_name_override]
      exporters: [otlphttp]
```

**OTel Collector Contrib**

Ensure the account running the collector service (`otelcol-contrib`) has read access to your Elasticsearch log files.

**If Elasticsearch runs on a Linux host, use this configuration:**

```yaml
receivers:
  filelog:
    include:
      - /var/log/elasticsearch/elasticsearch.log
      - /var/log/elasticsearch/*.log
```

**If Elasticsearch runs in Docker, use this configuration:**

```yaml
receivers:
  filelog:
    include:
      - /var/lib/docker/containers/*/*.log
    operators:
      - type: move
        from: attributes.log
        to: body
```

And add to the service pipelines:

```yaml
service:
  pipelines:
    logs:
      receivers: [filelog]
      processors: [resource/cluster_name_override]
      exporters: [otlphttp]
```

### Configuration parameters [#logs-configuration-parameters]

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

| Parameter                 | Description                                                                                    |
| ------------------------- | ---------------------------------------------------------------------------------------------- |
| `include`                 | Log file paths to tail (Linux host) or container log paths (Docker).                           |
| `operators` (Docker only) | The operator that moves the log line from `attributes.log` to `body` so it displays correctly. |

## Add custom metadata tags [#custom-tags]

To add custom metadata tags to your metrics, use the `resource/static_override` processor:

**NRDOT**

```yaml
processors:
  resource/static_override:
    attributes:
      - key: env
        value: "production"
        action: upsert
service:
  pipelines:
    metrics/elasticsearch:
      receivers: [elasticsearch]
      processors: [memory_limiter, resourcedetection, resource/cluster_name_override, resource/static_override, attributes/cardinality_reduction, cumulativetodelta, transform/metadata_nullify, batch]
      exporters: [otlphttp]
```

**OTel Collector Contrib**

```yaml
processors:
  resource/static_override:
    attributes:
      - key: env
        value: "production"
        action: upsert
service:
  pipelines:
    metrics/elasticsearch:
      receivers: [elasticsearch]
      processors: [memory_limiter, resourcedetection, resource/cluster_name_override, resource/static_override, attributes/cardinality_reduction, cumulativetodelta, transform/metadata_nullify, batch]
      exporters: [otlphttp]
```

### Configuration parameters [#custom-tags-configuration-parameters]

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

| Parameter | Description                                                                                     |
| --------- | ----------------------------------------------------------------------------------------------- |
| `key`     | The attribute name to add, e.g. `env`.                                                          |
| `value`   | The attribute value, e.g. `production`.                                                         |
| `action`  | The action to apply. Set to `upsert` to add the attribute or overwrite it if it already exists. |

## Restart the collector [#restart]

After updating your configuration, restart the collector to apply the changes.

**NRDOT (self-hosted)**

```bash
sudo systemctl daemon-reload
sudo systemctl restart nrdot-collector.service
```

**OTel Collector Contrib (self-hosted)**

```bash
sudo systemctl daemon-reload
sudo systemctl restart otelcol-contrib.service
```

**Kubernetes (NRDOT or OTel Collector Contrib)**

For a manifest install, restart the deployment:

```bash
kubectl rollout restart deployment nr-k8s-otel-collector-deployment -n newrelic
```

For a Helm install, re-run the same `helm upgrade --install ... -f values.yaml` command from your install step to roll out the updated config.

## Verify your changes [#verify]

After restarting the collector, confirm your change took effect:

-   **Secured cluster**: Rerun your install page's data collection query. If metrics are flowing with no TLS or authentication errors in the collector logs, the secured connection is working.

-   **Host metrics**: Run this query:

    ```sql
    FROM Metric SELECT count(*) WHERE metricName LIKE 'system.%' SINCE 10 minutes ago
    ```

-   **Elasticsearch logs**: Run this query:

    ```sql
    FROM Log SELECT count(*) SINCE 10 minutes ago
    ```

    Adjust the `WHERE` clause to match your own log attributes.

-   **Custom tags**: Run this query, using the example tag from [Add custom metadata tags](#custom-tags):

    ```sql
    FROM Metric SELECT count(*) WHERE metricName LIKE 'elasticsearch.%' AND env = 'production' SINCE 10 minutes ago
    ```

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

## Related articles [#related-articles]

-   Self-hosted
    -   [Install and configure NRDOT on self-hosted Elasticsearch](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/self-hosted/nrdot)
    -   [Install and configure OTel Collector Contrib on self-hosted Elasticsearch](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/self-hosted/otel-collector-contrib)
    -   [Monitor self-hosted Elasticsearch with the Prometheus receiver](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/self-hosted/prometheus-receiver)
-   Kubernetes
    -   [Install and configure NRDOT on Kubernetes to monitor Elasticsearch (Manifest)](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/kubernetes/nrdot-manifest-install)
    -   [Install and configure NRDOT on Kubernetes to monitor Elasticsearch (Helm)](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/kubernetes/nrdot-helm-install)
    -   [Install and configure OTel Collector Contrib on Kubernetes to monitor Elasticsearch](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/kubernetes/otel-collector-contrib)
    -   [Monitor Elasticsearch on Kubernetes with the Prometheus receiver](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/kubernetes/prometheus-receiver)
-   [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)
