in internal/pacemaker/pacemakermetrics.go [195:289]
func collectPacemakerValAndLabels(ctx context.Context, params Parameters) (float64, map[string]string) {
labels := map[string]string{}
if params.Config.GetCloudProperties() == nil {
log.CtxLogger(ctx).Debug("No cloud properties")
return 0.0, labels
}
properties := params.Config.GetCloudProperties()
projectID := properties.GetProjectId()
crmAvailable := params.Exists("crm")
pacemakerXMLString := XMLString(ctx, params.Execute, crmAvailable)
if pacemakerXMLString == nil {
log.CtxLogger(ctx).Debug("No pacemaker xml")
return 0.0, labels
}
pacemakerDocument, err := ParseXML([]byte(*pacemakerXMLString))
if err != nil {
log.CtxLogger(ctx).Debugw("Could not parse the pacemaker configuration xml", "xml", *pacemakerXMLString, "error", err)
return 0.0, labels
}
instances := clusterNodes(pacemakerDocument.Configuration.Nodes)
// Sort VM instance names by length, descending.
// This should prevent collisions when searching within a substring.
// Ex: instance11, ... , instance1
sort.Slice(instances, func(i, j int) bool { return len(instances[i]) > len(instances[j]) })
results := setPacemakerPrimitives(ctx, labels, pacemakerDocument.Configuration.Resources, instances, params.Config)
if id, ok := results["projectId"]; ok {
projectID = id
}
bearerToken, err := getBearerToken(ctx, results["serviceAccountJsonFile"], params.ConfigFileReader,
params.JSONCredentialsGetter, params.DefaultTokenGetter)
if err != nil {
log.CtxLogger(ctx).Debugw("Could not parse the pacemaker configuration xml", "xml", *pacemakerXMLString, "error", err)
return 0.0, labels
}
rscLocations := pacemakerDocument.Configuration.Constraints.RSCLocations
locationPreferenceSet := "false"
for _, rscLocation := range rscLocations {
idNode := rscLocation.ID
if strings.HasPrefix(idNode, "cli-prefer-") {
locationPreferenceSet = "true"
break
}
}
labels["location_preference_set"] = locationPreferenceSet
rscOptionNvPairs := pacemakerDocument.Configuration.RSCDefaults.NVPairs
setLabelsForRSCNVPairs(labels, rscOptionNvPairs, "migration-threshold")
setLabelsForRSCNVPairs(labels, rscOptionNvPairs, "resource-stickiness")
// Aggregate resources specified as <clone> or <master> into a single slice.
// This is necessary because of differences in the Pacemaker XML config
// between RHEL and SLES.
var cloneResources []Clone
cloneResources = append(cloneResources, pacemakerDocument.Configuration.Resources.Clone...)
cloneResources = append(cloneResources, pacemakerDocument.Configuration.Resources.Master)
var clonePrimitives []PrimitiveClass
for _, cloneResource := range cloneResources {
clonePrimitives = append(clonePrimitives, cloneResource.Primitives...)
}
// This will get metrics for the <primitive> with type=SAPHana.
setPacemakerHanaOperations(labels, filterPrimitiveOpsByType(clonePrimitives, "SAPHana"))
setPacemakerHANACloneAttrs(labels, cloneResources)
// This will get metrics for the <primitive> with type=SAPHanaTopology.
pacemakerHanaTopology(labels, filterPrimitiveOpsByType(clonePrimitives, "SAPHanaTopology"))
setPacemakerHANATopologyCloneAttrs(labels, cloneResources)
setPacemakerAPIAccess(ctx, labels, projectID, bearerToken, params.Execute)
setPacemakerMaintenanceMode(ctx, labels, crmAvailable, params.Execute)
setPacemakerClusterHealthy(ctx, labels, params.Execute)
setPacemakerStonithClusterProperty(labels, pacemakerDocument.Configuration.CRMConfig.ClusterPropertySets)
collectASCSInstance(ctx, labels, params.Exists, params.Execute)
collectEnqueueServer(ctx, labels, params.Execute)
setASCSConfigMetrics(ctx, labels, pacemakerDocument.Configuration.Resources.Groups, params.Execute)
setERSConfigMetrics(ctx, labels, pacemakerDocument.Configuration.Resources.Groups)
// sets the OP options from the pacemaker configuration.
setOPOptions(labels, pacemakerDocument.Configuration.OPDefaults)
setHealthCheckInternalLoadBalancerMetrics(labels, pacemakerDocument.Configuration.Resources.Groups)
return 1.0, labels
}