Skip to content

Instantly share code, notes, and snippets.

@athoune
Last active June 2, 2020 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athoune/84ad16fca816ddbb44630cdac863439e to your computer and use it in GitHub Desktop.
Save athoune/84ad16fca816ddbb44630cdac863439e to your computer and use it in GitHub Desktop.
display swap and rss in cgroup services
#!/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