3 # This munin plugin isolates processes by looking for the 'pid' file created
4 # by 'allmydata start', then extracts the amount of memory they consume (both
5 # VmSize and VmRSS) from /proc
11 os.environ["nodememory_warner1"] = "run/warner1"
12 os.environ["nodememory_warner2"] = "run/warner2"
15 for k,v in os.environ.items():
16 if k.startswith("nodememory_"):
17 nodename = k[len("nodememory_"):]
18 nodedirs.append((nodename, v))
19 nodedirs.sort(lambda a,b: cmp(a[0],b[0]))
23 for node,nodedir in nodedirs:
24 pidfile = os.path.join(nodedir, "twistd.pid")
25 if os.path.exists(pidfile):
26 pid = int(open(pidfile,"r").read())
29 fields = ["VmSize", "VmRSS"]
33 if sys.argv[1] == "config":
35 """graph_title Memory Consumed by Nodes
38 graph_info This graph shows the memory used by specific processes
40 for nodename,nodedir in nodedirs:
42 configinfo += "%s_%s.label %s used by %s\n" % (nodename, f,
47 configinfo += "%s_%s.draw %s\n" % (nodename, f, linetype)
49 configinfo += "%s_%s.graph no\n" % (nodename, f)
55 for node,pid in pids.items():
57 statusfile = "/proc/%s/status" % pid
58 if not os.path.exists(statusfile):
60 for line in open(statusfile,"r").readlines():
62 if line.startswith(f + ":"):
63 m = re.search(r'(\d+)', line)
64 stats[f] = int(m.group(1))
65 nodestats[node] = stats
67 for node,stats in nodestats.items():
68 for f,value in stats.items():
69 # TODO: not sure if /proc/%d/status means 1000 or 1024 when it says
71 print "%s_%s.value %d" % (node, f, 1024*value)