@@ -39,38 +39,7 @@ func GetCgroupSubsystems(includedMetrics container.MetricSet) (map[string]string
39
39
return nil , err
40
40
}
41
41
42
- disableCgroups := map [string ]struct {}{}
43
-
44
- if ! includedMetrics .Has (container .DiskIOMetrics ) {
45
- disableCgroups ["blkio" ] = struct {}{}
46
- disableCgroups ["io" ] = struct {}{}
47
- }
48
-
49
- if ! includedMetrics .Has (container .CpuUsageMetrics ) {
50
- disableCgroups ["cpu" ] = struct {}{}
51
- }
52
-
53
- if ! includedMetrics .Has (container .CPUSetMetrics ) {
54
- disableCgroups ["cpuset" ] = struct {}{}
55
- }
56
-
57
- if ! includedMetrics .Has (container .HugetlbUsageMetrics ) {
58
- disableCgroups ["hugetlb" ] = struct {}{}
59
- }
60
-
61
- if ! includedMetrics .Has (container .MemoryUsageMetrics ) {
62
- disableCgroups ["memory" ] = struct {}{}
63
- }
64
-
65
- if ! includedMetrics .Has (container .PerfMetrics ) {
66
- disableCgroups ["perf_event" ] = struct {}{}
67
- }
68
-
69
- if ! includedMetrics .Has (container .ProcessMetrics ) {
70
- disableCgroups ["pids" ] = struct {}{}
71
- }
72
-
73
- return getCgroupSubsystemsHelper (allCgroups , disableCgroups )
42
+ return getCgroupSubsystemsHelper (allCgroups , includedMetrics )
74
43
}
75
44
76
45
// Get information about all the cgroup subsystems.
@@ -81,11 +50,10 @@ func GetAllCgroupSubsystems() (map[string]string, error) {
81
50
return nil , err
82
51
}
83
52
84
- emptyDisableCgroups := map [string ]struct {}{}
85
- return getCgroupSubsystemsHelper (allCgroups , emptyDisableCgroups )
53
+ return getCgroupSubsystemsHelper (allCgroups , nil )
86
54
}
87
55
88
- func getCgroupSubsystemsHelper (allCgroups []cgroups.Mount , disableCgroups map [ string ] struct {} ) (map [string ]string , error ) {
56
+ func getCgroupSubsystemsHelper (allCgroups []cgroups.Mount , includedMetrics container. MetricSet ) (map [string ]string , error ) {
89
57
if len (allCgroups ) == 0 {
90
58
return nil , fmt .Errorf ("failed to find cgroup mounts" )
91
59
}
@@ -94,11 +62,7 @@ func getCgroupSubsystemsHelper(allCgroups []cgroups.Mount, disableCgroups map[st
94
62
mountPoints := make (map [string ]string , len (allCgroups ))
95
63
for _ , mount := range allCgroups {
96
64
for _ , subsystem := range mount .Subsystems {
97
- if _ , exists := disableCgroups [subsystem ]; exists {
98
- continue
99
- }
100
- if _ , ok := supportedSubsystems [subsystem ]; ! ok {
101
- // Unsupported subsystem
65
+ if ! needSubsys (subsystem , includedMetrics ) {
102
66
continue
103
67
}
104
68
if _ , ok := mountPoints [subsystem ]; ok {
@@ -113,18 +77,34 @@ func getCgroupSubsystemsHelper(allCgroups []cgroups.Mount, disableCgroups map[st
113
77
return mountPoints , nil
114
78
}
115
79
116
- // Cgroup subsystems we support listing (should be the minimal set we need stats from).
117
- var supportedSubsystems map [string ]struct {} = map [string ]struct {}{
118
- "cpu" : {},
119
- "cpuacct" : {},
120
- "memory" : {},
121
- "hugetlb" : {},
122
- "pids" : {},
123
- "cpuset" : {},
124
- "blkio" : {},
125
- "io" : {},
126
- "devices" : {},
127
- "perf_event" : {},
80
+ // A map of cgroup subsystems we support listing (should be the minimal set
81
+ // we need stats from) to a respective MetricKind.
82
+ var supportedSubsystems = map [string ]container.MetricKind {
83
+ "cpu" : container .CpuUsageMetrics ,
84
+ "cpuacct" : container .CpuUsageMetrics ,
85
+ "memory" : container .MemoryUsageMetrics ,
86
+ "hugetlb" : container .HugetlbUsageMetrics ,
87
+ "pids" : container .ProcessMetrics ,
88
+ "cpuset" : container .CPUSetMetrics ,
89
+ "blkio" : container .DiskIOMetrics ,
90
+ "io" : container .DiskIOMetrics ,
91
+ "devices" : "" ,
92
+ "perf_event" : container .PerfMetrics ,
93
+ }
94
+
95
+ // Check if this cgroup subsystem/controller is of use.
96
+ func needSubsys (name string , metrics container.MetricSet ) bool {
97
+ // Check if supported.
98
+ metric , supported := supportedSubsystems [name ]
99
+ if ! supported {
100
+ return false
101
+ }
102
+ // Check if needed.
103
+ if metrics == nil || metric == "" {
104
+ return true
105
+ }
106
+
107
+ return metrics .Has (metric )
128
108
}
129
109
130
110
func diskStatsCopy0 (major , minor uint64 ) * info.PerDiskStats {
0 commit comments