@@ -18,7 +18,6 @@ package raw
18
18
import (
19
19
"fmt"
20
20
"io/ioutil"
21
- "os"
22
21
"path"
23
22
"strings"
24
23
@@ -62,6 +61,8 @@ type rawContainerHandler struct {
62
61
63
62
// Metrics to be ignored.
64
63
ignoreMetrics container.MetricSet
64
+
65
+ pid int
65
66
}
66
67
67
68
func (self * rawContainerHandler ) GetCgroupPaths () map [string ]string {
@@ -88,6 +89,10 @@ func (self *rawContainerHandler) HasFilesystem() bool {
88
89
return false
89
90
}
90
91
92
+ func isRootCgroup (name string ) bool {
93
+ return name == "/"
94
+ }
95
+
91
96
func newRawContainerHandler (name string , cgroupSubsystems * libcontainer.CgroupSubsystems , machineInfoFactory info.MachineInfoFactory , fsInfo fs.FsInfo , watcher * common.InotifyWatcher , rootFs string , ignoreMetrics container.MetricSet ) (container.ContainerHandler , error ) {
92
97
cgroupPaths := common .MakeCgroupPaths (cgroupSubsystems .MountPoints , name )
93
98
@@ -112,6 +117,11 @@ func newRawContainerHandler(name string, cgroupSubsystems *libcontainer.CgroupSu
112
117
}
113
118
}
114
119
120
+ pid := 0
121
+ if isRootCgroup (name ) {
122
+ pid = 1
123
+ }
124
+
115
125
return & rawContainerHandler {
116
126
name : name ,
117
127
cgroupSubsystems : cgroupSubsystems ,
@@ -124,6 +134,7 @@ func newRawContainerHandler(name string, cgroupSubsystems *libcontainer.CgroupSu
124
134
watcher : watcher ,
125
135
rootFs : rootFs ,
126
136
ignoreMetrics : ignoreMetrics ,
137
+ pid : pid ,
127
138
}, nil
128
139
}
129
140
@@ -136,7 +147,7 @@ func (self *rawContainerHandler) ContainerReference() (info.ContainerReference,
136
147
137
148
func (self * rawContainerHandler ) GetRootNetworkDevices () ([]info.NetInfo , error ) {
138
149
nd := []info.NetInfo {}
139
- if self .name == "/" {
150
+ if isRootCgroup ( self .name ) {
140
151
mi , err := self .machineInfoFactory .GetMachineInfo ()
141
152
if err != nil {
142
153
return nd , err
@@ -158,7 +169,7 @@ func (self *rawContainerHandler) GetSpec() (info.ContainerSpec, error) {
158
169
159
170
func (self * rawContainerHandler ) getFsStats (stats * info.ContainerStats ) error {
160
171
// Get Filesystem information only for the root cgroup.
161
- if self .name == "/" {
172
+ if isRootCgroup ( self .name ) {
162
173
filesystems , err := self .fsInfo .GetGlobalFsInfo ()
163
174
if err != nil {
164
175
return err
@@ -221,7 +232,7 @@ func (self *rawContainerHandler) getFsStats(stats *info.ContainerStats) error {
221
232
}
222
233
223
234
func (self * rawContainerHandler ) GetStats () (* info.ContainerStats , error ) {
224
- stats , err := libcontainer .GetStats (self .cgroupManager , self .rootFs , os . Getpid () , self .ignoreMetrics )
235
+ stats , err := libcontainer .GetStats (self .cgroupManager , self .rootFs , self . pid , self .ignoreMetrics )
225
236
if err != nil {
226
237
return stats , err
227
238
}
0 commit comments