Integrate Elasticsearch 8 with Prometheus monitoring and Grafana dashboards

Intermediate 45 min Apr 10, 2026 42 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up comprehensive monitoring for Elasticsearch 8 using Prometheus metrics collection and Grafana visualization. This tutorial covers exporter installation, metric configuration, dashboard setup, and alerting rules for production environments.

Prerequisites

  • Elasticsearch 8 installed and running
  • Prometheus server configured
  • Grafana installed with admin access
  • Root or sudo access

What this solves

Elasticsearch monitoring is critical for production deployments to track cluster health, performance metrics, and resource utilization. This tutorial integrates Elasticsearch 8 with Prometheus for metrics collection and Grafana for visualization, providing real-time monitoring and alerting capabilities for your search infrastructure.

Step-by-step installation

Update system packages

Start by updating your package manager to ensure you have the latest package information.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install Elasticsearch exporter

Download and install the Prometheus Elasticsearch exporter to collect metrics from your cluster.

cd /tmp
wget https://github.com/prometheus-community/elasticsearch_exporter/releases/download/v1.7.0/elasticsearch_exporter-1.7.0.linux-amd64.tar.gz
tar -xzf elasticsearch_exporter-1.7.0.linux-amd64.tar.gz
sudo mv elasticsearch_exporter-1.7.0.linux-amd64/elasticsearch_exporter /usr/local/bin/
sudo chmod +x /usr/local/bin/elasticsearch_exporter

Create exporter user and directories

Create a dedicated system user for the exporter service with minimal privileges.

sudo useradd --no-create-home --shell /bin/false elasticsearch_exporter
sudo mkdir -p /var/lib/elasticsearch_exporter
sudo chown elasticsearch_exporter:elasticsearch_exporter /var/lib/elasticsearch_exporter

Configure Elasticsearch exporter

Create the configuration file to specify Elasticsearch connection details and export settings.

elasticsearch:
  uri: "http://localhost:9200"
  username: ""
  password: ""
  timeout: 30s
  ssl_skip_verify: false

log:
  level: info
  format: json

metrics:
  cluster_info: true
  cluster_stats: true
  indices_stats: true
  shards_stats: true
  snapshots_stats: false

Create systemd service file

Configure the Elasticsearch exporter as a systemd service for automatic startup and management.

[Unit]
Description=Elasticsearch Exporter
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=elasticsearch_exporter
Group=elasticsearch_exporter
ExecStart=/usr/local/bin/elasticsearch_exporter --config.file=/etc/elasticsearch_exporter/config.yml --web.listen-address=:9114
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Set proper permissions and start exporter

Apply correct ownership and permissions to configuration files, then enable the service.

sudo mkdir -p /etc/elasticsearch_exporter
sudo chown -R elasticsearch_exporter:elasticsearch_exporter /etc/elasticsearch_exporter
sudo chmod 755 /etc/elasticsearch_exporter
sudo chmod 644 /etc/elasticsearch_exporter/config.yml
sudo systemctl daemon-reload
sudo systemctl enable --now elasticsearch_exporter

Configure Prometheus scraping

Add the Elasticsearch exporter as a scraping target in your Prometheus configuration.

global:
  scrape_interval: 15s
  evaluation_interval: 15s

rule_files:
  - "elasticsearch_rules.yml"

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'elasticsearch'
    static_configs:
      - targets: ['localhost:9114']
    scrape_interval: 30s
    metrics_path: /metrics
    params:
      timeout: ['30s']

Create Elasticsearch alerting rules

Define Prometheus alerting rules to monitor critical Elasticsearch metrics and trigger notifications.

groups:
  - name: elasticsearch
    rules:
      - alert: ElasticsearchClusterRed
        expr: elasticsearch_cluster_health_status{color="red"} == 1
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "Elasticsearch cluster status is RED"
          description: "Cluster {{ $labels.cluster }} health is RED"

      - alert: ElasticsearchClusterYellow
        expr: elasticsearch_cluster_health_status{color="yellow"} == 1
        for: 10m
        labels:
          severity: warning
        annotations:
          summary: "Elasticsearch cluster status is YELLOW"
          description: "Cluster {{ $labels.cluster }} health is YELLOW for more than 10 minutes"

      - alert: ElasticsearchHighJVMMemory
        expr: elasticsearch_jvm_memory_used_bytes / elasticsearch_jvm_memory_max_bytes > 0.85
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Elasticsearch JVM memory usage is high"
          description: "JVM memory usage is above 85% on node {{ $labels.name }}"

      - alert: ElasticsearchDiskSpaceLow
        expr: elasticsearch_filesystem_data_available_bytes / elasticsearch_filesystem_data_size_bytes < 0.1
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "Elasticsearch disk space is low"
          description: "Less than 10% disk space available on node {{ $labels.name }}"

      - alert: ElasticsearchNodeDown
        expr: up{job="elasticsearch"} == 0
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: "Elasticsearch exporter is down"
          description: "Elasticsearch exporter has been down for more than 2 minutes"

Restart Prometheus

Reload Prometheus configuration to apply the new scraping targets and alerting rules.

sudo systemctl restart prometheus
sudo systemctl status prometheus

Import Grafana dashboard

Add a comprehensive Elasticsearch dashboard to Grafana for visualizing cluster metrics and performance data.

curl -X POST \
  http://admin:admin@localhost:3000/api/dashboards/db \
  -H 'Content-Type: application/json' \
  -d '{
    "dashboard": {
      "id": null,
      "title": "Elasticsearch Cluster Monitoring",
      "tags": ["elasticsearch", "monitoring"],
      "timezone": "browser",
      "panels": [
        {
          "id": 1,
          "title": "Cluster Health Status",
          "type": "stat",
          "targets": [
            {
              "expr": "elasticsearch_cluster_health_status",
              "refId": "A"
            }
          ],
          "fieldConfig": {
            "defaults": {
              "mappings": [
                {
                  "options": {
                    "0": {
                      "text": "GREEN",
                      "color": "green"
                    },
                    "1": {
                      "text": "YELLOW",
                      "color": "yellow"
                    },
                    "2": {
                      "text": "RED",
                      "color": "red"
                    }
                  },
                  "type": "value"
                }
              ]
            }
          }
        }
      ],
      "time": {
        "from": "now-1h",
        "to": "now"
      },
      "refresh": "30s"
    }
  }'

Configure Grafana data source

Add Prometheus as a data source in Grafana to enable dashboard functionality.

curl -X POST \
  http://admin:admin@localhost:3000/api/datasources \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Prometheus",
    "type": "prometheus",
    "url": "http://localhost:9090",
    "access": "proxy",
    "isDefault": true
  }'

Configure authentication for secure environments

Set up Elasticsearch authentication

If your Elasticsearch cluster uses authentication, update the exporter configuration with credentials.

elasticsearch:
  uri: "https://localhost:9200"
  username: "monitoring_user"
  password: "secure_password"
  timeout: 30s
  ssl_skip_verify: false
  ca_cert: "/etc/elasticsearch/certs/ca.crt"
  client_cert: "/etc/elasticsearch/certs/client.crt"
  client_key: "/etc/elasticsearch/certs/client.key"

Create monitoring user in Elasticsearch

Create a dedicated user with minimal privileges for metrics collection.

curl -X POST "localhost:9200/_security/user/monitoring_user" \
  -H 'Content-Type: application/json' \
  -d '{
    "password" : "secure_password",
    "roles" : [ "monitoring_user" ],
    "full_name" : "Monitoring User",
    "email" : "monitoring@example.com"
  }'

Advanced dashboard configuration

Create comprehensive monitoring panels

Set up detailed Grafana panels for monitoring various Elasticsearch metrics including performance and resource utilization.

# Cluster Nodes Count
sum(elasticsearch_cluster_health_number_of_nodes)

Index Operations Rate

rate(elasticsearch_indices_indexing_index_total[5m])

Search Operations Rate

rate(elasticsearch_indices_search_query_total[5m])

JVM Memory Usage

elasticsearch_jvm_memory_used_bytes{area="heap"} / elasticsearch_jvm_memory_max_bytes{area="heap"} * 100

Disk Usage per Node

(elasticsearch_filesystem_data_size_bytes - elasticsearch_filesystem_data_available_bytes) / elasticsearch_filesystem_data_size_bytes * 100

Thread Pool Queue Size

elasticsearch_thread_pool_queue_count

GC Collection Time

rate(elasticsearch_jvm_gc_collection_seconds_sum[5m])

Verify your setup

Check that all components are running correctly and collecting metrics.

# Check Elasticsearch exporter status
sudo systemctl status elasticsearch_exporter

Verify metrics are being collected

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

Check Prometheus targets

curl http://localhost:9090/api/v1/targets | jq '.data.activeTargets[] | select(.job == "elasticsearch")'

Test Elasticsearch connectivity

curl -X GET "localhost:9200/_cluster/health?pretty"

Verify alerting rules are loaded

curl http://localhost:9090/api/v1/rules | jq '.data.groups[] | select(.name == "elasticsearch")'

Check Grafana data source

curl -u admin:admin http://localhost:3000/api/datasources

Performance optimization

Note: Adjust scrape intervals based on your monitoring requirements. Shorter intervals provide more granular data but increase resource usage.
Metric TypeRecommended IntervalResource Impact
Cluster health15-30 secondsLow
Node statistics30-60 secondsMedium
Index statistics60-300 secondsHigh
Shard statistics300-600 secondsVery High

Common issues

SymptomCauseFix
Exporter fails to startInvalid configuration fileCheck YAML syntax with yamllint /etc/elasticsearch_exporter/config.yml
Connection refused errorsElasticsearch not accessibleVerify Elasticsearch is running on specified URI
Authentication failuresInvalid credentials or permissionsCheck username/password and user roles in Elasticsearch
No metrics in PrometheusScraping configuration incorrectVerify target configuration in prometheus.yml
SSL certificate errorsInvalid or expired certificatesUpdate certificate paths or disable SSL verification for testing
High memory usageToo many metrics being collectedDisable unnecessary metrics in exporter configuration

Next steps

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed devops services for businesses that depend on uptime. From initial setup to ongoing operations.