Delete empty tags and meta data tags

This commit is contained in:
Holger Obermaier 2022-04-20 14:39:26 +02:00
parent c2d4272fdf
commit 9d6d0dbd93

View File

@ -79,15 +79,30 @@ func (r *RedfishReceiver) Start() {
if err != nil { if err != nil {
return fmt.Errorf("readPowerMetric: chassis.Power() failed: %v", err) return fmt.Errorf("readPowerMetric: chassis.Power() failed: %v", err)
} }
if power == nil {
continue
}
// Read min, max and average consumed watts for each power control // Read min, max and average consumed watts for each power control
for _, pc := range power.PowerControl { for _, pc := range power.PowerControl {
// Map of collected metrics // Map of collected metrics
metrics := map[string]float32{ metrics := map[string]float32{
// PowerConsumedWatts shall represent the actual power being consumed (in
// Watts) by the chassis
"consumed_watts": pc.PowerConsumedWatts,
// AverageConsumedWatts shall represent the
// average power level that occurred averaged over the last IntervalInMin
// minutes.
"average_consumed_watts": pc.PowerMetrics.AverageConsumedWatts, "average_consumed_watts": pc.PowerMetrics.AverageConsumedWatts,
"min_consumed_watts": pc.PowerMetrics.MinConsumedWatts, // MinConsumedWatts shall represent the
"max_consumed_watts": pc.PowerMetrics.MaxConsumedWatts, // minimum power level in watts that occurred within the last
// IntervalInMin minutes.
"min_consumed_watts": pc.PowerMetrics.MinConsumedWatts,
// MaxConsumedWatts shall represent the
// maximum power level in watts that occurred within the last
// IntervalInMin minutes
"max_consumed_watts": pc.PowerMetrics.MaxConsumedWatts,
} }
intervalInMin := strconv.FormatFloat(float64(pc.PowerMetrics.IntervalInMin), 'f', -1, 32) intervalInMin := strconv.FormatFloat(float64(pc.PowerMetrics.IntervalInMin), 'f', -1, 32)
@ -97,19 +112,46 @@ func (r *RedfishReceiver) Start() {
} }
for name, value := range metrics { for name, value := range metrics {
y, err := lp.New( // Set tags
name, tags := map[string]string{
map[string]string{ "hostname": *clientConfig.Hostname,
"hostname": *clientConfig.Hostname, "type": "node",
"type": "node", // ID uniquely identifies the resource
"power_control_name": pc.Name, "id": pc.ID,
}, // MemberID shall uniquely identify the member within the collection. For
map[string]string{ // services supporting Redfish v1.6 or higher, this value shall be the
"source": r.name, // zero-based array index.
"group": "Energy", "member_id": pc.MemberID,
"interval_in_minutes": intervalInMin, // PhysicalContext shall be a description of the affected device(s) or region
"unit": "watts", // within the chassis to which this power control applies.
}, "physical_context": string(pc.PhysicalContext),
// Name
"power_control_name": pc.Name,
}
// Delete empty tags
for key, value := range tags {
if value == "" {
delete(tags, key)
}
}
// Set meta data tags
meta := map[string]string{
"source": r.name,
"group": "Energy",
"interval_in_minutes": intervalInMin,
"unit": "watts",
}
// Delete empty tags
for key, value := range meta {
if value == "" {
delete(meta, key)
}
}
y, err := lp.New(name, tags, meta,
map[string]interface{}{ map[string]interface{}{
"value": value, "value": value,
}, },