@@ -15,22 +15,22 @@ import (
15
15
"path/filepath"
16
16
"strings"
17
17
18
- "github.com/pkg/errors"
19
18
"github.com/infrawatch/collectd-libpod-stats/pkg/cgroups"
20
19
"github.com/infrawatch/collectd-libpod-stats/pkg/containers"
20
+ "github.com/pkg/errors"
21
21
)
22
22
23
23
const (
24
24
//container path relative to user
25
- relativeContainersPath string = "containers/storage/overlay-containers/containers.json"
25
+ relativeContainersPath string = "containers/storage/overlay-containers/containers.json"
26
26
relativeVolatileContainersPath string = "containers/storage/overlay-containers/volatile-containers.json"
27
27
)
28
28
29
- //MetricMatrix holds stats for each container according to
30
- //control type. Usage is: map[container label]map[control type]data
29
+ // MetricMatrix holds stats for each container according to
30
+ // control type. Usage is: map[container label]map[control type]data
31
31
type MetricMatrix map [string ]map [cgroups.ControlType ]uint64
32
32
33
- //ContainersStats retrieves stats in specified cgroup controllers for all containers on host
33
+ // ContainersStats retrieves stats in specified cgroup controllers for all containers on host
34
34
func ContainersStats (cgroupControls ... cgroups.ControlType ) (MetricMatrix , error ) {
35
35
cgroup2 , err := cgroups .IsCgroup2UnifiedMode ()
36
36
if err != nil {
@@ -71,7 +71,7 @@ func ContainersStats(cgroupControls ...cgroups.ControlType) (MetricMatrix, error
71
71
return retMatrix , nil
72
72
}
73
73
74
- //getContainers returns map with containers created on host indexed by name
74
+ // getContainers returns map with containers created on host indexed by name
75
75
func getContainers () (map [string ]* containers.Container , error ) {
76
76
/*
77
77
libpod stores container related information in one of two places:
@@ -173,9 +173,14 @@ func genContainerCgroupPath(ctype cgroups.ControlType, id string, cgroup2 bool,
173
173
node_hostname = strings .Split (node_hostname , "." )[0 ]
174
174
175
175
// from `container_name` get the name of the ceph service for which cgroup path is to be found
176
- ceph_service_name := strings .Split (container_name , node_hostname )[0 ]
177
- ceph_service_name = strings .Trim (ceph_service_name , "-" )
178
- ceph_service_name = strings .SplitAfter (ceph_service_name , fmt .Sprintf ("ceph-%s-" , ceph_fsid ))[1 ]
176
+ if strings .Contains (container_name , node_hostname ) {
177
+ container_name = strings .Split (container_name , node_hostname )[0 ]
178
+ }
179
+
180
+ if strings .Contains (container_name , fmt .Sprintf ("ceph-%s" , ceph_fsid )) {
181
+ container_name = strings .Split (container_name , fmt .Sprintf ("ceph-%s" , ceph_fsid ))[1 ]
182
+ }
183
+ ceph_service_name := strings .Trim (container_name , "-" )
179
184
180
185
/*
181
186
Find out the directory starting with the prefix "ceph-<FSID>-" corresponding to `ceph_service_name`
0 commit comments