| 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 | |
|---|
| 22 | import os, sys |
|---|
| 23 | import commands |
|---|
| 24 | |
|---|
| 25 | nodedirs = [] |
|---|
| 26 | for k,v in os.environ.items(): |
|---|
| 27 | if k.startswith("basedir_"): |
|---|
| 28 | nodename = k[len("basedir_"):] |
|---|
| 29 | nodedirs.append( (nodename, v) ) |
|---|
| 30 | nodedirs.sort() |
|---|
| 31 | |
|---|
| 32 | seriesname = "storage" |
|---|
| 33 | |
|---|
| 34 | configinfo = \ |
|---|
| 35 | """graph_title Allmydata Tahoe Shareholder Space |
|---|
| 36 | graph_vlabel bytes |
|---|
| 37 | graph_category tahoe |
|---|
| 38 | graph_info This graph shows the space consumed by this node's StorageServer |
|---|
| 39 | """ |
|---|
| 40 | |
|---|
| 41 | for nodename, basedir in nodedirs: |
|---|
| 42 | configinfo += "%s.label %s\n" % (nodename, nodename) |
|---|
| 43 | configinfo += "%s.draw LINE2\n" % (nodename,) |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | if len(sys.argv) > 1: |
|---|
| 47 | if sys.argv[1] == "config": |
|---|
| 48 | print(configinfo.rstrip()) |
|---|
| 49 | sys.exit(0) |
|---|
| 50 | |
|---|
| 51 | for nodename, basedir in nodedirs: |
|---|
| 52 | cmd = "du --bytes --summarize %s" % os.path.join(basedir, "storage") |
|---|
| 53 | rc,out = commands.getstatusoutput(cmd) |
|---|
| 54 | if rc != 0: |
|---|
| 55 | sys.exit(rc) |
|---|
| 56 | bytes, extra = out.split() |
|---|
| 57 | usage = int(bytes) |
|---|
| 58 | print("%s.value %d" % (nodename, usage)) |
|---|
| 59 | |
|---|