Added support for RRDtool file updating.

This commit is contained in:
nonatomicretain 2014-08-08 10:35:55 +10:00
parent 795bc51da4
commit 443862e974
2 changed files with 12 additions and 3 deletions

View File

@ -72,12 +72,12 @@ Usage
$ speedtest-cli -h $ speedtest-cli -h
usage: speedtest-cli [-h] [--bytes] [--share] [--simple] [--list] usage: speedtest-cli [-h] [--bytes] [--share] [--simple] [--list]
[--server SERVER] [--mini MINI] [--source SOURCE] [--server SERVER] [--mini MINI] [--source SOURCE]
[--version] [--version] [--rrdfile RRDFILE]
Command line interface for testing internet bandwidth using speedtest.net. Command line interface for testing internet bandwidth using speedtest.net.
-------------------------------------------------------------------------- --------------------------------------------------------------------------
https://github.com/sivel/speedtest-cli https://github.com/sivel/speedtest-cli
optional arguments: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
--bytes Display values in bytes instead of bits. Does not affect --bytes Display values in bytes instead of bits. Does not affect
@ -90,6 +90,7 @@ Usage
--mini MINI URL of the Speedtest Mini server --mini MINI URL of the Speedtest Mini server
--source SOURCE Source IP address to bind to --source SOURCE Source IP address to bind to
--version Show the version number and exit --version Show the version number and exit
--rrdfile Output results to an RRD file, three columns, ping (ms), download (bits per second), and upload (bits per second)
Inconsistency Inconsistency
------------- -------------

View File

@ -486,6 +486,7 @@ def speedtest():
parser.add_argument('--source', help='Source IP address to bind to') parser.add_argument('--source', help='Source IP address to bind to')
parser.add_argument('--version', action='store_true', parser.add_argument('--version', action='store_true',
help='Show the version number and exit') help='Show the version number and exit')
parser.add_argument('--rrdfile', help='Output results to an RRD file, three columns, ping (ms), download (bits per second), and upload (bits per second)')
options = parser.parse_args() options = parser.parse_args()
if isinstance(options, tuple): if isinstance(options, tuple):
@ -634,6 +635,13 @@ def speedtest():
print_() print_()
print_('Upload: %0.2f M%s/s' % print_('Upload: %0.2f M%s/s' %
((ulspeed / 1000 / 1000) * args.units[1], args.units[0])) ((ulspeed / 1000 / 1000) * args.units[1], args.units[0]))
if args.rrdfile:
import rrdtool
rrdping = int(round(best['latency'], 0))
rrdDLSpeedBits = int(round(dlspeed * 8, 0))
rrdULSpeedBits = int(round(ulspeed * 8, 0))
ret = rrdtool.update(args.rrdfile,'N:' + `rrdping` + ':' + `rrdDLSpeedBits` + ':' + `rrdULSpeedBits`);
if args.share and args.mini: if args.share and args.mini:
print_('Cannot generate a speedtest.net share results image while ' print_('Cannot generate a speedtest.net share results image while '