项目作者: aristocratos

项目描述 :
Internet speed reability tester
高级语言: Shell
项目地址: git://github.com/aristocratos/spdtest.sh.git
创建时间: 2020-01-08T16:25:04Z
项目社区:https://github.com/aristocratos/spdtest.sh

开源协议:Apache License 2.0

下载


spdtest.sh

State: Beta
Version: 0.3.0
Usage: Script with UI for testing internet speed reability
Language: Bash & Python

Description

Internet speeds are tested against random servers from speedtest.net at an timed interval (defined by user).
If slow speed (defined by user) is detected, then runs a number of download and upload test with optional route tests to servers and writes to a logfile.

Screenshots

Main UI with graph on.

Screenshot 1

Features

  • Function for checking current bandwidth usage to block false positives. Can optionally collect bandwidth usage from a router running linux with a ssh server enabled.
  • Scrollable graph showing speeds over time.
  • All output in the UI is also scrollabe with UP, DOWN, PAGE_UP, PAGE_DOWN, HOME, END keys working as you would expect.
  • Option to have the timer reset on any mouse or keyboard activity in XServer.
  • Option to have the timer auto pause when monitor is on and unpause when monitor is off.
  • Unit used can be switched between Mbits and MB/s.
  • Function for splitting log files at a defined size, old log files can also be automatically compressed.

Configurability

Config files stored in “$HOME/.config/spdtest” folder

spdtest.cfg: (auto generated if not found)

  1. net_device="auto" #* Network interface to get current speed from, set to "auto" to get default interface from "ip route" command
  2. unit="megabit" #* Default speed value to use, valid values are "megabit" and "megabyte"
  3. slowspeed="30" #* Download speed in unit defined above that triggers more tests, recommended set to 10%-40% of your max speed
  4. numservers="30" #* How many of the closest servers to get from speedtest.net, used as random pool of servers to test against
  5. slowretry="1" #* When speed is below slowspeed, how many retries of random servers before running full tests
  6. max_err_retry="3" #* Max servers to test if an error is encountered in slowcheck
  7. numslowservers="8" #* How many of the closest servers from list to test if slow speed has been detected, tests all if not set
  8. precheck="true" #* Check current bandwidth usage before slowcheck, blocks if speed is higher then values set below
  9. precheck_samplet="5" #* Time in seconds to sample bandwidth usage, defaults to 5 if not set
  10. precheck_down="50" #* Download speed in unit defined above that blocks slowcheck
  11. precheck_up="50" #* Upload speed in unit defined above that blocks slowcheck
  12. precheck_ssh_host="192.168.1.1" #* If set, precheck will fetch data from /proc/net/dev over SSH, for example from a router running linux
  13. #* remote machine needs to have: "/proc/net/dev" and be able to run commands "ip route" and "grep"
  14. #* copy SSH keys to remote machine if you don't want to be asked for password at start, guide: https://www.ssh.com/ssh/copy-id
  15. precheck_ssh_user="admin" #* Username for ssh connection
  16. precheck_ssh_nd="auto" #* Network interface on remote machine to get speeds from, set to "auto" if unsure
  17. waittime="00:20:00" #* Default wait timer between slowchecks, format: "HH:MM:SS"
  18. slowwait="00:10:00" #* Time between tests when slow speed has been detected, uses wait timer if unset, format: "HH:MM:SS"
  19. idle="false" #* If "true", resets timer if keyboard or mouse activity is detected in XServer
  20. # idletimer="00:30:00" #* If set and idle="true", the script uses this timer until first test, then uses standard wait time,
  21. #* any X Server activity resets back to idletimer, format: "HH:MM:SS"
  22. displaypause="false" #* If "true" automatically pauses timer when display is on, unpauses when off, overrides idle="true" if set, needs xset to work
  23. paused="false" #* If "true", the timer is paused at startup, ignored if displaypause="true"
  24. startuptest="false" #* If "true" and paused="false", tests speed at startup before timer starts
  25. main_menu_start="shown" #* The status of the main menu at start, possible values: "shown", "hidden"
  26. graph_start="shown" #* The status of the speed graph at start, possible values: "shown", "hidden"
  27. loglevel="2" #* 0 : No logging
  28. #* 1 : Log only when slow speed has been detected
  29. #* 2 : Also log slow speed check
  30. #* 3 : Also log server updates
  31. #* 4 : Log all including forced tests
  32. logdir="$HOME/spdtest-logs" #* Logfile save directory
  33. quiet_start="true" #* If "true", don't print serverlist and routelist at startup
  34. maxlogsize="1024" #* Max logsize (in kilobytes) before log is split
  35. logcompress="gzip" #* Command for compressing logs, only log splits beyond the last split is compressed, disabled if not set
  36. # custom_log="" #* Custom logfile (full path), if a custom logfile is set log splitting is disabled
  37. max_buffer="1000" #* Max number of lines to buffer in internal scroll buffer
  38. buffer_save="true" #* Save buffer to disk on exit and restore on start
  39. mtr="true" #* Set "false" to disable route testing with mtr, automatically set to "false" if mtr is not found in PATH
  40. mtr_internal="true" #* Use hosts from full test with speeds below $slowspeed in mtr test
  41. mtr_internal_ok="false" #* Use hosts from full test with speeds above $slowspeed in mtr test
  42. # mtr_internal_max="" #* Set max hosts to add from full test
  43. mtr_external="false" #* Use hosts from route.cfg, see route.cfg.sample for formatting
  44. mtrpings="25" #* Number of pings sent with mtr
  45. testonly="false" #* If "true", never enter UI mode, always run full tests and quit
  46. testnum="1" #* Number of times to loop full tests in testonly mode
  47. ookla_speedtest="speedtest" #* Command or full path to official speedtest client
  48. trace_errors="true" #* In event of error print line number of offending command to $HOME/.config/spdtest/errors

route.cfg.sample: (rename to route.cfg to use additional hosts in route test)

  1. #? List of routes to test with mtr
  2. #? Format:
  3. #? routelista+=("host")
  4. #? routelistdesc["host"]=("Name")
  5. #? routelistport["host"]=("port") 'Set port to "auto" if you don't want to set a custom port!'
  6. routelista+=("google.com")
  7. routelistdesc["google.com"]="Google"
  8. routelistport["google.com"]="auto"
  9. routelista+=("reddit.com")
  10. routelistdesc["reddit.com"]="Reddit"
  11. routelistport["reddit.com"]="auto"
  12. routelista+=("twitch.tv")
  13. routelistdesc["twitch.tv"]="Twitch"
  14. routelistport["twitch.tv"]="auto"
  15. routelista+=("amazon.com")
  16. routelistdesc["amazon.com"]="Amazon"
  17. routelistport["amazon.com"]="auto"

Command line options: (to be updated)

  1. USAGE: ./spdtest.sh [OPTIONS]
  2. OPTIONS:
  3. -t, --test [num] Runs full test 1 or <x> number of times and quits
  4. -u, --unit megabit/megabyte Which unit to show speed in, [default: megabit]
  5. -s, --slow-speed speed Defines what speed in defined unit that will trigger more tests
  6. -n, --num-servers num How many of the closest servers to get from speedtest.net
  7. -i, --interface name Network interface being used [default: auto]
  8. -l, --loglevel 0-3 0 No logging
  9. 1 Log only when slow speed has been detected
  10. 2 Also log slow speed check and server update
  11. 3 Log all including forced tests
  12. -lf, --log-file file Full path to custom logfile, no log rotation is done on custom logfiles
  13. -p, --paused Sets timer to paused state at startup
  14. -wt, --wait-time HH:MM:SS Time between tests when NO slowdown is detected [default: 00:10:00]
  15. -st, --slow-time HH:MM:SS Time between tests when slowdown has been detected, uses wait timer if unset
  16. -x, --x-reset [HH:MM:SS] Reset timer if keyboard or mouse activity is detected in X Server
  17. If HH:MM:SS is included, the script uses this timer until first test, then uses
  18. standard wait time, any activity resets to idle timer [default: unset]
  19. -d, --display-pause Automatically pauses timer when display is on, unpauses when off
  20. -gs, --gen-server-cfg num Writes <x> number of the closest servers to "server.cfg" and quits
  21. Servers aren't updated automatically at start if "server.cfg" exists
  22. -sc, --server-config file Reads server config from <file> [default: server.cfg]
  23. If used in combination with -gs a new file is created
  24. -h, --help Shows help information
  25. CONFIG:
  26. Note: All config files are stored in: $HOME/.config/spdtest
  27. spdtest.cfg Automatically created with default values if removed
  28. [server.cfg] Stores server id's to use with speedtest, delete to refresh servers on start
  29. [route.cfg] Additional hosts to test with mtr, see route.cfg.sample for formatting
  30. LOG:
  31. Logfile location can be changed in config file
  32. Currently: $HOME/spdtest-logs

Dependencies

bash (v4.4 or later) Script functionality might brake with earlier versions.

Python 3 (v3.7 or later) Needed for speedtest-cli, grc and getIdle.

speedtest Official speedtest client from Ookla, needs to be in path or defined in config.
Note: You will need to run speedtest manually in a terminal to accept license before first use.

jq Needed for json parsing.

Included

speedtest-cli Used to get serverlist, since official speedtest client from Ookla is limited to 10 servers.
Modified and heavily stripped down, based on version 2.1.2. Python code included in the script.

grc For making text output in the UI pretty.
Modified version of grcat. Python code included in the script.

getIdle Get XServer idle time. Python code included in script.

Optionals

mtr Needed if you want to check routes to slow servers.

less Needed if you want option to view logfile from UI.

TODO

  • TODO Fix argument parsing and error messages
  • TODO Change slowtest to multiple servers and compare results
  • TODO fix wrong keypress in inputwait, esc codes etc
  • TODO fix up README.md
  • TODO extern config and save to config?
  • TODO ssh controlmaster, server, client for precheck_speed
  • TODO buffer logview
  • TODO route test menu, choose host to test
  • TODO windows: help, options, route
  • TODO plot speedgraphs overtime in UI
  • TODO stat file
  • Everything else…

LICENSE

Apache License 2.0