Last active
June 2, 2020 15:13
-
-
Save athoune/84ad16fca816ddbb44630cdac863439e to your computer and use it in GitHub Desktop.
display swap and rss in cgroup services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from pathlib import Path | |
def containerd(): | |
for p in Path("/sys/fs/cgroup/memory/system.slice/containerd.service/").iterdir(): | |
if not p.is_dir(): | |
continue | |
print(p.name) | |
with (p / "memory.stat").open("r") as f: | |
for line in f: | |
if not line.startswith("swap "): | |
continue | |
print("\t", line[:-1]) | |
def stat(reader): | |
return {k: int(v) for k, v in ( | |
line[:-1].split(" ", 1) for line in reader) | |
} | |
def services(): | |
for service in Path("/sys/fs/cgroup/memory/system.slice/").glob("*.service"): | |
with (service / "memory.stat").open("r") as f: | |
s = stat(f) | |
print(s["swap"], s["rss"], service.name) | |
services() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment