Skip to content

Instantly share code, notes, and snippets.

@athoune
Last active Jun 2, 2020
Embed
What would you like to do?
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