---
title: HCP Consul monitoring (via StatsD)
source: https://docs.newrelic.com/docs/infrastructure/other-infrastructure-integrations/hcp-consul-monitoring
---

HCP (Hashicorp Cloud Platform) Consul is a version of Consul in which the control plane is managed by HashiCorp Cloud Platform. HCP Consul is a service mesh and service discovery solution provided by Hashicorp. It enables platform operators to quickly deploy a fully managed, secure-by-default service mesh, helping developers discover and securely connect any application on any runtime, including Kubernetes, Nomad, and Amazon ECS.

Keeping your Consul clusters healthy can help with optimizing SQL query times, troubleshooting slow HTTP response times, and real-time alerting on down-time for your Hashicorp clusters. Monitoring your Hashicorp cluster metrics is pivotal for keeping your Hashicorp mesh services operating at full capacity.

> #### 💡 TIP
>
> We also have a [HashiCorp Consul integration](https://docs.newrelic.com/docs/infrastructure/host-integrations/host-integrations-list/hashicorp-consul-monitoring-integration) for Consul instances not on HCP.

### Monitor HCP Consul metrics with New Relic [#monitor-metrics]

There are a number of ways and environments in which HCP Consul is installed. In the examples below, we will work with HCP's Quick Start installed via Terraform.

New Relic supports monitoring of HCP Consul and Envoy metrics through the StatsD plugin integration. The StatsD plugin aggregates all the metrics exposed by HCP Consul and pushes them to New Relic for data visualization and alerting.

### Generate the Terraform deploy file [#terraform-file]

Generate the Terraform deployment file from your HCP Portal account's **Overview** page.

![consul overview](https://docs.newrelic.com/images/infrastructure_screenshot-crop_consul-overview.webp "consul overview")

### Deploy the Consul cluster [#deploy]

Deploy the Consul cluster following the steps for the appropriate environment in the [end-to-end overview](https://learn.hashicorp.com/tutorials/cloud/consul-end-to-end-overview). **Important:** Ensure you follow the **Consul CLI configuration** at the bottom of the **Deploy** page.

## [gostatsd](https://github.com/atlassian/gostatsd) installation [#statsd-install]

Copy [`deploy-gostatsd.yaml`](https://github.com/newrelic-experimental/hashicorp-quickstart-annex/blob/main/hcp-consul/deploy-gostatsd.yaml) and [`rbac-gostatsd.yaml`](https://github.com/newrelic-experimental/hashicorp-quickstart-annex/blob/main/hcp-consul/rbac-gostatsd.yaml) to your local Kubernetes client.

### Edit deploy-gstatsd.yaml [#edit-yaml]

1.  Replace `YOUR_NEW_RELIC_ACCOUNT_ID` with your New Relic account ID.
2.  Replace `YOUR_NEW_RELIC_LICENSE_KEY` with your New Relic license key.
3.  Adjust URLs for EU, JP, or FedRAMP accounts if necessary (see comments in file).

### Deploy gostatsd [#deploy-statsd]

Run the following commands in your local Kubernetes client:

```bash
kubectl apply -f deploy-gostatsd.yaml
kubectl apply -f rbac-gostatsd.yaml
```

## Configure the Consul clients to report metrics [#configure-consul-client]

### Edit consul-client-config Map

Add [Consul telemetry configuration](https://www.consul.io/docs/agent/telemetry) by editing the Consul Client's ConfigMap:

```bash
kubectl edit cm consul-client-config
```

Add the following under `data`:

```yaml
telemetry-config.json: |-
  {   
    "telemetry": {
      "disable_hostname": false,
      "disable_compat_1.9": true,
      "dogstatsd_addr": "gostatsd.default.svc.cluster.local:8125",
      "dogstatsd_tags": ["consul.source.datacenter:YOUR_CONSUL_DATACENTER_NAME_HERE"]
    }
  }
```

The result should look something like this:

```yaml
apiVersion: v1
data:
  central-config.json: |-
    {   
      "enable_central_service_config": true
    }   
  config.json: |-
    {   
      "check_update_interval": "0s"
    }   
  extra-from-values.json: '{}'
  telemetry-config.json: |-
    {   
      "telemetry": {
        "disable_hostname": false,
        "disable_compat_1.9": true,
        "dogstatsd_addr": "gostatsd.default.svc.cluster.local:8125",
        "dogstatsd_tags": ["consul.source.datacenter:YOUR_CONSUL_DATACENTER_NAME_HERE"]
      }   
    }  
```

Notes:

1.  We use the `dogstatsd_addr` here so we can add the `consul.source.datacenter` tag to each metric. This lets you filter your dashboards by Consul Datacenter.
2.  Be sure to replace `YOUR_CONSUL_DATACENTER_NAME_HERE` with your Consul Datacenter name.
3.  See [Consul telemetry configuration options](https://www.consul.io/docs/agent/config/config-files#telemetry).

### Edit consul-connect-injector deployment [#edit-consul-connect-injector-deployment]

Enable Consul metrics in the deployment by editing the deployment:

```bash
kubectl edit deploy consul-connect-injector
```

Search for `default-enable-metrics` and set it to `true`:

```bash
-default-enable-metrics=true \
```

**Restart Consul client pods**

The Consul clients may, or may not, restart after the configuration changes. If they do not, restart each Consul client pod:

```bash
kubectl delete pod consul-client-<POD_ID> -n <NAMESPACE>
```

## Browse Consul metrics in New Relic [#browse-metrics]

To see your HCP Consul data in New Relic, navigate to [query builder](https://docs.newrelic.com/docs/query-your-data/explore-query-data/query-builder/introduction-query-builder/).

![query builder](https://docs.newrelic.com/images/infrastructure_screenshot-crop_query-builder.webp "query builder")

Then, use the query below to see HCP Consul metrics:

```sql
SELECT * FROM Metric WHERE metricName LIKE 'consul.%' SINCE 1 minute ago
```

![query metrics](https://docs.newrelic.com/images/infrastructure_screenshot-full_query-metrics.webp "query metrics")

### Install the dashboard [#install-dashboard]

Get started in minutes with a pre-built dashboard to see key metrics from HCP Consul about your clients, networks, runtime, serf, and Envoy.

Go to the [HCP Consul quickstart](https://newrelic.com/instant-observability/hcp-consul) in New Relic Instant Observability, and click **+ Install now**.

![consul dashboard](https://docs.newrelic.com/images/infrastructure_screenshot-full_consul-dashboard.webp "consul dashboard")

### Troubleshooting [#troubleshoot]

For a pod that crashes at init:

```bash
kubectl logs PODNAME -c consul-connect-inject-init
```

For a running pod:

```bash
kubectl logs PODNAME -c DEPLOYMENTNAME
```

### Useful kubectl snippets [#kubectl-snippets]

Delete all pods:

```bash
kubectl get pods | grep PODNAMEPREFIX | cut -f 1 -d ' ' | xargs kubectl delete pods
```

Delete a deployment and pods it generates:

```bash
kubectl delete deployment DEPLOYMENTNAME -n default
```
