Skip to content

Commit

Permalink
add support to show overall cluster maintenance mode
Browse files Browse the repository at this point in the history
  • Loading branch information
scrusanhrt committed Jul 24, 2024
1 parent 88de01b commit e602c9f
Show file tree
Hide file tree
Showing 4 changed files with 18 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
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -423,6 +424,7 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
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-20191204190536-9bdfabe68543/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 e602c9f

Please sign in to comment.