@@ -18,7 +18,6 @@ package docker
18
18
import (
19
19
"fmt"
20
20
"io/ioutil"
21
- "math"
22
21
"path"
23
22
"strings"
24
23
"time"
@@ -28,7 +27,6 @@ import (
28
27
containerlibcontainer "github.com/google/cadvisor/container/libcontainer"
29
28
"github.com/google/cadvisor/fs"
30
29
info "github.com/google/cadvisor/info/v1"
31
- "github.com/google/cadvisor/utils"
32
30
33
31
docker "github.com/fsouza/go-dockerclient"
34
32
"github.com/opencontainers/runc/libcontainer/cgroups"
@@ -222,50 +220,6 @@ func (self *dockerContainerHandler) ContainerReference() (info.ContainerReferenc
222
220
}, nil
223
221
}
224
222
225
- func (self * dockerContainerHandler ) readLibcontainerConfig () (* libcontainerconfigs.Config , error ) {
226
- config , err := containerlibcontainer .ReadConfig (* dockerRootDir , * dockerRunDir , self .id )
227
- if err != nil {
228
- return nil , fmt .Errorf ("failed to read libcontainer config: %v" , err )
229
- }
230
-
231
- // Replace cgroup parent and name with our own since we may be running in a different context.
232
- if config .Cgroups == nil {
233
- config .Cgroups = new (libcontainerconfigs.Cgroup )
234
- }
235
- config .Cgroups .Name = self .name
236
- config .Cgroups .Parent = "/"
237
-
238
- return config , nil
239
- }
240
-
241
- func libcontainerConfigToContainerSpec (config * libcontainerconfigs.Config , mi * info.MachineInfo ) info.ContainerSpec {
242
- var spec info.ContainerSpec
243
- spec .HasMemory = true
244
- spec .Memory .Limit = math .MaxUint64
245
- spec .Memory .SwapLimit = math .MaxUint64
246
-
247
- if config .Cgroups .Resources != nil {
248
- if config .Cgroups .Resources .Memory > 0 {
249
- spec .Memory .Limit = uint64 (config .Cgroups .Resources .Memory )
250
- }
251
- if config .Cgroups .Resources .MemorySwap > 0 {
252
- spec .Memory .SwapLimit = uint64 (config .Cgroups .Resources .MemorySwap )
253
- }
254
-
255
- // Get CPU info
256
- spec .HasCpu = true
257
- spec .Cpu .Limit = 1024
258
- if config .Cgroups .Resources .CpuShares != 0 {
259
- spec .Cpu .Limit = uint64 (config .Cgroups .Resources .CpuShares )
260
- }
261
- spec .Cpu .Mask = utils .FixCpuMask (config .Cgroups .Resources .CpusetCpus , mi .NumCores )
262
- }
263
-
264
- spec .HasDiskIo = true
265
-
266
- return spec
267
- }
268
-
269
223
func (self * dockerContainerHandler ) needNet () bool {
270
224
if ! self .ignoreMetrics .Has (container .NetworkUsageMetrics ) {
271
225
return ! strings .HasPrefix (self .networkMode , "container:" )
@@ -274,28 +228,8 @@ func (self *dockerContainerHandler) needNet() bool {
274
228
}
275
229
276
230
func (self * dockerContainerHandler ) GetSpec () (info.ContainerSpec , error ) {
277
- mi , err := self .machineInfoFactory .GetMachineInfo ()
278
- if err != nil {
279
- return info.ContainerSpec {}, err
280
- }
281
- libcontainerConfig , err := self .readLibcontainerConfig ()
282
- if err != nil {
283
- return info.ContainerSpec {}, err
284
- }
285
-
286
- spec := libcontainerConfigToContainerSpec (libcontainerConfig , mi )
287
- spec .CreationTime = self .creationTime
288
-
289
- if ! self .ignoreMetrics .Has (container .DiskUsageMetrics ) {
290
- spec .HasFilesystem = true
291
- }
292
-
293
- spec .Labels = self .labels
294
- spec .Envs = self .envs
295
- spec .Image = self .image
296
- spec .HasNetwork = self .needNet ()
297
-
298
- return spec , err
231
+ hasFilesystem := ! self .ignoreMetrics .Has (container .DiskUsageMetrics )
232
+ return common .GetSpec (self .cgroupPaths , self .machineInfoFactory , self .needNet (), hasFilesystem )
299
233
}
300
234
301
235
func (self * dockerContainerHandler ) getFsStats (stats * info.ContainerStats ) error {
@@ -399,7 +333,7 @@ func (self *dockerContainerHandler) StopWatchingSubcontainers() error {
399
333
}
400
334
401
335
func (self * dockerContainerHandler ) Exists () bool {
402
- return containerlibcontainer . Exists ( * dockerRootDir , * dockerRunDir , self .id )
336
+ return common . CgroupExists ( self .cgroupPaths )
403
337
}
404
338
405
339
func DockerInfo () (docker.DockerInfo , error ) {
0 commit comments