2019-02-15 15:49:55 +00:00
|
|
|
#!/usr/bin/env python3
|
2017-10-02 17:55:35 +03:00
|
|
|
#
|
|
|
|
|
# mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
|
|
|
|
|
# Copyright (C)2013-2017 Philemon <mmgen-py@yandex.com>
|
|
|
|
|
#
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify it under
|
|
|
|
|
# the terms of the GNU General Public License as published by the Free Software
|
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
|
# version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
|
# details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
mmgen-netrate: Bitcoin daemon network rate monitor
|
|
|
|
|
"""
|
2017-08-05 13:54:53 +03:00
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
from mmgen.common import *
|
|
|
|
|
|
2017-10-01 11:30:11 +03:00
|
|
|
opts_data = lambda: {
|
2017-08-05 13:54:53 +03:00
|
|
|
'desc': 'Bitcoin daemon network rate monitor',
|
|
|
|
|
'usage': '[opts]',
|
|
|
|
|
'options': """
|
|
|
|
|
-h, --help Print this help message
|
|
|
|
|
--, --longhelp Print help message for long options (common options)
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd_args = opts.init(opts_data)
|
|
|
|
|
|
|
|
|
|
ERASE_LINE,CUR_UP = '\033[K','\033[1A'
|
2017-10-30 12:44:19 +03:00
|
|
|
c = rpc_init()
|
2017-08-05 13:54:53 +03:00
|
|
|
|
|
|
|
|
def do_loop():
|
|
|
|
|
def get_data():
|
|
|
|
|
d = c.getnettotals()
|
|
|
|
|
return [float(e) for e in (d['totalbytesrecv'],d['totalbytessent'],d['timemillis'])]
|
|
|
|
|
|
|
|
|
|
r,s,t = get_data()
|
|
|
|
|
time.sleep(0.2)
|
|
|
|
|
while True:
|
|
|
|
|
rs,ss,ts = r,s,t
|
|
|
|
|
r,s,t = get_data()
|
|
|
|
|
td = t-ts
|
|
|
|
|
sys.stderr.write('\rrcvd: {:9.2f} kB/s\nsent: {:9.2f} kB/s '.format((r-rs)/td,(s-ss)/td))
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
sys.stderr.write('{}{}{}'.format(ERASE_LINE,CUR_UP,ERASE_LINE))
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
do_loop()
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
sys.stderr.write('\n')
|