Skip to content

Commit

Permalink
Merge pull request #2164 from viberan/master
Browse files Browse the repository at this point in the history
add docker_only_prefix_whitelist flag and fix issue #2129
  • Loading branch information
dashpole authored Feb 19, 2019
2 parents cd92744 + 7bb8b34 commit 1032888
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion cadvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ var whitelistedContainerLabels = flag.String("whitelisted_container_labels", "",

var urlBasePrefix = flag.String("url_base_prefix", "", "prefix path that will be prepended to all paths to support some reverse proxies")

var rawCgroupPrefixWhiteList = flag.String("raw_cgroup_prefix_whitelist", "", "A comma-separated list of cgroup path prefix that needs to be collected even when -docker_only is specified")

var (
// Metrics to be ignored.
// Tcp metrics are ignored by default.
Expand Down Expand Up @@ -145,7 +147,7 @@ func main() {

collectorHttpClient := createCollectorHttpClient(*collectorCert, *collectorKey)

containerManager, err := manager.New(memoryStorage, sysFs, *maxHousekeepingInterval, *allowDynamicHousekeeping, includedMetrics, &collectorHttpClient, []string{"/"})
containerManager, err := manager.New(memoryStorage, sysFs, *maxHousekeepingInterval, *allowDynamicHousekeeping, includedMetrics, &collectorHttpClient, strings.Split(*rawCgroupPrefixWhiteList,","))
if err != nil {
klog.Fatalf("Failed to create a Container Manager: %s", err)
}
Expand Down
15 changes: 9 additions & 6 deletions container/raw/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ func (self *rawFactory) NewContainerHandler(name string, inHostNamespace bool) (
return newRawContainerHandler(name, self.cgroupSubsystems, self.machineInfoFactory, self.fsInfo, self.watcher, rootFs, self.includedMetrics)
}

// The raw factory can handle any container. If --docker_only is set to false, non-docker containers are ignored.
// The raw factory can handle any container. If --docker_only is set to true, non-docker containers are ignored except for "/" and those whitelisted by raw_cgroup_prefix_whitelist flag.
func (self *rawFactory) CanHandleAndAccept(name string) (bool, bool, error) {
accept := name == "/" || !*dockerOnly

if name == "/" {
return true, true, nil
}
if *dockerOnly && self.rawPrefixWhiteList[0] == "" {
return true, false, nil
}
for _, prefix := range self.rawPrefixWhiteList {
if strings.HasPrefix(name, prefix) {
accept = true
break
return true, true, nil
}
}
return true, accept, nil
return true, false, nil
}

func (self *rawFactory) DebugInfo() map[string][]string {
Expand Down

0 comments on commit 1032888

Please sign in to comment.