added per-miner graphs
authorForrest Voight <forrest@forre.st>
Sun, 22 Jan 2012 07:44:49 +0000 (02:44 -0500)
committerForrest Voight <forrest@forre.st>
Sun, 22 Jan 2012 08:39:51 +0000 (03:39 -0500)
p2pool/graphs.py
p2pool/main.py

index 388c34f..ab71d3c 100644 (file)
@@ -1,3 +1,4 @@
+import hashlib
 import os
 import tempfile
 
@@ -54,13 +55,26 @@ else:
                 'DEF:A=%s.poolrate:poolrate:AVERAGE' % (self.grapher.path,), 'LINE1:A#0000FF:Total (last month)',
                 'DEF:B=%s.localrate:localrate:AVERAGE' % (self.grapher.path,), 'LINE1:B#0000FF:Local (last month)']))
             
-            self.putChild('localrate_day', Renderer(lambda: ['--lower-limit', '0', '--start', '-1d',
+            def get_lines():
+                res = []
+                for i, x in enumerate(os.listdir(os.path.dirname(self.grapher.path))):
+                    x2 = os.path.join(os.path.dirname(self.grapher.path), x)
+                    if not x2.startswith(self.grapher.path + '.') or not x2.endswith('.localminer'):
+                        continue
+                    name = x2[len(self.grapher.path + '.'):-len('.localminer')].decode('hex')
+                    res.extend([
+                        'DEF:%i=%s:localminer:AVERAGE' % (i, x2),
+                        'AREA:%i#%s:%s%s' % (i, hashlib.sha256(name).hexdigest()[:6], name, ':STACK' if i != 0 else ''),
+                    ])
+                return res
+            
+            self.putChild('localrate_day', Renderer(lambda: ['--lower-limit', '0', '--start', '-1d'] + get_lines() + [
                 'DEF:A=%s.localrate:localrate:AVERAGE' % (self.grapher.path,), 'LINE1:A#0000FF:Total (last day)',
                 'DEF:B=%s.localdeadrate:localdeadrate:AVERAGE' % (self.grapher.path,), 'LINE1:B#FF0000:Dead (last day)']))
-            self.putChild('localrate_week', Renderer(lambda: ['--lower-limit', '0', '--start', '-1w',
+            self.putChild('localrate_week', Renderer(lambda: ['--lower-limit', '0', '--start', '-1w'] + get_lines() + [
                 'DEF:A=%s.localrate:localrate:AVERAGE' % (self.grapher.path,), 'LINE1:A#0000FF:Total (last week)',
                 'DEF:B=%s.localdeadrate:localdeadrate:AVERAGE' % (self.grapher.path,), 'LINE1:B#FF0000:Dead (last week)']))
-            self.putChild('localrate_month', Renderer(lambda: ['--lower-limit', '0', '--start', '-1m',
+            self.putChild('localrate_month', Renderer(lambda: ['--lower-limit', '0', '--start', '-1m'] + get_lines() + [
                 'DEF:A=%s.localrate:localrate:AVERAGE' % (self.grapher.path,), 'LINE1:A#0000FF:Total (last month)',
                 'DEF:B=%s.localdeadrate:localdeadrate:AVERAGE' % (self.grapher.path,), 'LINE1:B#FF0000:Dead (last month)']))
         
@@ -109,5 +123,24 @@ else:
             rrdtool.update(self.path + '.localrate', '-t', 'localrate', 'N:%f' % (hashes,))
             rrdtool.update(self.path + '.localdeadrate', '-t', 'localdeadrate', 'N:%f' % (hashes if dead else 0,))
         
+        def add_localminer_point(self, name, hashes, dead):
+            path = self.path + '.' + name.encode('hex')
+            if not os.path.exists(path + '.localminer'):
+                rrdtool.create(path + '.localminer', '--step', '300', '--no-overwrite',
+                    'DS:localminer:ABSOLUTE:43200:U:U',
+                    'RRA:AVERAGE:0.5:1:288', # last day
+                    'RRA:AVERAGE:0.5:7:288', # last week
+                    'RRA:AVERAGE:0.5:30:288', # last month
+                )
+            if not os.path.exists(path + '.localdeadminer'):
+                rrdtool.create(path + '.localdeadminer', '--step', '300', '--no-overwrite',
+                    'DS:localdeadminer:ABSOLUTE:43200:U:U',
+                    'RRA:AVERAGE:0.5:1:288', # last day
+                    'RRA:AVERAGE:0.5:7:288', # last week
+                    'RRA:AVERAGE:0.5:30:288', # last month
+                )
+            rrdtool.update(path + '.localminer', '-t', 'localminer', 'N:%f' % (hashes,))
+            rrdtool.update(path + '.localdeadminer', '-t', 'localdeadminer', 'N:%f' % (hashes if dead else 0,))
+        
         def get_resource(self):
             return Resource(self)
index 59d0393..502a427 100644 (file)
@@ -364,6 +364,15 @@ def main(args, net, datadir_path):
         
         print 'Listening for workers on port %i...' % (args.worker_port,)
         
+        if os.path.exists(os.path.join(datadir_path, 'vip_pass')):
+            with open(os.path.join(datadir_path, 'vip_pass'), 'rb') as f:
+                vip_pass = f.read().strip('\r\n')
+        else:
+            vip_pass = '%016x' % (random.randrange(2**64),)
+            with open(os.path.join(datadir_path, 'vip_pass'), 'wb') as f:
+                f.write(vip_pass)
+        print "    Worker password: ", vip_pass, " (only required for generating graphs)"
+        
         # setup worker logic
         
         removed_unstales_var = variable.Variable((0, 0, 0))
@@ -543,6 +552,8 @@ def main(args, net, datadir_path):
                 
                 if pow_hash <= target:
                     reactor.callLater(1, grapher.add_localrate_point, bitcoin_data.target_to_average_attempts(target), not on_time)
+                    if request.getPassword() == vip_pass:
+                        reactor.callLater(1, grapher.add_localminer_point, request.getUser(), bitcoin_data.target_to_average_attempts(target), not on_time)
                 
                 if pow_hash > target:
                     print 'Worker submitted share with hash > target:'