Skip to content

Latest commit

 

History

History
269 lines (241 loc) · 10.2 KB

readme.org

File metadata and controls

269 lines (241 loc) · 10.2 KB

Speed Demon

Runs internet connection speed checks for a specified interval and logs the results.

Project aims

Allow a user to

  1. Be confident that future functionality will not break current functionality (is fully tested)
  2. Access great documentation
  3. Easily extend the current project
  4. Run a single terminal command to setup the project
  5. Easily alter the default settings via command line options
  6. Automate the speed testing to run at their preferred interval
  7. Save results
  8. Log cron errors
  9. Log whether the speed test was done via a wireless or wired connection
  10. Log time at which each speedtest was conducted
  11. Log time when cron errors occurred

Dependencies

Ruby gem

The below dependencies can be installed to the system ruby (if using a rapsberrypi) or can be installed via a gem manager such as rbenv. Speed Demon will just run a CLI call to instatiate the gem. So ensure that the global ruby version is the version that has the below gems installed!

whenever

This gem handles cron tasks beautifully, has a great test suite, is well documented/maintained and is used by a large number of people so I decided to integrate with it to draw on its functionality.

Linux packages

The below linux packages are used

speedtest-cli

Used to gather data on ping, download speed and upload speed

ip

Used to determine whether the speed test was done via a wireless or wired connection. This package comes preinstalled as standard with many linux distributions

Hardware requirements

At least 1Ghz processor and 2Gb of RAM. (Overclocked Raspberrypi 1B) These figures are hand wavy. However, on a non overclocked Raspberrypi 1 B, any CPU speed below 1GHz detrimentally affects that calculated speed. i.e the calculated speed will be less than that actual speed.

Installation

(Will be pushed to ruby gems shortly <2018-11-10 Sat 07:46>)

Simple

  1. git clone this project to a desired location
  2. install the dependencies listed
  3. simply install to current directory with all defaults
    speed_demon --setup-default
        

This will setup the project with the following defaults:

  • output directory at ~/.local/share/speed_demon
  • config directory at ~/.config/speed_demon
  • cron log directory at ~/.speed_demon
  • speedtest check frequency of 15 minutes

Custom

  1. git clone this project to a desired location
  2. install the dependencies listed
  3. simply install to current directory with all defaults
    speed_demon --custom-output /tmp/speed_demon/output --custom-log /tmp/speed_demon/log --custom-frequency '2.minutes'
        

This will setup the project with the following defaults:

  • output directory at /tmp/speed_demon/output
  • config directory at ~/.config/speed_demon (this cannot be changed)
  • cron log directory at /tmp/speed_demon/log
  • speedtest check frequency of 2 minutes

Note: The most updated custom options are in the code & tests

Frequency

Can be called with the following:

  • ‘2.minutes’ (not recommended to run any more frequent that this)
  • ‘hour’
  • ‘3.hours’
  • ‘1.day’
  • ‘1.day, at: [‘4:30 am’, ‘6:00 pm’]’ (TODO: test, but i think this already works)

For more options check out the whenever gem

CLI Options

speed_demon [options]
Short flag–options [INPUT]Result
-h–helpprints all options to CLI
-s–setup-defaultsetup using defaults
-o–custom-output [PATH]specify custom path for output directory
-l–custom-log [PATH]specify custom path for log directory
-f–custom-frequency [TIME]specify custom speed measuring frequency
-m–measure-speedmanually run a speed check

Output file format

For now all output is in CSV format. The output is intended to be used for graphing and analysis.

Speed_demon TODO/DONE Tasks

0.0.1 - Launch

Remove the custom hash level from cli.rb & setup.rb & all tests!

eg. options[:custom][:base_Dir] in setup.rb should be options[:base_dir]

Write test to ensure –frequency flag writes frequency to cron file

Write test that will fail if the following line is placed before the call of OptionParser.new

@custom[:base_dir] = ARGV[0] || Dir.pwd # If it exists, ARGV remains is user’s chosen setup path

Replace SpeedTest::Setup.new with SpeedTest::Setup.execute

setup = SpeedTest::Setup.new(SpeedTest::CLI.parse(ARGV)) setup.directories setup.cron_create

With: SpeedTest::Setup.execute(custom: SpeedTest::CLI.parse(ARGV)) This will create all the directories, create the cron task and start the cron task

Redefine default config path to be XDG-spec compliant i.e ~/.config/myapp

Redefine default output (data) directory to be ~/.local/share/myapp

Check where the default location for the .config directory is

~/.config is correct

Redefine default log directory to be ~/.myapp/log

Call SpeedTest::Setup.execute with defaults if proviso is met

proviso: only do this if a –setup-default flag is passed or a custom flag is passed

If CLI is called with executable name only display help screen

Call SpeedTest::Measure only if a –measure flag is passed

Test-if a configuration file called directories has been created

Write SpeedTest::Setup directories out to a configuration file

Call speedtest_init -m and get the gem to measure and log speed out to the configured file

Test-whenever –update-crontab is called by SpeedTest::Setup.execute(cli)

Test-when cron errors it saves error with timestamp to cron.log

When a cron task error occurs add a timestamp to the cron log

Disallow speed measurement if speedtest is not setup (configuration file is not found)

Rename gem from speed_test & speedtest_init to speed_demon

  • [X] SpeedTest to SpeedDemon
  • [X] speed_test to speed_demon
  • [X] speedtest_init to speed_demon
  • [X] Rename file names
  • [X] Ensure speedtest –simple linux command line call is not renamed

Add rubocop to gemspec development dependencies

Fix rubocop errors

Add a license

Choose an open source license | Choose a License Just use MIT

Add test that errors if user has not installed speedtest-cli

Update documentation

Change tests so that they all run in the /tmp directory and dont step on existing speed demon data!

Publish the gem!!!

0.1.0 - Handle errors nicely

Add a code of conduct

Contributor Covenant: A Code of Conduct for Open Source Projects

Write error handling for the case where a user forgets to install whenever gem

Silence stdout messages during test runs

Add a logger class to handle all stdout & stderr logging

  • [ ] Write error handling for the case a user does not have access to linux package ‘ip’ & ‘ip link’ does not provide required output

Test if all whenever frequency options work (they should)

1.day, at: [‘4:30 am’, ‘6:00 pm’] :sunday, at: ‘12pm’ ‘0 0 27-31 * *’ :day, at: ‘12:20am’, roles: [:app]

0.2.0 - Add ability to save data to external postgreSQL database

Extend the class SaveData so that it can send data to an external postgreSQL database

Update documentation to use rdoc

0.3.0 - Add ability to remove speed_demon and another option to completely remove

Create a CLI option to completely remove all speed demon directories, locally saved data and configuration files