resource_container_linux new getAllPidsByCgroup

This commit is contained in:
Lang Martin 2019-07-09 18:47:51 -04:00
parent 2e981a812e
commit 18597c4917
1 changed files with 37 additions and 0 deletions

View File

@ -4,6 +4,8 @@ import (
"os"
"sync"
"github.com/hashicorp/nomad/client/stats"
"github.com/opencontainers/runc/libcontainer/cgroups"
cgroupConfig "github.com/opencontainers/runc/libcontainer/configs"
)
@ -23,3 +25,38 @@ func (rc *resourceContainerContext) executorCleanup() error {
}
return nil
}
func (rc *resourceContainerContext) isEmpty() bool {
return rc.groups == nil
}
func (rc *resourceContainerContext) getAllPidsByCgroup() (map[int]*nomadPid, error) {
nPids := map[int]*nomadPid{}
if rc.groups == nil {
return nPids, nil
}
var path string
if p, ok := rc.groups.Paths["freezer"]; ok {
path = p
} else {
path = rc.groups.Path
}
pids, err := cgroups.GetAllPids(path)
if err != nil {
return nPids, err
}
for _, pid := range pids {
nPids[pid] = &nomadPid{
pid: pid,
cpuStatsTotal: stats.NewCpuStats(),
cpuStatsUser: stats.NewCpuStats(),
cpuStatsSys: stats.NewCpuStats(),
}
}
return nPids, nil
}