Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metric to collect wan status #212

Merged
merged 1 commit into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.",
SuperQ marked this conversation as resolved.
Show resolved Hide resolved
[]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