1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | # graph operations-per-second from a set of storage servers. |
---|
4 | |
---|
5 | # the OPERATION value should come from the following list: |
---|
6 | # allocate: allocate_buckets, first step to upload an immutable file |
---|
7 | # write: write data to an immutable share |
---|
8 | # close: finish writing to an immutable share |
---|
9 | # cancel: abandon a partial immutable share |
---|
10 | # get: get_buckets, first step to download an immutable file |
---|
11 | # read: read data from an immutable share |
---|
12 | # writev: slot_testv_and_readv_and_writev, modify/create a directory |
---|
13 | # readv: read a directory (or mutable file) |
---|
14 | |
---|
15 | # To use this, create a symlink from |
---|
16 | # /etc/munin/plugins/tahoe_server_operations_OPERATION to this script. For |
---|
17 | # example: |
---|
18 | |
---|
19 | # ln -s /usr/share/munin/plugins/tahoe_server_operations_ \ |
---|
20 | # /etc/munin/plugins/tahoe_server_operations_allocate |
---|
21 | |
---|
22 | # Also, you will need to put a list of node statistics URLs in the plugin's |
---|
23 | # environment, by adding a stanza like the following to a file in |
---|
24 | # /etc/munin/plugin-conf.d/, such as /etc/munin/plugin-conf.d/tahoe_operations: |
---|
25 | # |
---|
26 | # [tahoe_server_operations*] |
---|
27 | # env.url_storage1 http://localhost:9011/statistics?t=json |
---|
28 | # env.url_storage2 http://localhost:9012/statistics?t=json |
---|
29 | # env.url_storage3 http://localhost:9013/statistics?t=json |
---|
30 | # env.url_storage4 http://localhost:9014/statistics?t=json |
---|
31 | |
---|
32 | # of course, these URLs must match the webports you have configured into the |
---|
33 | # storage nodes. |
---|
34 | |
---|
35 | |
---|
36 | import os, sys |
---|
37 | import urllib |
---|
38 | import json |
---|
39 | |
---|
40 | node_urls = [] |
---|
41 | for k,v in os.environ.items(): |
---|
42 | if k.startswith("url_"): |
---|
43 | nodename = k[len("url_"):] |
---|
44 | node_urls.append( (nodename, v) ) |
---|
45 | node_urls.sort() |
---|
46 | |
---|
47 | my_name = os.path.basename(sys.argv[0]) |
---|
48 | PREFIX = "tahoe_server_operations_" |
---|
49 | assert my_name.startswith(PREFIX) |
---|
50 | operation = my_name[len(PREFIX):] |
---|
51 | |
---|
52 | configinfo = \ |
---|
53 | """graph_title Tahoe Server '%(operation)s' Operations |
---|
54 | graph_vlabel ops per second |
---|
55 | graph_category tahoe |
---|
56 | graph_info This graph shows how many '%(operation)s' operations take place on the storage server |
---|
57 | """ % {'operation': operation} |
---|
58 | |
---|
59 | for nodename, url in node_urls: |
---|
60 | configinfo += "%s.label %s\n" % (nodename, nodename) |
---|
61 | configinfo += "%s.type DERIVE\n" % (nodename,) |
---|
62 | configinfo += "%s.min 0\n" % (nodename,) |
---|
63 | configinfo += "%s.draw LINE2\n" % (nodename,) |
---|
64 | |
---|
65 | |
---|
66 | if len(sys.argv) > 1: |
---|
67 | if sys.argv[1] == "config": |
---|
68 | print(configinfo.rstrip()) |
---|
69 | sys.exit(0) |
---|
70 | |
---|
71 | for nodename, url in node_urls: |
---|
72 | data = json.loads(urllib.urlopen(url).read()) |
---|
73 | key = "storage_server.%s" % operation |
---|
74 | value = data["counters"][key] |
---|
75 | print("%s.value %s" % (nodename, value)) |
---|
76 | |
---|