Add 'tools/arvbox/' from commit 'd3d368758db1f4a9fa5b89f77b5ee61d68ef5b72'
[arvados.git] / services / fuse / arvados_fuse / crunchstat.py
1 import sys
2 import time
3
4 class Stat(object):
5     def __init__(self, prefix, interval,
6                  egr_name, ing_name,
7                  egr_func, ing_func):
8         self.prefix = prefix
9         self.interval = interval
10         self.egr_name = egr_name
11         self.ing_name = ing_name
12         self.egress = egr_func
13         self.ingress = ing_func
14         self.egr_prev = self.egress()
15         self.ing_prev = self.ingress()
16
17     def update(self):
18         egr = self.egress()
19         ing = self.ingress()
20
21         delta = " -- interval %.4f seconds %d %s %d %s" % (self.interval,
22                                                            egr - self.egr_prev,
23                                                            self.egr_name,
24                                                            ing - self.ing_prev,
25                                                            self.ing_name)
26
27         sys.stderr.write("crunchstat: %s %d %s %d %s%s\n" % (self.prefix,
28                                                              egr,
29                                                              self.egr_name,
30                                                              ing,
31                                                              self.ing_name,
32                                                              delta))
33
34         self.egr_prev = egr
35         self.ing_prev = ing
36
37
38 def statlogger(interval, keep, ops):
39     calls = Stat("keepcalls", interval, "put", "get",
40                  keep.put_counter.get,
41                  keep.get_counter.get)
42     net = Stat("net:keep0", interval, "tx", "rx",
43                keep.upload_counter.get,
44                keep.download_counter.get)
45     cache = Stat("keepcache", interval, "hit", "miss",
46                keep.hits_counter.get,
47                keep.misses_counter.get)
48     fuseops = Stat("fuseops", interval,"write", "read",
49                    ops.write_ops_counter.get,
50                    ops.read_ops_counter.get)
51     blk = Stat("blkio:0:0", interval, "write", "read",
52                ops.write_counter.get,
53                ops.read_counter.get)
54
55     while True:
56         time.sleep(interval)
57         calls.update()
58         net.update()
59         cache.update()
60         fuseops.update()
61         blk.update()
62
63