Skip to content

Commit

Permalink
add support to show overall cluster maintenance mode (#260)
Browse files Browse the repository at this point in the history
Co-authored-by: Stefano Torresi <[email protected]>
  • Loading branch information
scrusanhrt and stefanotorresi authored Aug 2, 2024
1 parent d0d3705 commit e26395b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion collector/pacemaker/crmmon/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ type Root struct {
Blocked int `xml:"blocked,attr"`
} `xml:"resources_configured"`
ClusterOptions struct {
StonithEnabled bool `xml:"stonith-enabled,attr"`
StonithEnabled bool `xml:"stonith-enabled,attr"`
MaintenanceMode bool `xml:"maintenance-mode,attr"`
} `xml:"cluster_options"`
} `xml:"summary"`
Nodes []Node `xml:"nodes>node"`
Expand Down
11 changes: 11 additions & 0 deletions collector/pacemaker/pacemaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func NewCollector(crmMonPath string, cibAdminPath string, timestamps bool, logge
c.SetDescriptor("node_attributes", "Metadata attributes of each node; value is always 1", []string{"node", "name", "value"})
c.SetDescriptor("resources", "The status of each resource in the cluster; 1 means the resource is in that status, 0 otherwise", []string{"node", "resource", "role", "managed", "status", "agent", "group", "clone"})
c.SetDescriptor("stonith_enabled", "Whether or not stonith is enabled", nil)
c.SetDescriptor("maintenance_mode_enabled", "Whether or not cluster wide maintenance-mode is enabled", nil)
c.SetDescriptor("fail_count", "The Fail count number per node and resource id", []string{"node", "resource"})
c.SetDescriptor("migration_threshold", "The migration_threshold number per node and resource id", []string{"node", "resource"})
c.SetDescriptor("config_last_change", "The timestamp of the last change of the cluster configuration", nil)
Expand Down Expand Up @@ -61,6 +62,7 @@ func (c *pacemakerCollector) CollectWithError(ch chan<- prometheus.Metric) error
}

c.recordStonithStatus(crmMon, ch)
c.recordMaintenanceModeStatus(crmMon, ch)
c.recordNodes(crmMon, ch)
c.recordNodeAttributes(crmMon, ch)
c.recordResources(crmMon, ch)
Expand All @@ -85,6 +87,15 @@ func (c *pacemakerCollector) Collect(ch chan<- prometheus.Metric) {
}
}

func (c *pacemakerCollector) recordMaintenanceModeStatus(crmMon crmmon.Root, ch chan<- prometheus.Metric) {
var maintenanceModeEnabled float64
if crmMon.Summary.ClusterOptions.MaintenanceMode {
maintenanceModeEnabled = 1
}

ch <- c.MakeGaugeMetric("maintenance_mode_enabled", maintenanceModeEnabled)
}

func (c *pacemakerCollector) recordStonithStatus(crmMon crmmon.Root, ch chan<- prometheus.Metric) {
var stonithEnabled float64
if crmMon.Summary.ClusterOptions.StonithEnabled {
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
3 changes: 3 additions & 0 deletions test/pacemaker.metrics
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,6 @@ ha_cluster_pacemaker_resources{agent="stonith:external/sbd",clone="",group="",ma
# HELP ha_cluster_pacemaker_stonith_enabled Whether or not stonith is enabled
# TYPE ha_cluster_pacemaker_stonith_enabled gauge
ha_cluster_pacemaker_stonith_enabled 1
# HELP ha_cluster_pacemaker_maintenance_mode_enabled Whether or not cluster wide maintenance-mode is enabled
# TYPE ha_cluster_pacemaker_maintenance_mode_enabled gauge
ha_cluster_pacemaker_maintenance_mode_enabled 0

0 comments on commit e26395b

Please sign in to comment.