| 2218 | |
| 2219 | |
| 2220 | Try<ResourceStatistics> DockerContainerizerProcess::cgroupsStatistics( |
| 2221 | pid_t pid) const |
| 2222 | { |
| 2223 | #ifndef __linux__ |
| 2224 | return Error("Does not support cgroups on non-linux platform"); |
| 2225 | #else |
| 2226 | static const Result<string> cpuacctHierarchy = cgroups::hierarchy("cpuacct"); |
| 2227 | static const Result<string> memHierarchy = cgroups::hierarchy("memory"); |
| 2228 | |
| 2229 | // NOTE: Normally, a Docker container should be in its own cgroup. |
| 2230 | // However, a zombie process (exited but not reaped) will be |
| 2231 | // temporarily moved into the system root cgroup. We add some |
| 2232 | // defensive check here to make sure we are not reporting statistics |
| 2233 | // for the root cgroup. See MESOS-8480 for details. |
| 2234 | const string systemRootCgroup = stringify(os::PATH_SEPARATOR); |
| 2235 | |
| 2236 | if (cpuacctHierarchy.isError()) { |
| 2237 | return Error( |
| 2238 | "Failed to determine the cgroup 'cpuacct' subsystem hierarchy: " + |
| 2239 | cpuacctHierarchy.error()); |
| 2240 | } |
| 2241 | |
| 2242 | if (memHierarchy.isError()) { |
| 2243 | return Error( |
| 2244 | "Failed to determine the cgroup 'memory' subsystem hierarchy: " + |
| 2245 | memHierarchy.error()); |
| 2246 | } |
| 2247 | |
| 2248 | const Result<string> cpuacctCgroup = cgroups::cpuacct::cgroup(pid); |
| 2249 | if (cpuacctCgroup.isError()) { |
| 2250 | return Error( |
| 2251 | "Failed to determine cgroup for the 'cpuacct' subsystem: " + |
| 2252 | cpuacctCgroup.error()); |
| 2253 | } else if (cpuacctCgroup.isNone()) { |
| 2254 | return Error("Unable to find 'cpuacct' cgroup subsystem"); |
| 2255 | } else if (cpuacctCgroup.get() == systemRootCgroup) { |
| 2256 | return Error( |
| 2257 | "Process '" + stringify(pid) + |
| 2258 | "' should not be in the system root cgroup (being destroyed?)"); |
| 2259 | } |
| 2260 | |
| 2261 | const Result<string> memCgroup = cgroups::memory::cgroup(pid); |
| 2262 | if (memCgroup.isError()) { |
| 2263 | return Error( |
| 2264 | "Failed to determine cgroup for the 'memory' subsystem: " + |
| 2265 | memCgroup.error()); |
| 2266 | } else if (memCgroup.isNone()) { |
| 2267 | return Error("Unable to find 'memory' cgroup subsystem"); |
| 2268 | } else if (memCgroup.get() == systemRootCgroup) { |
| 2269 | return Error( |
| 2270 | "Process '" + stringify(pid) + |
| 2271 | "' should not be in the system root cgroup (being destroyed?)"); |
| 2272 | } |
| 2273 | |
| 2274 | const Try<cgroups::cpuacct::Stats> cpuAcctStat = |
| 2275 | cgroups::cpuacct::stat(cpuacctHierarchy.get(), cpuacctCgroup.get()); |
| 2276 | |
| 2277 | if (cpuAcctStat.isError()) { |
nothing calls this directly
no test coverage detected