Skip to content
Exporter for Consul metrics
Go Makefile Dockerfile
Branch: master
Clone or download

Latest commit

yz1509 fix "service_checks was collected before with the same name and label…
… values" (#169)

* fix "service_checks was collected before with the same name and label values"

Signed-off-by: yz1509 <pro-765@qq.com>

* modify test case

Signed-off-by: yz1509 <pro-765@qq.com>
Latest commit adc1820 May 25, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci .circleci/config.yml: collect test metadata (#163) May 14, 2020
.github Add template for issues (#165) May 14, 2020
scripts Switch logging to go-kit (#144) Oct 22, 2019
vendor *: bump Go dependencies (#158) Feb 14, 2020
.dockerignore Fix build for ARM container images (#121) Jul 1, 2019
.gitignore New release process using docker, circleci and a centralized building… May 14, 2016
.golangci.yml Fix up lint errors Jun 13, 2019
.promu.yml Bump golang version to 1.14 (#167) May 6, 2020
CHANGELOG.md Cut 0.6.0 (#155) Dec 16, 2019
CONTRIBUTING.md Replace AUTHORS.md by an updated MAINTAINERS.md Feb 16, 2017
Dockerfile adding non-root user in dockerfile (#139) Sep 16, 2019
LICENSE Initial commit Mar 18, 2015
MAINTAINERS.md Change maintainer to Simon Pasquier Jun 18, 2019
Makefile Bump github.com/hashicorp/consul (#128) Jul 26, 2019
Makefile.common makefile: update Makefile.common with newer version (#168) May 19, 2020
NOTICE New release process using docker, circleci and a centralized building… May 14, 2016
README.md fix "service_checks was collected before with the same name and label… May 25, 2020
VERSION Cut 0.6.0 (#155) Dec 16, 2019
consul_exporter.go fix "service_checks was collected before with the same name and label… May 25, 2020
consul_exporter_test.go fix "service_checks was collected before with the same name and label… May 25, 2020
go.mod *: bump Go dependencies (#158) Feb 14, 2020
go.sum *: bump Go dependencies (#158) Feb 14, 2020

README.md

Consul Exporter

CircleCI Docker Repository on Quay Docker Pulls

Export Consul service health to Prometheus.

To run it:

make
./consul_exporter [flags]

Exported Metrics

Metric Meaning Labels
consul_up Was the last query of Consul successful
consul_raft_peers How many peers (servers) are in the Raft cluster
consul_serf_lan_members How many members are in the cluster
consul_serf_lan_member_status Status of member in the cluster. 1=Alive, 2=Leaving, 3=Left, 4=Failed. member
consul_catalog_services How many services are in the cluster
consul_catalog_service_node_healthy Is this service healthy on this node service, node
consul_health_node_status Status of health checks associated with a node check, node, status
consul_health_service_status Status of health checks associated with a service check, node, service, status
consul_catalog_kv The values for selected keys in Consul's key/value catalog. Keys with non-numeric values are omitted key
consul_service_checks Link the Consul service ID with check name if available service_id,service_name, check_id, check_name, node

Flags

./consul_exporter --help
  • consul.allow_stale: Allows any Consul server (non-leader) to service a read.
  • consul.ca-file: File path to a PEM-encoded certificate authority used to validate the authenticity of a server certificate.
  • consul.cert-file: File path to a PEM-encoded certificate used with the private key to verify the exporter's authenticity.
  • consul.health-summary: Collects information about each registered service and exports consul_catalog_service_node_healthy. This requires n+1 Consul API queries to gather all information about each service. Health check information are available via consul_health_service_status as well, but only for services which have a health check configured. Defaults to true.
  • consul.key-file: File path to a PEM-encoded private key used with the certificate to verify the exporter's authenticity.
  • consul.require_consistent: Forces the read to be fully consistent.
  • consul.server: Address (host and port) of the Consul instance we should connect to. This could be a local agent (localhost:8500, for instance), or the address of a Consul server.
  • consul.server-name: When provided, this overrides the hostname for the TLS certificate. It can be used to ensure that the certificate name matches the hostname we declare.
  • consul.timeout: Timeout on HTTP requests to consul.
  • log.format: Set the log target and format. Example: logger:syslog?appname=bob&local=7 or logger:stdout?json=true
  • log.level: Logging level. info by default.
  • version: Show application version.
  • web.listen-address: Address to listen on for web interface and telemetry.
  • web.telemetry-path: Path under which to expose metrics.

Key/Value Checks

This exporter supports grabbing key/value pairs from Consul's KV store and exposing them to Prometheus. This can be useful, for instance, if you use Consul KV to store your intended cluster size, and want to graph that value against the actual value found via monitoring.

  • kv.filter: Only store keys that match this regex pattern.
  • kv.prefix: Prefix under which to look for KV pairs.

A prefix must be supplied to activate this feature. Pass / if you want to search the entire keyspace.

Environment variables

The consul_exporter supports all environment variables provided by the official consul/api package, including CONSUL_HTTP_TOKEN to set the ACL token.

Useful Queries

Are my services healthy?

min(consul_catalog_service_node_healthy) by (service_name)

Values of 1 mean that all nodes for the service are passing. Values of 0 mean at least one node for the service is not passing.

What service nodes are failing?

sum by (node, service_name)(consul_catalog_service_node_healthy == 0)

What service checks are critical?

consul_health_service_status{status="critical"} == 1

You can query for the following health check states: "maintenance", "critical", "warning" or "passing"

Using Docker

You can deploy this exporter using the prom/consul-exporter Docker image.

For example:

docker pull prom/consul-exporter

docker run -d -p 9107:9107 prom/consul-exporter --consul.server=172.17.0.1:8500

Keep in mind that your container needs to be able to communicate with the Consul server or agent. Use an IP accessible from the container or set the --dns and --dns-search options of the docker run command:

docker run -d -p 9107:9107 --dns=172.17.0.1 --dns-search=service.consul \
        prom/consul-exporter --consul.server=consul:8500
You can’t perform that action at this time.