]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - misc/operations_helpers/munin/tahoe_storagespace
setup: organize misc/ scripts and tools and remove obsolete ones
[tahoe-lafs/tahoe-lafs.git] / misc / operations_helpers / munin / tahoe_storagespace
1 #!/usr/bin/env python
2
3 # This is a munin plugin to track the amount of disk space each node's
4 # StorageServer is consuming on behalf of other nodes. This is where the
5 # shares are kept. If there are N nodes present in the mesh, the total space
6 # consumed by the entire mesh will be about N times the space reported by
7 # this plugin.
8
9 # Copy this plugin into /etc/munun/plugins/tahoe_storagespace and then put
10 # the following in your /etc/munin/plugin-conf.d/foo file to let it know
11 # where to find the basedirectory for each node:
12 #
13 #  [tahoe_storagespace]
14 #  env.basedir_NODE1 /path/to/node1
15 #  env.basedir_NODE2 /path/to/node2
16 #  env.basedir_NODE3 /path/to/node3
17 #
18 # Allmydata-tahoe must be installed on the system where this plugin is used,
19 # since it imports a utility module from allmydata.utils .
20
21 import os, sys
22 import commands
23
24 nodedirs = []
25 for k,v in os.environ.items():
26     if k.startswith("basedir_"):
27         nodename = k[len("basedir_"):]
28         nodedirs.append( (nodename, v) )
29 nodedirs.sort()
30
31 seriesname = "storage"
32
33 configinfo = \
34 """graph_title Allmydata Tahoe Shareholder Space
35 graph_vlabel bytes
36 graph_category tahoe
37 graph_info This graph shows the space consumed by this node's StorageServer
38 """
39
40 for nodename, basedir in nodedirs:
41     configinfo += "%s.label %s\n" % (nodename, nodename)
42     configinfo += "%s.draw LINE2\n" % (nodename,)
43
44
45 if len(sys.argv) > 1:
46     if sys.argv[1] == "config":
47         print configinfo.rstrip()
48         sys.exit(0)
49
50 for nodename, basedir in nodedirs:
51     cmd = "du --bytes --summarize %s" % os.path.join(basedir, "storage")
52     rc,out = commands.getstatusoutput(cmd)
53     if rc != 0:
54         sys.exit(rc)
55     bytes, extra = out.split()
56     usage = int(bytes)
57     print "%s.value %d" % (nodename, usage)
58