Skip to content

Commit

Permalink
fix formatting pv metrics (#1219)
Browse files Browse the repository at this point in the history
Co-authored-by: Amol Agrawal <[email protected]>
  • Loading branch information
pfrcks and Amol Agrawal authored Mar 29, 2024
1 parent 1526f23 commit db3690a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions source/plugins/go/input/lib/cadvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1203,12 +1203,12 @@ func getPersistentVolumeMetrics(metricInfo map[string]interface{}, hostName, met
excludeNamespace = true
}

podVolume, ok := podData["volume"].(map[string]interface{})
podVolume, ok := podData["volume"].([]interface{})
if !excludeNamespace && ok {
for _, volume := range podVolume {
pvcRef, ok := volume.(map[string]interface{})["pvcRef"].(map[string]interface{})
parsedVolume := volume.(map[string]interface{})
pvcRef, ok := parsedVolume["pvcRef"].(map[string]interface{})
if !ok {
Log.Warnf("Error: pvcRef data is not a map")
continue
}

Expand All @@ -1225,7 +1225,7 @@ func getPersistentVolumeMetrics(metricInfo map[string]interface{}, hostName, met
metricItem["CollectionTime"] = metricTime
metricItem["Computer"] = hostName
metricItem["Name"] = metricName
metricItem["Value"] = volume.(map[string]interface{})[metricKey]
metricItem["Value"] = parsedVolume[metricKey].(float64)
metricItem["Origin"] = INSIGHTSMETRICS_TAGS_ORIGIN
metricItem["Namespace"] = INSIGHTSMETRICS_TAGS_PV_NAMESPACE

Expand All @@ -1236,11 +1236,15 @@ func getPersistentVolumeMetrics(metricInfo map[string]interface{}, hostName, met
metricTags[INSIGHTSMETRICS_TAGS_POD_NAME] = podName
metricTags[INSIGHTSMETRICS_TAGS_PVC_NAME] = pvcName
metricTags[INSIGHTSMETRICS_TAGS_PVC_NAMESPACE] = pvcNamespace
metricTags[INSIGHTSMETRICS_TAGS_VOLUME_NAME] = volume.(map[string]interface{})["name"].(string)
metricTags[INSIGHTSMETRICS_TAGS_PV_CAPACITY_BYTES] = volume.(map[string]interface{})["capacityBytes"].(string)

metricItem["Tags"] = metricTags
metricTags[INSIGHTSMETRICS_TAGS_VOLUME_NAME] = parsedVolume["name"].(string)
metricTags[INSIGHTSMETRICS_TAGS_PV_CAPACITY_BYTES] = fmt.Sprintf("%.0f", parsedVolume["capacityBytes"].(float64))

jsonTags, err := json.Marshal(metricTags)
if (err != nil) {
Log.Warnf("Error marshaling metricTags: %s", err)
continue
}
metricItem["Tags"] = string(jsonTags)
metricItems = append(metricItems, metricItem)
}
}
Expand Down

0 comments on commit db3690a

Please sign in to comment.