|
# -*- coding: utf-8 -*- |
|
import os |
|
import requests |
|
import rrdtool |
|
import time |
|
import datetime |
|
import json |
|
|
|
def parse(): |
|
url = 'http://wafflepool.com/tmp_api?address=<YOUR_BTC_ADDRESS>' |
|
res = requests.get(url) |
|
data = res.json() |
|
return dict(hash=int(data['hash_rate'])/1000./1000., |
|
paid=data['balances']['sent'], |
|
converted=data['balances']['confirmed'], |
|
unexchanged=data['balances']['unconverted']) |
|
|
|
def create_rrd(): |
|
if os.path.exists('wafflepool.rrd'): |
|
return |
|
rrdtool.create('wafflepool.rrd', |
|
'--step', '60', |
|
['DS:hashrate:GAUGE:600:0:U', |
|
'DS:converted:GAUGE:600:0:U', |
|
'DS:paid:GAUGE:600:0:U', |
|
'DS:unexchanged:GAUGE:600:0:U', |
|
'DS:unpaid:GAUGE:600:0:U'], |
|
'RRA:AVERAGE:0.5:1:600', |
|
'RRA:AVERAGE:0.5:6:700', |
|
'RRA:AVERAGE:0.5:24:775', |
|
'RRA:AVERAGE:0.5:288:797', |
|
'RRA:LAST:0.5:1:600', |
|
'RRA:LAST:0.5:6:700', |
|
'RRA:LAST:0.5:24:775', |
|
'RRA:LAST:0.5:288:797') |
|
|
|
def update_rrd(data): |
|
unpaid = float(data['converted']) + float(data['unexchanged']) |
|
fields = (str(x) for x in ('N', data['hash'], data['converted'], |
|
data['paid'], data['unexchanged'], unpaid)) |
|
rrdtool.update('wafflepool.rrd', str(':'.join(fields))) |
|
|
|
def create_graph(): |
|
now = str(datetime.datetime.now()).split('.')[0] |
|
for x in ['-6h', '-1d', '-1w', '-1m']: |
|
rrdtool.graph('hashrate%s.png' % x, |
|
'--end', 'now', |
|
'--start', x, |
|
'--vertical-label', 'Hash Rate (MH/s)', |
|
'--title', 'Hash Rate', |
|
'--lower-limit', '0', |
|
'--width', '720', |
|
'--height', '180', |
|
'--watermark', now, |
|
'DEF:hr=wafflepool.rrd:hashrate:AVERAGE', |
|
'DEF:hr30m=wafflepool.rrd:hashrate:AVERAGE:step=1800', |
|
'DEF:hr1h=wafflepool.rrd:hashrate:AVERAGE:step=3600', |
|
'DEF:hr6h=wafflepool.rrd:hashrate:AVERAGE:step=21600', |
|
'AREA:hr#3FD212:Hash Rate', |
|
'LINE2:hr30m#FF9900:Hash Rate (30m)', |
|
'LINE2:hr1h#DC3912:Hash Rate (1h)', |
|
'LINE2:hr6h#3366CC:Hash Rate (6h)', |
|
'COMMENT:\\n', |
|
'GPRINT:hr:MIN:MIN\: %4.2lf MH/s', |
|
'COMMENT: ', |
|
'GPRINT:hr:AVERAGE:AVG\: %4.2lf MH/s', |
|
'COMMENT: ', |
|
'GPRINT:hr:MAX:MAX\: %4.2lf MH/s\\r') |
|
rrdtool.graph('exchanges%s.png' % x, |
|
'--end', 'now', |
|
'--start', x, |
|
'--vertical-label', 'mBTC', |
|
'--title', 'Approx Balances', |
|
'--lower-limit', '0', |
|
'--width', '720', |
|
'--height', '180', |
|
'--watermark', now, |
|
'DEF:converted=wafflepool.rrd:converted:LAST', |
|
'CDEF:mconverted=converted,1000,*', |
|
'DEF:unexchanged=wafflepool.rrd:unexchanged:AVERAGE', |
|
'CDEF:munexchanged=unexchanged,1000,*', |
|
'DEF:last_unexchanged=wafflepool.rrd:unexchanged:LAST', |
|
'CDEF:unpaid=converted,unexchanged,+', |
|
'CDEF:last_unpaid=converted,last_unexchanged,+', |
|
'CDEF:munpaid=unpaid,1000,*', |
|
'AREA:munpaid#3FD212:Total', |
|
'AREA:munexchanged#FF9900:Unexchanged', |
|
'LINE2:mconverted#DC3912:Converted', |
|
'COMMENT:\\n', |
|
'GPRINT:converted:LAST:CURRENT CONVERTED\: %0.8lf BTC\\r', |
|
'COMMENT:\\n', |
|
'GPRINT:last_unexchanged:LAST:CURRENT UNEXCHANGED\: %0.8lf BTC\\r', |
|
'COMMENT:\\n', |
|
'GPRINT:last_unpaid:LAST:CURRENT TOTAL\: %0.8lf BTC\\r') |
|
rrdtool.graph('payout%s.png' % x, |
|
'--end', 'now', |
|
'--start', x, |
|
'--vertical-label', 'mBTC', |
|
'--title', 'Payout Balances', |
|
#'--lower-limit', '0', |
|
'--width', '720', |
|
'--height', '180', |
|
'--watermark', now, |
|
'DEF:paid=wafflepool.rrd:paid:LAST', |
|
'DEF:converted=wafflepool.rrd:converted:LAST', |
|
'DEF:unexchanged=wafflepool.rrd:unexchanged:AVERAGE', |
|
'DEF:last_unexchanged=wafflepool.rrd:unexchanged:LAST', |
|
'CDEF:unpaid=converted,unexchanged,+', |
|
'CDEF:last_unpaid=converted,last_unexchanged,+', |
|
'CDEF:mpaid=paid,1000,*', |
|
'CDEF:total_balances=paid,unpaid,+', |
|
'CDEF:last_total_balances=paid,last_unpaid,+', |
|
'CDEF:total_converted=paid,converted,+', |
|
'CDEF:mtotal_balances=total_balances,1000,*', |
|
'CDEF:mtotal_converted=total_converted,1000,*', |
|
'AREA:mtotal_balances#3FD212:Unexchanged', |
|
'AREA:mtotal_converted#DC3912:Exchanged', |
|
'AREA:mpaid#3366CC:Payout', |
|
'COMMENT:\\n', |
|
'GPRINT:last_unpaid:LAST:CURRENT UNPAID\: %0.8lf BTC\\r', |
|
'COMMENT:\\n', |
|
'GPRINT:paid:LAST:CURRENT PAID\: %0.8lf BTC\\r', |
|
'COMMENT:\\n', |
|
'GPRINT:last_total_balances:LAST:CURRENT APPROX TOTAL\: %0.8lf BTC\\r') |
|
|
|
if __name__ == '__main__': |
|
data = parse() |
|
create_rrd() |
|
update_rrd(data) |
|
create_graph() |