Elasticsearch Monitoring Elasticsearch with Prometheus

By Opster Team

Updated: Nov 14, 2023

| 2 min read

Introduction

Prometheus is a popular open-source monitoring and alerting toolkit that can be used to monitor various systems, including Elasticsearch. In this article, we will discuss how to set up Prometheus to monitor Elasticsearch and visualize the collected metrics using Grafana. We will cover the following topics:

  1. Installing and configuring Prometheus
  2. Configuring Elasticsearch for Prometheus
  3. Setting up Grafana for Elasticsearch metrics visualization
  4. Installing and Configuring Prometheus

To monitor Elasticsearch with Prometheus, you will need to install and configure Prometheus on your system.

Steps to set up Prometheus

Step 1: Download and install Prometheus

Download the latest release of Prometheus from the official website (https://prometheus.io/download/) and extract the archive to a directory of your choice.

Step 2: Configure Prometheus

Create a configuration file named `prometheus.yml` in the Prometheus installation directory. Add the following content to the file:

global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
job_name: 'elasticsearch'
    static_configs:
targets: ['<elasticsearch_host>:<elasticsearch_exporter_port>']

Replace `<elasticsearch_host>` with the hostname or IP address of your Elasticsearch instance, and `<elasticsearch_exporter_port>` with the port number where the Elasticsearch exporter will be running.

Step 3: Start Prometheus

Run the following command in the Prometheus installation directory to start Prometheus:

./prometheus --config.file=prometheus.yml

Prometheus should now be running and accessible at `http://localhost:9090`.

Configuring Elasticsearch for Prometheus

To expose Elasticsearch metrics to Prometheus, you will need to use an exporter. In this guide, we will use the Elasticsearch Exporter (https://github.com/justwatchcom/elasticsearch_exporter).

Step 1: Download and install Elasticsearch Exporter

Download the latest release of Elasticsearch Exporter from the GitHub repository and extract the archive to a directory of your choice.

Step 2: Configure Elasticsearch Exporter

Create a configuration file named `elasticsearch_exporter.yml` in the Elasticsearch Exporter installation directory. Add the following content to the file:

es.uri: "http://<elasticsearch_host>:<elasticsearch_port>"

Replace `<elasticsearch_host>` with the hostname or IP address of your Elasticsearch instance, and `<elasticsearch_port>` with the port number where Elasticsearch is running (default is 9200).

Step 3: Start Elasticsearch Exporter

Run the following command in the Elasticsearch Exporter installation directory to start the exporter:

./elasticsearch_exporter --config.file=elasticsearch_exporter.yml

Elasticsearch Exporter should now be running and exposing metrics at `http://<elasticsearch_host>:<elasticsearch_exporter_port>/metrics`.

Setting up Grafana for Elasticsearch Metrics Visualization

Grafana is a popular open-source analytics and monitoring platform that can be used to visualize the metrics collected by Prometheus. Follow these steps to set up Grafana for Elasticsearch metrics visualization:

Step 1: Download and install Grafana

Download the latest release of Grafana from the official website (https://grafana.com/grafana/download) and follow the installation instructions for your operating system.

Step 2: Configure Grafana data source

Start Grafana and access the web interface at `http://localhost:3000`. Log in with the default credentials (admin/admin) and navigate to “Configuration” > “Data Sources” > “Add data source”. Select “Prometheus” as the data source type and enter the Prometheus URL (`http://localhost:9090`).

Step 3: Import Elasticsearch dashboard

Navigate to “Dashboards” > “Manage” > “Import” and enter the ID `2322` to import the Elasticsearch dashboard provided by Grafana. Select the Prometheus data source you configured earlier and click “Import”.

You should now see a pre-built dashboard displaying various Elasticsearch metrics collected by Prometheus.

Conclusion

In this article, we have discussed how to set up Prometheus to monitor Elasticsearch and visualize the collected metrics using Grafana. By following these steps, you can gain valuable insights into the performance and health of your Elasticsearch cluster, allowing you to optimize and troubleshoot issues more effectively.