This repository has been archived on 2023-04-13. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
CloudBot/plugins/bandwidth.py
2015-02-18 22:49:44 +01:00

21 lines
605 B
Python

from util import hook, http, web
from subprocess import check_output, CalledProcessError
from datetime import datetime
@hook.command("bw", autohelp=False)
def bw(inp):
"""bw - list last bandwidth measurement to the outside."""
try:
o = check_output("/bin/chch-bandwidth")
except CalledProcessError as err:
return "chch-bandwidth: returned %s" % (str(err))
os = o.split(",")
upl = int(os[-1])/1024.0/1024.0
dl = int(os[-2])/1024.0/1024.0
ts = os[0]
tsd = datetime.strptime(ts, "%Y%m%d%H%M%S")
return "%s: upl = %f Mbit/s; dl = %f Mbit/s;" % (tsd, upl, dl)