Hashicorp Consul metrics

The OpenTelemetry Collector, when configured with a Prometheus receiver, provides an integration with Hashicorp Consul to ingest metrics. The Collector fetches metrics from the configured path in the Hashicorp Consul configuration file and sends it to the Prometheus exporter. From there the metrics are received and processed by the Prometheus receiver and exported to Cloud Observability.

To complete the integration, you will:

  • Configure Hashicorp Consul to use the Prometheus exporter.
  • Configure the Collector to use the Hashicorp Consul endpoint as a scrape target for the Prometheus receiver.
  • Enable the integration by adding it to a pipeline

Prerequisites

  • Hashicorp Consul v1.8 or later
  • You’ve configured the Collector to export metric data to Cloud Observability.

Configure Hashicorp Consul reporting

You need to configure Hashicorp Consul to use the Prometheus exporter by setting the native Prometheus endpoint to a retention time greater than 0 and disabling the hostname.

In the Hashicorp Consul configuration file, add the following:

1
2
3
4
telemetry {
  prometheus_retention_time = "60s"
  disable_hostname = true
}

For more details about using Hashicorp Consul with the Prometheus exporter, see the official Hashicorp Consul documentation.

Configure the Collector receiver

In the Collector configuration file, configure the Prometheus receiver to use the Hashicorp Consul endpoint as a scrape target.

1
2
3
4
5
6
7
8
9
10
receivers:
  prometheus:
    config:
      scrape_configs:
        - job_name: 'consul-server'
          metrics_path: '/v1/agent/metrics'
          params:
            format: ['prometheus']
          static_configs:
            - targets: ['localhost:8500']

The OpenTelemetry repo’s readme provides additional details about Prometheus receiver configuration.

Enable the Collector receiver

Once the Hashicorp Consul receiver is configured, enable it by adding it to one or more pipelines as described in the Collector configuration documentation.

Validate metrics are reporting to Cloud Observability

You can validate that metrics are reporting to Cloud Observability on the Metrics details page in Settings.

  1. In Cloud Observability, click Settings > Metric details.

  2. Search for Hashicorp Consul metric names. Arrow points to the metrics search box.

    See the Consul docs for a complete list of emitted metrics.
    Note that the metric names will be converted to Prometheus conventions. For example . will be replaced by _, so consul.runtime.alloc_bytes will be renamed to consul_runtime_alloc_bytes.

  3. If needed, click on the metric to edit the description and how the units are displayed in Cloud Observability.

Create a dashboard for the metrics

Use the Cloud Observability Terraform Provider to create a dashboard for the metrics.

Additional resources

For a more complete example that’s ready to run, see the Hashicorp Consul integration in Cloud Observability OpenTelemetry Examples.

Read Hashicorp’s blog post about using OpenTelemetry with Consul.

See also

Create and manage dashboards

Create alerts

Updated Dec 1, 2022