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
|
2021-03-12 18:20:44 +00:00
|
|
|
# Copyright (C)2013-2021 The MMGen Project <mmgen@tuta.io>
|
2017-10-02 17:55:35 +03:00
|
|
|
#
|
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
|
|
"""
|
2021-03-12 18:20:44 +00:00
|
|
|
mmnode-netrate: Bitcoin daemon network rate monitor
|
2017-10-02 17:55:35 +03:00
|
|
|
"""
|
2017-08-05 13:54:53 +03:00
|
|
|
|
2025-10-04 09:56:55 +00:00
|
|
|
import sys, time
|
2023-04-04 16:00:29 +00:00
|
|
|
|
|
|
|
|
from mmgen.cfg import Config
|
|
|
|
|
from mmgen.util import async_run
|
2017-08-05 13:54:53 +03:00
|
|
|
|
2019-05-29 12:06:08 +00:00
|
|
|
opts_data = {
|
|
|
|
|
'text': {
|
|
|
|
|
'desc': 'Bitcoin daemon network rate monitor',
|
|
|
|
|
'usage': '[opts]',
|
|
|
|
|
'options': """
|
2017-08-05 13:54:53 +03:00
|
|
|
-h, --help Print this help message
|
|
|
|
|
--, --longhelp Print help message for long options (common options)
|
2025-10-04 09:56:55 +00:00
|
|
|
"""}
|
2017-08-05 13:54:53 +03:00
|
|
|
}
|
|
|
|
|
|
2023-04-04 16:00:29 +00:00
|
|
|
cfg = Config(opts_data=opts_data)
|
2017-08-05 13:54:53 +03:00
|
|
|
|
2025-10-04 09:56:55 +00:00
|
|
|
ERASE_LINE, CUR_UP = '\033[K', '\033[1A'
|
2017-08-05 13:54:53 +03:00
|
|
|
|
2020-05-12 16:40:08 +00:00
|
|
|
async def main():
|
2020-06-01 20:29:58 +00:00
|
|
|
|
2020-05-12 16:40:08 +00:00
|
|
|
from mmgen.rpc import rpc_init
|
2025-10-04 09:56:55 +00:00
|
|
|
c = await rpc_init(cfg, ignore_wallet=True)
|
2020-05-12 16:40:08 +00:00
|
|
|
|
|
|
|
|
async def get_data():
|
|
|
|
|
d = await c.call('getnettotals')
|
2025-10-04 09:56:55 +00:00
|
|
|
return [float(e) for e in (d['totalbytesrecv'], d['totalbytessent'], d['timemillis'])]
|
2017-08-05 13:54:53 +03:00
|
|
|
|
2025-10-04 09:56:55 +00:00
|
|
|
rs, ss, ts = (None, None, None)
|
2017-08-05 13:54:53 +03:00
|
|
|
while True:
|
2025-10-04 09:56:55 +00:00
|
|
|
r, s, t = await get_data()
|
2020-05-12 16:40:08 +00:00
|
|
|
|
|
|
|
|
if rs is not None:
|
|
|
|
|
sys.stderr.write(
|
|
|
|
|
'\rrcvd: {:9.2f} kB/s\nsent: {:9.2f} kB/s '.format(
|
|
|
|
|
(r-rs)/(t-ts),
|
2025-10-04 09:56:55 +00:00
|
|
|
(s-ss)/(t-ts)))
|
2020-05-12 16:40:08 +00:00
|
|
|
|
2017-08-05 13:54:53 +03:00
|
|
|
time.sleep(2)
|
2020-05-12 16:40:08 +00:00
|
|
|
|
|
|
|
|
if rs is not None:
|
2025-10-04 09:56:55 +00:00
|
|
|
sys.stderr.write('{}{}{}'.format(ERASE_LINE, CUR_UP, ERASE_LINE))
|
2020-05-12 16:40:08 +00:00
|
|
|
|
2025-10-04 09:56:55 +00:00
|
|
|
rs, ss, ts = (r, s, t)
|
2017-08-05 13:54:53 +03:00
|
|
|
|
|
|
|
|
try:
|
2025-10-01 15:26:42 +00:00
|
|
|
async_run(cfg, main)
|
2017-08-05 13:54:53 +03:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
sys.stderr.write('\n')
|