Collect Elasticsearch metrics by using managed service for Prometheus

Elasticsearch is the distributed search and analytics engine at the heart of the Elastic Stack. It's where the indexing, search, and analysis happen.

This article describes how to configure the Azure Monitor managed service for Prometheus feature with Azure Kubernetes Service (AKS) and Azure Arc-enabled Kubernetes to monitor Elasticsearch clusters by scraping Prometheus metrics.

Prerequisites

  • Elasticsearch cluster running on AKS or Azure Arc-enabled Kubernetes
  • Managed service for Prometheus enabled on the cluster. For more information, see Enable Prometheus and Grafana.

Install the Elasticsearch Exporter

Install the Prometheus Elasticsearch Exporter by using the Helm chart:

helm install azmon-elasticsearch-exporter --version 5.7.0 prometheus-community/prometheus-elasticsearch-exporter --set es.uri="https://username:password@elasticsearch-service.namespace:9200" --set podMonitor.enabled=true --set podMonitor.apiVersion=azmonitoring.coreos.com/v1

You can configure the Elasticsearch Exporter Helm chart with values. Specify the right server addresses where the Elasticsearch servers can be reached.

Based on your configuration, set the username, password, or certificates that are used to authenticate with the Elasticsearch server. Set the address where Elasticsearch is reachable by using the argument es.uri.

Note

A managed Prometheus service/pod monitor configuration with Helm chart installation is supported only with the Helm chart version 5.7.0 or later.

You could also use a service monitor instead of pod monitor by using the --set serviceMonitor.enabled=true Helm chart parameter. Make sure to use the API version that managed service for Prometheus supports, by using the parameter serviceMonitor.apiVersion=azmonitoring.coreos.com/v1.

If you want to configure any other service or pod monitors, follow these instructions.

Deploy rules

  1. Download these files for recording rules:

    Download these files for alerting rules:

  2. Edit the following values in the parameter files.

    Parameter Value
    azureMonitorWorkspace Resource ID for the Azure Monitor workspace. Retrieve it from JSON view on the Overview page for the Azure Monitor workspace.
    location Location of the Azure Monitor workspace. Retrieve it from JSON view on the Overview page for the Azure Monitor workspace.
    clusterName Name of the cluster. Retrieve it from JSON view on the Overview page for the cluster.
    actionGroupId Resource ID for the alert action group. Retrieve it from JSON view on the Overview page for the action group. Learn more about action groups.
  3. Deploy the template by using any standard method for installing Azure Resource Manager templates. For guidance, see Resource Manager template samples for Azure Monitor.

If you want to use any other open-source Prometheus alerting/recording rules, use az-prom-rules-converter to create the Azure-equivalent Prometheus rules.

Import the Grafana dashboards

To import the following Grafana dashboards by using the ID or JSON, use the instructions in Import a dashboard from Grafana Labs:

Troubleshoot

When the service monitor is successfully applied, if you want to make sure that the add-on picks up the service monitor targets, follow these instructions.