diff --git a/README.md b/README.md index fe9c5ff..6d2b79c 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ make | 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_serf_wan_member_status | Status of member in the wan cluster. 1=Alive, 2=Leaving, 3=Left, 4=Failed. | member, dc | | 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 | diff --git a/pkg/exporter/consul_exporter.go b/pkg/exporter/consul_exporter.go index 5e4eace..6554661 100644 --- a/pkg/exporter/consul_exporter.go +++ b/pkg/exporter/consul_exporter.go @@ -61,6 +61,11 @@ var ( "Status of member in the cluster. 1=Alive, 2=Leaving, 3=Left, 4=Failed.", []string{"member"}, nil, ) + memberWanStatus = prometheus.NewDesc( + prometheus.BuildFQName(namespace, "", "serf_wan_member_status"), + "Status of member in the wan cluster. 1=Alive, 2=Leaving, 3=Left, 4=Failed.", + []string{"member", "dc"}, nil, + ) serviceCount = prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "catalog_services"), "How many services are in the cluster.", @@ -188,6 +193,7 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) { ch <- clusterLeader ch <- nodeCount ch <- memberStatus + ch <- memberWanStatus ch <- serviceCount ch <- serviceNodesHealthy ch <- nodeChecks @@ -204,6 +210,7 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { ok = e.collectLeaderMetric(ch) && ok ok = e.collectNodesMetric(ch) && ok ok = e.collectMembersMetric(ch) && ok + ok = e.collectMembersWanMetric(ch) && ok ok = e.collectServicesMetric(ch) && ok ok = e.collectHealthStateMetric(ch) && ok ok = e.collectKeyValues(ch) && ok @@ -275,6 +282,20 @@ func (e *Exporter) collectMembersMetric(ch chan<- prometheus.Metric) bool { return true } +func (e *Exporter) collectMembersWanMetric(ch chan<- prometheus.Metric) bool { + members, err := e.client.Agent().Members(true) + if err != nil { + level.Error(e.logger).Log("msg", "Failed to query wan member status", "err", err) + return false + } + for _, entry := range members { + ch <- prometheus.MustNewConstMetric( + memberWanStatus, prometheus.GaugeValue, float64(entry.Status), entry.Name, entry.Tags["dc"], + ) + } + return true +} + func (e *Exporter) collectServicesMetric(ch chan<- prometheus.Metric) bool { serviceNames, _, err := e.client.Catalog().Services(&e.queryOptions) if err != nil {