Skip to content

Commit

Permalink
Add metric to collect wan status
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemarey committed Sep 17, 2021
1 parent e944f46 commit b51931b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
21 changes: 21 additions & 0 deletions pkg/exporter/consul_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b51931b

Please sign in to comment.