source: trunk/misc/operations_helpers/munin/tahoe_nodememory

Last change on this file was b856238, checked in by Alexandre Detiste <alexandre.detiste@…>, at 2024-02-15T15:53:34Z

remove old Python2 future statements

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#!/usr/bin/env python
2
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
6
7
8import os, sys, re
9
10# for testing
11# os.environ["nodememory_warner1"] = "run/warner1"
12# os.environ["nodememory_warner2"] = "run/warner2"
13
14nodedirs = []
15for k,v in os.environ.items():
16    if k.startswith("nodememory_"):
17        nodename = k[len("nodememory_"):]
18        nodedirs.append((nodename, v))
19nodedirs.sort(lambda a,b: cmp(a[0],b[0]))
20
21pids = {}
22
23for 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())
27        pids[node] = pid
28
29fields = ["VmSize", "VmRSS"]
30
31
32if len(sys.argv) > 1:
33    if sys.argv[1] == "config":
34        configinfo = \
35        """graph_title Memory Consumed by Nodes
36graph_vlabel bytes
37graph_category Tahoe
38graph_info This graph shows the memory used by specific processes
39"""
40        for nodename,nodedir in nodedirs:
41            for f in fields:
42                configinfo += "%s_%s.label %s used by %s\n" % (nodename, f,
43                                                               f, nodename)
44                linetype = "LINE1"
45                if f == "VmSize":
46                    linetype = "LINE2"
47                configinfo += "%s_%s.draw %s\n" % (nodename, f, linetype)
48                if f == "VmData":
49                    configinfo += "%s_%s.graph no\n" % (nodename, f)
50
51        print(configinfo)
52        sys.exit(0)
53
54nodestats = {}
55for node,pid in pids.items():
56    stats = {}
57    statusfile = "/proc/%s/status" % pid
58    if not os.path.exists(statusfile):
59        continue
60    for line in open(statusfile,"r").readlines():
61        for f in fields:
62            if line.startswith(f + ":"):
63                m = re.search(r'(\d+)', line)
64                stats[f] = int(m.group(1))
65    nodestats[node] = stats
66
67for 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
70        # 'kB'
71        print("%s_%s.value %d" % (node, f, 1024*value))
Note: See TracBrowser for help on using the repository browser.