| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | # This is a munin plugin to track the number of files that each node's |
|---|
| 4 | # StorageServer is holding on behalf of other nodes. Each file that has been |
|---|
| 5 | # uploaded to the mesh (and has shares present on this node) will be counted |
|---|
| 6 | # here. When there are <= 100 nodes in the mesh, this count will equal the |
|---|
| 7 | # total number of files that are active in the entire mesh. When there are |
|---|
| 8 | # 200 nodes present in the mesh, it will represent about half of the total |
|---|
| 9 | # number. |
|---|
| 10 | |
|---|
| 11 | # Copy this plugin into /etc/munun/plugins/tahoe-files and then put |
|---|
| 12 | # the following in your /etc/munin/plugin-conf.d/foo file to let it know |
|---|
| 13 | # where to find the basedirectory for each node: |
|---|
| 14 | # |
|---|
| 15 | # [tahoe-files] |
|---|
| 16 | # env.basedir_NODE1 /path/to/node1 |
|---|
| 17 | # env.basedir_NODE2 /path/to/node2 |
|---|
| 18 | # env.basedir_NODE3 /path/to/node3 |
|---|
| 19 | # |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | import os, sys |
|---|
| 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 | configinfo = \ |
|---|
| 32 | """graph_title Allmydata Tahoe Filecount |
|---|
| 33 | graph_vlabel files |
|---|
| 34 | graph_category tahoe |
|---|
| 35 | graph_info This graph shows the number of files hosted by this node's StorageServer |
|---|
| 36 | """ |
|---|
| 37 | |
|---|
| 38 | for nodename, basedir in nodedirs: |
|---|
| 39 | configinfo += "%s.label %s\n" % (nodename, nodename) |
|---|
| 40 | configinfo += "%s.draw LINE2\n" % (nodename,) |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | if len(sys.argv) > 1: |
|---|
| 44 | if sys.argv[1] == "config": |
|---|
| 45 | print(configinfo.rstrip()) |
|---|
| 46 | sys.exit(0) |
|---|
| 47 | |
|---|
| 48 | for nodename, basedir in nodedirs: |
|---|
| 49 | shares = 0 |
|---|
| 50 | root = os.path.join(basedir, "storage", "shares") |
|---|
| 51 | |
|---|
| 52 | for dirpath, dirnames, filenames in os.walk(root, topdown=True): |
|---|
| 53 | if dirpath == root and "incoming" in dirnames: |
|---|
| 54 | dirnames.remove("incoming") |
|---|
| 55 | shares += len(filenames) |
|---|
| 56 | print("%s.value %d" % (nodename, shares)) |
|---|
| 57 | |
|---|