removed old graphs
authorForrest Voight <forrest.voight@gmail.com>
Mon, 26 Mar 2012 12:33:54 +0000 (08:33 -0400)
committerForrest Voight <forrest@forre.st>
Thu, 5 Apr 2012 19:03:40 +0000 (15:03 -0400)
p2pool/graphs.py [deleted file]
p2pool/web.py

diff --git a/p2pool/graphs.py b/p2pool/graphs.py
deleted file mode 100644 (file)
index ba28896..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-import hashlib
-import os
-import tempfile
-
-from twisted.web import resource
-
-try:
-    import rrdtool
-except ImportError:
-    class Resource(resource.Resource):
-        def __init__(self):
-            resource.Resource.__init__(self)
-            
-            self.putChild('', self)
-        
-        def render_GET(self, request):
-            if not request.path.endswith('/'):
-                request.redirect(request.path + '/')
-                return ''
-            request.setHeader('Content-Type', 'text/html')
-            return '<html><head><title>P2Pool Graphs</title></head><body><p>Deprecated. Go to <a href="/static">/static</a>!</p></body></html>'
-    
-    class Grapher(object):
-        def __init__(self, *args): pass
-        def get_resource(self): return Resource()
-        def __getattr__(self, name): return lambda *args, **kwargs: None
-else:
-    class Renderer(resource.Resource):
-        def __init__(self, arg_func):
-            self.arg_func = arg_func
-        
-        def render_GET(self, request):
-            handle, filename = tempfile.mkstemp()
-            os.close(handle)
-            
-            rrdtool.graph(filename, '--imgformat', 'PNG', *self.arg_func())
-            
-            request.setHeader('Content-Type', 'image/png')
-            request.write(open(filename, 'rb').read())
-            os.remove(filename)
-    
-    class Resource(resource.Resource):
-        def __init__(self, grapher):
-            resource.Resource.__init__(self)
-            self.grapher = grapher
-            
-            self.putChild('', self)
-            
-            self.putChild('poolrate_day', Renderer(lambda: ['--lower-limit', '0', '-M', '-E', '--start', '-1d',
-                'DEF:A=%s.poolrate:poolrate:AVERAGE' % (self.grapher.path,), 'LINE1:A#0000FF:Total (last day)',
-                'DEF:C=%s.stalerate:stalerate:AVERAGE' % (self.grapher.path,), 'LINE1:C#FF0000:Total stale (last day)',
-                'DEF:B=%s.localrate:localrate:AVERAGE' % (self.grapher.path,), 'LINE1:B#0000FF:Local (last day)']))
-            self.putChild('poolrate_week', Renderer(lambda: ['--lower-limit', '0', '-M', '-E', '--start', '-1w',
-                'DEF:A=%s.poolrate:poolrate:AVERAGE' % (self.grapher.path,), 'LINE1:A#0000FF:Total (last week)',
-                'DEF:C=%s.stalerate:stalerate:AVERAGE' % (self.grapher.path,), 'LINE1:C#FF0000:Total stale (last week)',
-                'DEF:B=%s.localrate:localrate:AVERAGE' % (self.grapher.path,), 'LINE1:B#0000FF:Local (last week)']))
-            self.putChild('poolrate_month', Renderer(lambda: ['--lower-limit', '0', '-M', '-E', '--start', '-1m',
-                'DEF:A=%s.poolrate:poolrate:AVERAGE' % (self.grapher.path,), 'LINE1:A#0000FF:Total (last month)',
-                'DEF:C=%s.stalerate:stalerate:AVERAGE' % (self.grapher.path,), 'LINE1:C#FF0000:Total stale (last month)',
-                'DEF:B=%s.localrate:localrate:AVERAGE' % (self.grapher.path,), 'LINE1:B#0000FF:Local (last month)']))
-            
-            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', '-M', '-E', '--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', '-M', '-E', '--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', '-M', '-E', '--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)']))
-        
-        def render_GET(self, request):
-            if not request.path.endswith('/'):
-                request.redirect(request.path + '/')
-                return ''
-            request.setHeader('Content-Type', 'text/html')
-            return '''<html><head><title>P2Pool Graphs</title></head><body><h1>P2Pool Graphs</h1>
-                <p>Deprecated. Go to <a href="/static">/static</a>!</p>
-                <h2>Pool hash rate:</h2>
-                <p><img style="display:inline" src="poolrate_day"/> <img style="display:inline" src="poolrate_week"/> <img style="display:inline" src="poolrate_month"/></p>
-                <h2>Local hash rate:</h2>
-                <p><img style="display:inline" src="localrate_day"/> <img style="display:inline" src="localrate_week"/> <img style="display:inline" src="localrate_month"/></p>
-            </body></html>'''
-    
-    class Grapher(object):
-        def __init__(self, path):
-            self.path = path
-            
-            if not os.path.exists(self.path + '.poolrate'):
-                rrdtool.create(self.path + '.poolrate', '--step', '300',
-                    'DS:poolrate:GAUGE:600: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(self.path + '.stalerate'):
-                rrdtool.create(self.path + '.stalerate', '--step', '300',
-                    'DS:stalerate:GAUGE:600: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(self.path + '.localrate'):
-                rrdtool.create(self.path + '.localrate', '--step', '300',
-                    'DS:localrate: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(self.path + '.localdeadrate'):
-                rrdtool.create(self.path + '.localdeadrate', '--step', '300',
-                    'DS:localdeadrate: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
-                )
-        
-        def add_poolrate_point(self, poolrate, stalerate):
-            rrdtool.update(self.path + '.poolrate', '-t', 'poolrate', 'N:%f' % (poolrate,))
-            rrdtool.update(self.path + '.stalerate', '-t', 'stalerate', 'N:%f' % (stalerate,))
-        
-        def add_localrate_point(self, hashes, dead):
-            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',
-                    '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',
-                    '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 7b4bad2..d87119e 100644 (file)
@@ -6,12 +6,12 @@ import os
 import sys
 import time
 
-from twisted.internet import reactor, task
+from twisted.internet import task
 from twisted.python import log
 from twisted.web import resource, static
 
 from bitcoin import data as bitcoin_data
-from . import data as p2pool_data, graphs
+from . import data as p2pool_data
 from util import graph, math
 
 def _atomic_read(filename):
@@ -299,21 +299,6 @@ def get_web_root(tracker, current_work, current_work2, get_current_txouts, datad
             return self
     new_root.putChild('explorer', Explorer())
     
-    grapher = graphs.Grapher(os.path.join(datadir_path, 'rrd'))
-    web_root.putChild('graphs', grapher.get_resource())
-    def add_point():
-        if tracker.get_height(current_work.value['best_share_hash']) < 720:
-            return
-        nonstalerate = p2pool_data.get_pool_attempts_per_second(tracker, current_work.value['best_share_hash'], 720)
-        poolrate = nonstalerate / (1 - p2pool_data.get_average_stale_prop(tracker, current_work.value['best_share_hash'], 720))
-        grapher.add_poolrate_point(poolrate, poolrate - nonstalerate)
-    task.LoopingCall(add_point).start(100)
-    @pseudoshare_received.watch
-    def _(work, dead, user, had_vip_pass):
-        reactor.callLater(1, grapher.add_localrate_point, work, dead)
-        if user is not None and had_vip_pass:
-            reactor.callLater(1, grapher.add_localminer_point, user, work, dead)
-    
     hd_path = os.path.join(datadir_path, 'graph_db')
     hd_data = _atomic_read(hd_path)
     hd_obj = {}