Skip to content

Commit 90b8148

Browse files
authored
Correctly obtain name Ceph service names (#9)
Ceph containers like "ceph-nfs-pacemaker" don't have either ceph-fsid nor node's hostname in their names. This change fixes parsing names of such containers.
1 parent 9946c09 commit 90b8148

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

pkg/virt/virt.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ import (
1515
"path/filepath"
1616
"strings"
1717

18-
"github.com/pkg/errors"
1918
"github.com/infrawatch/collectd-libpod-stats/pkg/cgroups"
2019
"github.com/infrawatch/collectd-libpod-stats/pkg/containers"
20+
"github.com/pkg/errors"
2121
)
2222

2323
const (
2424
//container path relative to user
25-
relativeContainersPath string = "containers/storage/overlay-containers/containers.json"
25+
relativeContainersPath string = "containers/storage/overlay-containers/containers.json"
2626
relativeVolatileContainersPath string = "containers/storage/overlay-containers/volatile-containers.json"
2727
)
2828

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
3131
type MetricMatrix map[string]map[cgroups.ControlType]uint64
3232

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
3434
func ContainersStats(cgroupControls ...cgroups.ControlType) (MetricMatrix, error) {
3535
cgroup2, err := cgroups.IsCgroup2UnifiedMode()
3636
if err != nil {
@@ -71,7 +71,7 @@ func ContainersStats(cgroupControls ...cgroups.ControlType) (MetricMatrix, error
7171
return retMatrix, nil
7272
}
7373

74-
//getContainers returns map with containers created on host indexed by name
74+
// getContainers returns map with containers created on host indexed by name
7575
func getContainers() (map[string]*containers.Container, error) {
7676
/*
7777
libpod stores container related information in one of two places:
@@ -173,9 +173,14 @@ func genContainerCgroupPath(ctype cgroups.ControlType, id string, cgroup2 bool,
173173
node_hostname = strings.Split(node_hostname, ".")[0]
174174

175175
// 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, "-")
179184

180185
/*
181186
Find out the directory starting with the prefix "ceph-<FSID>-" corresponding to `ceph_service_name`

0 commit comments

Comments
 (0)