Skip to content

Instantly share code, notes, and snippets.

Last active Jun 2, 2020
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():
with (p / "memory.stat").open("r") as f:
for line in f:
if not line.startswith("swap "):
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"],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment