|
| 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 | +} |
0 commit comments