@@ -1203,12 +1203,12 @@ func getPersistentVolumeMetrics(metricInfo map[string]interface{}, hostName, met
12031203 excludeNamespace = true
12041204 }
12051205
1206- podVolume , ok := podData ["volume" ].(map [ string ]interface {})
1206+ podVolume , ok := podData ["volume" ].([ ]interface {})
12071207 if ! excludeNamespace && ok {
12081208 for _ , volume := range podVolume {
1209- pvcRef , ok := volume .(map [string ]interface {})["pvcRef" ].(map [string ]interface {})
1209+ parsedVolume := volume .(map [string ]interface {})
1210+ pvcRef , ok := parsedVolume ["pvcRef" ].(map [string ]interface {})
12101211 if ! ok {
1211- Log .Warnf ("Error: pvcRef data is not a map" )
12121212 continue
12131213 }
12141214
@@ -1225,7 +1225,7 @@ func getPersistentVolumeMetrics(metricInfo map[string]interface{}, hostName, met
12251225 metricItem ["CollectionTime" ] = metricTime
12261226 metricItem ["Computer" ] = hostName
12271227 metricItem ["Name" ] = metricName
1228- metricItem ["Value" ] = volume .( map [ string ] interface {})[ metricKey ]
1228+ metricItem ["Value" ] = parsedVolume [ metricKey ].( float64 )
12291229 metricItem ["Origin" ] = INSIGHTSMETRICS_TAGS_ORIGIN
12301230 metricItem ["Namespace" ] = INSIGHTSMETRICS_TAGS_PV_NAMESPACE
12311231
@@ -1236,11 +1236,15 @@ func getPersistentVolumeMetrics(metricInfo map[string]interface{}, hostName, met
12361236 metricTags [INSIGHTSMETRICS_TAGS_POD_NAME ] = podName
12371237 metricTags [INSIGHTSMETRICS_TAGS_PVC_NAME ] = pvcName
12381238 metricTags [INSIGHTSMETRICS_TAGS_PVC_NAMESPACE ] = pvcNamespace
1239- metricTags [INSIGHTSMETRICS_TAGS_VOLUME_NAME ] = volume .(map [string ]interface {})["name" ].(string )
1240- metricTags [INSIGHTSMETRICS_TAGS_PV_CAPACITY_BYTES ] = volume .(map [string ]interface {})["capacityBytes" ].(string )
1241-
1242- metricItem ["Tags" ] = metricTags
1239+ metricTags [INSIGHTSMETRICS_TAGS_VOLUME_NAME ] = parsedVolume ["name" ].(string )
1240+ metricTags [INSIGHTSMETRICS_TAGS_PV_CAPACITY_BYTES ] = fmt .Sprintf ("%.0f" , parsedVolume ["capacityBytes" ].(float64 ))
12431241
1242+ jsonTags , err := json .Marshal (metricTags )
1243+ if (err != nil ) {
1244+ Log .Warnf ("Error marshaling metricTags: %s" , err )
1245+ continue
1246+ }
1247+ metricItem ["Tags" ] = string (jsonTags )
12441248 metricItems = append (metricItems , metricItem )
12451249 }
12461250 }
0 commit comments