@@ -328,17 +328,27 @@ func (e *Exporter) getMetrics(name string, pids map[string][]int) (CgroupMetric,
328328 return metric , err
329329 }
330330 stats , _ := ctrl .Stat (cgroups .IgnoreNotExist )
331- metric .cpuUser = float64 (stats .CPU .Usage .User ) / 1000000000.0
332- metric .cpuSystem = float64 (stats .CPU .Usage .Kernel ) / 1000000000.0
333- metric .cpuTotal = float64 (stats .CPU .Usage .Total ) / 1000000000.0
334- metric .memoryRSS = float64 (stats .Memory .TotalRSS )
335- metric .memoryCache = float64 (stats .Memory .TotalCache )
336- metric .memoryUsed = float64 (stats .Memory .Usage .Usage )
337- metric .memoryTotal = float64 (stats .Memory .Usage .Limit )
338- metric .memoryFailCount = float64 (stats .Memory .Usage .Failcnt )
339- metric .memswUsed = float64 (stats .Memory .Swap .Usage )
340- metric .memswTotal = float64 (stats .Memory .Swap .Limit )
341- metric .memswFailCount = float64 (stats .Memory .Swap .Failcnt )
331+ if stats .CPU != nil {
332+ if stats .CPU .Usage != nil {
333+ metric .cpuUser = float64 (stats .CPU .Usage .User ) / 1000000000.0
334+ metric .cpuSystem = float64 (stats .CPU .Usage .Kernel ) / 1000000000.0
335+ metric .cpuTotal = float64 (stats .CPU .Usage .Total ) / 1000000000.0
336+ }
337+ }
338+ if stats .Memory != nil {
339+ metric .memoryRSS = float64 (stats .Memory .TotalRSS )
340+ metric .memoryCache = float64 (stats .Memory .TotalCache )
341+ if stats .Memory .Usage != nil {
342+ metric .memoryUsed = float64 (stats .Memory .Usage .Usage )
343+ metric .memoryTotal = float64 (stats .Memory .Usage .Limit )
344+ metric .memoryFailCount = float64 (stats .Memory .Usage .Failcnt )
345+ }
346+ if stats .Memory .Swap != nil {
347+ metric .memswUsed = float64 (stats .Memory .Swap .Usage )
348+ metric .memswTotal = float64 (stats .Memory .Swap .Limit )
349+ metric .memswFailCount = float64 (stats .Memory .Swap .Failcnt )
350+ }
351+ }
342352 if cpus , err := getCPUs (name , e .logger ); err == nil {
343353 metric .cpus = len (cpus )
344354 metric .cpu_list = strings .Join (cpus , "," )
0 commit comments