Merge pull request #2600 from dqminh/raw-container-process-stat

Allow raw container to retrieve process stats
This commit is contained in:
David Ashpole 2020-06-25 16:19:30 -07:00 committed by GitHub
commit 6f30891d89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -118,9 +118,7 @@ func (h *Handler) GetStats() (*info.ContainerStats, error) {
}
// If we know the pid then get network stats from /proc/<pid>/net/dev
if h.pid == 0 {
return stats, nil
}
if h.pid > 0 {
if h.includedMetrics.Has(container.NetworkUsageMetrics) {
netStats, err := networkStatsFromProc(h.rootFs, h.pid)
if err != nil {
@ -168,6 +166,10 @@ func (h *Handler) GetStats() (*info.ContainerStats, error) {
stats.Network.Udp6 = u6
}
}
}
// some process metrics are per container ( number of processes, number of
// file descriptors etc.) and not required a proper container's
// root PID (systemd services don't have the root PID atm)
if h.includedMetrics.Has(container.ProcessMetrics) {
paths := h.cgroupManager.GetPaths()
path, ok := paths["cpu"]
@ -298,13 +300,15 @@ func processStatsFromProcs(rootFs string, cgroupPath string, rootPid int) (info.
}
}
}
ulimits := processRootProcUlimits(rootFs, rootPid)
processStats := info.ProcessStats{
ProcessCount: uint64(len(pids)),
FdCount: fdCount,
SocketCount: socketCount,
Ulimits: ulimits,
}
if rootPid > 0 {
processStats.Ulimits = processRootProcUlimits(rootFs, rootPid)
}
return processStats, nil