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

This page configures the OpenTelemetry Collector's Prometheus receiver, deployed to Kubernetes, to monitor Elasticsearch through an existing [Prometheus Elasticsearch exporter](https://github.com/prometheus-community/elasticsearch_exporter) running in your cluster. Use this path only if you already run that exporter, or are migrating from a Prometheus-based monitoring stack. If not, use NRDOT ([manifest install](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/kubernetes/nrdot-manifest-install) or [Helm install](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/kubernetes/nrdot-helm-install)) or [OTel Collector Contrib](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/kubernetes/otel-collector-contrib) instead, which connect directly to the Elasticsearch API with pod auto-discovery and don't need an extra component.

## Compatibility and requirements [#requirements]

### Supported

-   Elasticsearch 7.16 or later, running as pods in a Kubernetes cluster, monitored via `elasticsearch_exporter` 1.x
-   Helm 3.x install method for both the exporter and the collector

### Not supported

-   Automatic pod discovery: this path scrapes a single exporter endpoint rather than discovering Elasticsearch pods directly

### You need

Before you begin, make sure you have:

-   A New Relic [license key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#ingest-license-key)
-   `kubectl` access to your Kubernetes cluster
-   Helm 3.x installed
-   Outbound HTTPS (port 443) connectivity to New Relic's [OTLP endpoint](https://docs.newrelic.com/docs/opentelemetry/best-practices/opentelemetry-otlp)

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

Deploy the [Prometheus Elasticsearch exporter](https://github.com/prometheus-community/elasticsearch_exporter) to your cluster. It exposes Elasticsearch metrics in Prometheus format on port `9114`.

1.  Deploy the Elasticsearch exporter, if it isn't already running:

    ```bash
    helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
    helm repo update
    helm install elasticsearch-exporter prometheus-community/prometheus-elasticsearch-exporter \
      --namespace monitoring \
      --create-namespace \
      --set es.uri=http://elasticsearch.default.svc.cluster.local:9200
    ```

    Replace `elasticsearch.default.svc.cluster.local:9200` with your Elasticsearch service address.

2.  Verify the exporter is running:

    ```bash
    kubectl get pods -n monitoring -l app=prometheus-elasticsearch-exporter
    ```

## Create the credentials secret [#create-secret]

Create the credentials secret the collector needs to send data to New Relic. The secret goes in the `monitoring` namespace. If that namespace doesn't exist yet, because you didn't deploy the exporter in the previous step, create it first with `kubectl create namespace monitoring`.

```bash
kubectl create secret generic newrelic-credentials \
  --namespace monitoring \
  --from-literal=NEWRELIC_LICENSE_KEY=YOUR_LICENSE_KEY_HERE \
  --from-literal=NEWRELIC_OTLP_ENDPOINT=<YOUR_OTLP_ENDPOINT>
```

> #### 💡 TIP
>
> For US accounts, use `NEWRELIC_OTLP_ENDPOINT=https://otlp.nr-data.net:4318`. For EU accounts, use `NEWRELIC_OTLP_ENDPOINT=https://otlp.eu01.nr-data.net:4318`.

## Create the collector ConfigMap [#create-configmap]

Create a ConfigMap with the collector configuration. This maps the exporter's Prometheus metric names to the OTel-style names that power the New Relic Elasticsearch dashboard. Save the following as `otel-collector-prometheus-es.yaml`, updating `<elasticsearch-cluster-name>` and the exporter's service address:

```yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: otel-collector-prometheus-es
  namespace: monitoring
data:
  config.yaml: |
    receivers:
      prometheus/elasticsearch:
        config:
          scrape_configs:
            - job_name: 'elasticsearch'
              scrape_interval: 15s
              static_configs:
                - targets: ['elasticsearch-exporter-prometheus-elasticsearch-exporter.monitoring.svc.cluster.local:9114']

    processors:
      memory_limiter:
        check_interval: 60s
        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_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_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_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_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_os_cpu_percent$
            match_type: regexp
            action: update
            new_name: elasticsearch.os.cpu.usage
          - include: ^elasticsearch_jvm_gc_collection_seconds_count$
            match_type: regexp
            action: update
            new_name: jvm.gc.collections.count
          - 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.cluster.io
              - elasticsearch.node.documents
              - elasticsearch.node.fs.disk.available
              - elasticsearch.node.fs.disk.total
              - elasticsearch.node.operations.completed
              - elasticsearch.node.operations.time
              - elasticsearch.os.cpu.usage
              - jvm.gc.collections.count
              - 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: "<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: [env]
        env:
          resource_attributes:
            host.name:
              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]
```

Apply it:

```bash
kubectl apply -f otel-collector-prometheus-es.yaml
```

### Configuration parameters [#configuration-parameters]

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

| Parameter                                                          | Description                                                                                                                                                                                                 |
| ------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `targets`                                                          | The address of your `elasticsearch_exporter` service. Update it to match your exporter's Kubernetes service address.                                                                                        |
| `elasticsearch-cluster-name` (in `resource/cluster_name_override`) | A unique name identifying this cluster in New Relic. Replace `<elasticsearch-cluster-name>` with a name that's unique across your account.                                                                  |
| `NEWRELIC_LICENSE_KEY`                                             | Your New Relic [license key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#ingest-license-key), set in the credentials secret above.                                                   |
| `NEWRELIC_OTLP_ENDPOINT`                                           | The New Relic OTLP endpoint for your account's region, set in the credentials secret above. See [New Relic OTLP endpoints](https://docs.newrelic.com/docs/opentelemetry/best-practices/opentelemetry-otlp). |

## Deploy the collector [#deploy]

Deploy the collector. Update the `image` field below to `newrelic/nrdot-collector:latest` if you prefer NRDOT over OTel Collector Contrib. Save as `otel-collector-deployment.yaml` and apply with `kubectl apply -f otel-collector-deployment.yaml`:

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: otel-collector-elasticsearch
  namespace: monitoring
  labels:
    app: otel-collector-elasticsearch
spec:
  replicas: 1
  selector:
    matchLabels:
      app: otel-collector-elasticsearch
  template:
    metadata:
      labels:
        app: otel-collector-elasticsearch
    spec:
      containers:
        - name: otel-collector
          image: otel/opentelemetry-collector-contrib:latest
          args:
            - "--config=/etc/otel/config.yaml"
          env:
            - name: NEWRELIC_LICENSE_KEY
              valueFrom:
                secretKeyRef:
                  name: newrelic-credentials
                  key: NEWRELIC_LICENSE_KEY
            - name: NEWRELIC_OTLP_ENDPOINT
              valueFrom:
                secretKeyRef:
                  name: newrelic-credentials
                  key: NEWRELIC_OTLP_ENDPOINT
          volumeMounts:
            - name: config
              mountPath: /etc/otel
          resources:
            requests:
              memory: "128Mi"
              cpu: "100m"
            limits:
              memory: "256Mi"
              cpu: "500m"
      volumes:
        - name: config
          configMap:
            name: otel-collector-prometheus-es
```

## Verify your install [#verify]

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

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

> #### 💡 TIP
>
> You can also check the collector itself: the pod should be running (`kubectl get pods -n monitoring -l app=otel-collector-elasticsearch`), with no connection errors in the pod logs (`kubectl logs -n monitoring -l app=otel-collector-elasticsearch -f`).

If you don't see data within ~5 minutes, see [Kubernetes troubleshooting](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/troubleshooting#kubernetes-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)
