Skip to content

Commit eb74b01

Browse files
committed
Merge pull request #1235 from derekwaynecarr/systemd_ignore_mount
on systemd, we should ignore .mount cgroups
2 parents 64f8c8a + d01934a commit eb74b01

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

container/systemd/factory.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2016 Google Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package systemd
16+
17+
import (
18+
"fmt"
19+
"strings"
20+
21+
"github.com/google/cadvisor/container"
22+
"github.com/google/cadvisor/fs"
23+
info "github.com/google/cadvisor/info/v1"
24+
25+
"github.com/golang/glog"
26+
)
27+
28+
type systemdFactory struct{}
29+
30+
func (f *systemdFactory) String() string {
31+
return "systemd"
32+
}
33+
34+
func (f *systemdFactory) NewContainerHandler(name string, inHostNamespace bool) (container.ContainerHandler, error) {
35+
return nil, fmt.Errorf("Not yet supported")
36+
}
37+
38+
func (f *systemdFactory) CanHandleAndAccept(name string) (bool, bool, error) {
39+
// on systemd using devicemapper each mount into the container has an associated cgroup that we ignore.
40+
// for details on .mount units: http://man7.org/linux/man-pages/man5/systemd.mount.5.html
41+
if strings.HasSuffix(name, ".mount") {
42+
return true, false, nil
43+
}
44+
return false, false, fmt.Errorf("%s not handled by systemd handler", name)
45+
}
46+
47+
func (f *systemdFactory) DebugInfo() map[string][]string {
48+
return map[string][]string{}
49+
}
50+
51+
// Register registers the systemd container factory.
52+
func Register(machineInfoFactory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics container.MetricSet) error {
53+
glog.Infof("Registering systemd factory")
54+
factory := &systemdFactory{}
55+
container.RegisterContainerHandlerFactory(factory)
56+
return nil
57+
}

manager/manager.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/google/cadvisor/container/docker"
3232
"github.com/google/cadvisor/container/raw"
3333
"github.com/google/cadvisor/container/rkt"
34+
"github.com/google/cadvisor/container/systemd"
3435
"github.com/google/cadvisor/events"
3536
"github.com/google/cadvisor/fs"
3637
info "github.com/google/cadvisor/info/v1"
@@ -228,6 +229,11 @@ func (self *manager) Start() error {
228229
glog.Errorf("Registration of the rkt container factory failed: %v", err)
229230
}
230231

232+
err = systemd.Register(self, self.fsInfo, self.ignoreMetrics)
233+
if err != nil {
234+
glog.Errorf("Registration of the systemd container factory failed: %v", err)
235+
}
236+
231237
err = raw.Register(self, self.fsInfo, self.ignoreMetrics)
232238
if err != nil {
233239
glog.Errorf("Registration of the raw container factory failed: %v", err)

0 commit comments

Comments
 (0)