Menu
Grafana Cloud

Consul integration for Grafana Cloud

Consul is a service mesh solution providing a full featured control plane with service discovery, configuration, and segmentation functionality.

Consul is split into a client-server architecture by which servers provide a control plane into the cluster of clients, and clients form a mostly stateless data plane alongside the sidecar proxy on each node running your applications and services.

Since Consul provides first-class support for Envoy as a sidecar proxy, it is strongly recommended that you also install the Grafana integration for Envoy, assuming that you are using it.

This integration includes 3 useful alerts and 1 pre-built dashboard to help monitor and visualize Consul metrics.

Before you begin

This integration relies on a running Consul deployment.

Consul exposes health metrics over port 8500 by default, which the agent’s consul_exporter can then scrape.

Determine your usage scenario and potentially set up a Consul ACL token accordingly. See this tutorial from Hashicorp for further details on how to set up ACLs for your Consul instance.

  1. You can choose to use the consul_exporter configuration in the integrations Grafana Agent configuration block, without an ACL token. This will give you access to metrics from Consul’s Status API, which is enough to populate all of the integration dashboard panels.
  2. If you want the additional metrics provided, beyond what the integration dashboard supports, you can choose to additionally provide a scrape_config entry in the metrics Grafana Agent configuration block that targets Consul’s Prometheus-compatible Agent Telemetry API. This requires an ACL token with agent:read privileges to be specified in the scrape_config entry. Per this Consul documentation, you will need to add the following telemetry snippet to your Consul agent config. This will enable a Prometheus-compatible metrics scraping endpoint on the Consul client:
    "telemetry": {
        "prometheus_retention_time": "72h",
        "disable_hostname": true
    }

Install Consul integration for Grafana Cloud

  1. In your Grafana Cloud stack, click Connections in the left-hand menu.
  2. Find Consul and click its tile to open the integration.
  3. Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send Consul metrics to your Grafana Cloud instance.
  4. Click Install to add this integration’s pre-built dashboard and alerts to your Grafana Cloud instance, and you can start monitoring your Consul setup.

Post-install configuration for the Consul integration

This integration is configured to work with the consul_exporter, which is embedded in Grafana Agent.

Enable the integration by adding the provided snippets to your agent configuration file.

Make sure to change the server address to the address of your Consul instance that you want to monitor.

For a full description of configuration options see how to configure the consul_exporter_config block in the agent documentation.

Configuration snippets for Grafana Agent

Below integrations, insert the following lines and change the URLs according to your environment:

yaml
  consul_exporter:
    enabled: true
    server: localhost:8500
    relabel_configs:
    - replacement: '<your-instance-name>'
      target_label: instance
    - replacement: "integrations/consul"
      target_label: job

Below metrics.configs.scrape_configs, insert the following lines and change the URLs according to your environment:

yaml
    - job_name: 'integrations/consul'
      metrics_path: /v1/agent/metrics
      params:
        format: ["prometheus"]
      authorization:
        credentials: '<consul_acl_token>'
      scrape_interval: 60s
      static_configs:
        - targets: ['localhost:8500']
          labels:
            instance: '<your-instance-name>'

Full example configuration for Grafana Agent

Refer to the following Grafana Agent configuration for a complete example that contains all the snippets used for the Consul integration. This example also includes metrics that are sent to monitor your Grafana Agent instance.

yaml
integrations:
  prometheus_remote_write:
  - basic_auth:
      password: <your_prom_pass>
      username: <your_prom_user>
    url: <your_prom_url>
  agent:
    enabled: true
    relabel_configs:
    - action: replace
      source_labels:
      - agent_hostname
      target_label: instance
    - action: replace
      target_label: job
      replacement: "integrations/agent-check"
    metric_relabel_configs:
    - action: keep
      regex: (prometheus_target_sync_length_seconds_sum|prometheus_target_scrapes_.*|prometheus_target_interval.*|prometheus_sd_discovered_targets|agent_build.*|agent_wal_samples_appended_total|process_start_time_seconds)
      source_labels:
      - __name__
  # Add here any snippet that belongs to the `integrations` section.
  # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
  consul_exporter:
    enabled: true
    server: localhost:8500
    relabel_configs:
    - replacement: '<your-instance-name>'
      target_label: instance
    - replacement: "integrations/consul"
      target_label: job
logs:
  configs:
  - clients:
    - basic_auth:
        password: <your_loki_pass>
        username: <your_loki_user>
      url: <your_loki_url>
    name: integrations
    positions:
      filename: /tmp/positions.yaml
    scrape_configs:
      # Add here any snippet that belongs to the `logs.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
metrics:
  configs:
  - name: integrations
    remote_write:
    - basic_auth:
        password: <your_prom_pass>
        username: <your_prom_user>
      url: <your_prom_url>
    scrape_configs:
      # Add here any snippet that belongs to the `metrics.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
    - job_name: 'integrations/consul'
      metrics_path: /v1/agent/metrics
      params:
        format: ["prometheus"]
      authorization:
        credentials: '<consul_acl_token>'
      scrape_interval: 60s
      static_configs:
        - targets: ['localhost:8500']
          labels:
            instance: '<your-instance-name>'
  global:
    scrape_interval: 60s
  wal_directory: /tmp/grafana-agent-wal

Dashboards

The Consul integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.

  • Consul Overview

Consul Overview

Consul Overview

Alerts

The Consul integration includes the following useful alerts:

AlertDescription
ConsulUpCritical: Consul is not up.
ConsulMasterCritical: Consul has no master.
ConsulPeersCritical: Consul does not have peers.

Metrics

The most important metrics provided by the Consul integration, which are used on the pre-built dashboard and Prometheus alerts, are as follows:

  • consul_raft_leader
  • consul_raft_leader_lastcontact_count
  • consul_raft_peers
  • consul_up

Changelog

md
# 0.0.5 - September 2023

* New Filter Metrics option for configuring the Grafana Agent, which saves on metrics cost by dropping any metric not used by this integration. Beware that anything custom built using metrics that are not on the snippet will stop working.
* New hostname relabel option, which applies the instance name you write on the text box to the Grafana Agent configuration snippets, making it easier and less error prone to configure this mandatory label.

# 0.0.4 - August 2023

* Expand with some optional Agent configuration snippets and supporting documentation

# 0.0.3 - June 2022

* Make job template variable multi-select

# 0.0.2 - October 2021

* Update all rate queries to use `$__rate_interval`, so they respect the default resolution

# 0.0.1 - December 2020

* Initial release

Cost

By connecting your Consul instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see Active series and dpm usage and Cloud tier pricing.