Repository: ClusterLabs/ha_cluster_exporter
Pull request #143 (2020-03-19 16:12:06)

add resource agent label to resources
This was hanging in my local Git clone for a while and I completely forgot about it!


Patch:
diff --git a/collector/pacemaker/pacemaker.go b/collector/pacemaker/pacemaker.go
index 69baab2..9ca1a88 100644
--- a/collector/pacemaker/pacemaker.go
+++ b/collector/pacemaker/pacemaker.go
@@ -27,7 +27,7 @@ func NewCollector(crmMonPath string, cibAdminPath string) (*pacemakerCollector,
 		cib.NewCibAdminParser(cibAdminPath),
 	}
 	c.SetDescriptor("nodes", "The nodes in the cluster; one line per name, per status", []string{"node", "type", "status"})
-	c.SetDescriptor("resources", "The resources in the cluster; one line per id, per status", []string{"node", "resource", "role", "managed", "status"})
+	c.SetDescriptor("resources", "The resources in the cluster; one line per id, per status", []string{"node", "resource", "role", "managed", "status", "agent"})
 	c.SetDescriptor("stonith_enabled", "Whether or not stonith 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"})
@@ -142,7 +142,8 @@ func (c *pacemakerCollector) recordResource(resource crmmon.Resource, nodeName s
 			resource.Id,
 			strings.ToLower(resource.Role),
 			strconv.FormatBool(resource.Managed),
-			resourceStatus)
+			resourceStatus,
+			resource.Agent)
 	}
 }
 
diff --git a/doc/metrics.md b/doc/metrics.md
index 25436a1..c0a2087 100644
--- a/doc/metrics.md
+++ b/doc/metrics.md
@@ -99,11 +99,12 @@ Either the value is `1`, or the line is absent altogether.
 
 #### Labels
 
-- `resource`: the unique resource name.
-- `node`: the name of the node hosting the resource.
+- `agent`: the name of the resource agent for this resource.
 - `managed`: either `true` or `false`.
+- `node`: the name of the node hosting the resource.
+- `resource`: the unique resource name.
 - `role`:  one of `started|stopped|master|slave` or one of `starting|stopping|migrating|promoting|demoting`.
-- `status` one of `active|orphaned|blocked|failed|failure_ignored`.
+- `status`: one of `active|orphaned|blocked|failed|failure_ignored`.
 
 The total number of lines for this metric will be the cardinality of `id` times the cardinality of `status`.
 


Test patch:
diff --git a/test/pacemaker.metrics b/test/pacemaker.metrics
index a99ad9d..7733953 100644
--- a/test/pacemaker.metrics
+++ b/test/pacemaker.metrics
@@ -36,14 +36,14 @@ ha_cluster_pacemaker_nodes{node="hana02",status="expected_up",type="member"} 1
 ha_cluster_pacemaker_nodes{node="hana02",status="online",type="member"} 1
 # HELP ha_cluster_pacemaker_resources The resources in the cluster; one line per id, per status
 # TYPE ha_cluster_pacemaker_resources gauge
-ha_cluster_pacemaker_resources{managed="true",node="hana01",resource="rsc_ip_PRD_HDB00",role="started",status="active"} 1
-ha_cluster_pacemaker_resources{managed="true",node="hana01",resource="rsc_SAPHana_PRD_HDB00",role="master",status="active"} 1
-ha_cluster_pacemaker_resources{managed="true",node="hana01",resource="rsc_SAPHanaTopology_PRD_HDB00",role="started",status="active"} 1
-ha_cluster_pacemaker_resources{managed="true",node="hana01",resource="stonith-sbd",role="started",status="active"} 1
-ha_cluster_pacemaker_resources{managed="true",node="hana02",resource="rsc_SAPHana_PRD_HDB00",role="slave",status="active"} 1
-ha_cluster_pacemaker_resources{managed="true",node="hana02",resource="rsc_SAPHanaTopology_PRD_HDB00",role="started",status="active"} 1
-ha_cluster_pacemaker_resources{managed="true",node="hana02",resource="test",role="started",status="active"} 1
-ha_cluster_pacemaker_resources{managed="true",node="",resource="test-stop",role="stopped",status=""} 1
+ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Dummy",managed="true",node="",resource="test-stop",role="stopped",status=""} 1
+ha_cluster_pacemaker_resources{agent="ocf::heartbeat:Dummy",managed="true",node="hana02",resource="test",role="started",status="active"} 1
+ha_cluster_pacemaker_resources{agent="ocf::heartbeat:IPaddr2",managed="true",node="hana01",resource="rsc_ip_PRD_HDB00",role="started",status="active"} 1
+ha_cluster_pacemaker_resources{agent="ocf::suse:SAPHana",managed="true",node="hana01",resource="rsc_SAPHana_PRD_HDB00",role="master",status="active"} 1
+ha_cluster_pacemaker_resources{agent="ocf::suse:SAPHana",managed="true",node="hana02",resource="rsc_SAPHana_PRD_HDB00",role="slave",status="active"} 1
+ha_cluster_pacemaker_resources{agent="ocf::suse:SAPHanaTopology",managed="true",node="hana01",resource="rsc_SAPHanaTopology_PRD_HDB00",role="started",status="active"} 1
+ha_cluster_pacemaker_resources{agent="ocf::suse:SAPHanaTopology",managed="true",node="hana02",resource="rsc_SAPHanaTopology_PRD_HDB00",role="started",status="active"} 1
+ha_cluster_pacemaker_resources{agent="stonith:external/sbd",managed="true",node="hana01",resource="stonith-sbd",role="started",status="active"} 1
 # 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