Nagios Speedtest plugin

*** UPDATE ***

All the code for this plugin is now hosted over on GitHub: https://github.com/jonwitts/nagios-speedtest.

*** UPDATE ***

Version 1.2 is now available. You can now specify a Speedtest Mini Server to check against. If you are updating to this version you will need to change your Nagios check commands to include the new “l” argument to define if you are checking against an internal (Mini) or external Speedtest server. Download links both here and on Nagios Exchange are updated to the new version.

*** EDIT ***

Version 1.1 of the script is now released with some improvements suggested by Sigurdur Bjarnason via email. The download link below is updated to point to the new version and the version on Nagios plugins is updated too.

The main change is that you now need to define the location of the speedtest binary in the script before it will run, and you must now also pass the Server ID of the Speedtest server you want to check against in the command. See the usage of the script for more details.

*** ***

This week we were trying to download some files from work and the download speed was slow to say the least. I then made a SSH connection to my PC at home and downloaded them from there and then copied the files back to work with WinSCP; all of this quicker than downloading directly at work!

This lead us to wondering if there was a Linux utility for testing Internet upload and download speed on the CLI. A quick Google search later lead us to: https://github.com/sivel/speedtest-cli . The developers of the small Python utility describe it quite simply as: “Command line interface for testing internet bandwidth using speedtest.net”

I installed this on both my home PC and our Nagios server at work and begun to play around with what we could do with it. I have long thought that it would be nice to be able to monitor and graph the upload and download speed of our connection so that we can spot trends as to when we are getting Internet slow-downs. To date I had not found a Nagios plugin which would do what I wanted, but this little CLI tool could quite easily be manipulated to my own ends!

So with the python script running I began to play around with writing a BASH script which would take the output from the python script and format it in a way which Nagios and Nagiosgraph would be happy with. A lot of tweaking and adjusting later I am pleased to say that you can download it here. As always it comes with no warranty at all, and I am open to suggestions for improvements too!

Once the script is in your Nagios libexec folder and you have installed speedtest-cli and tested that the script works for you; you will need to configure a command definition and a service definition in Nagios. Mine are shown below as examples:

define command{
        command_name    check_internet_speed
        command_line    $USER1$/check_speedtest-cli.sh -w $ARG1$ -c $ARG2$ -W $ARG3$ -C $ARG4$ -l $ARG5$ -s $ARG6$ -p
}

define service{
        use                             web-check-service,graphed-service
        host_name                       localhost
        service_description             Internet Speed Test Check
        check_command                   check_internet_speed!10!7!15!10!1426
        normal_check_interval           30
        retry_check_interval            5
        }

Obviously you should adjust these as per your install. The other point worth noting is that the results of the speedtest-cli can sometimes take some time to return. If you find that your nagios check is timing out it may be worth trying to increase your “service_check_timeout” value in your main nagios.cfg to 120 to allow time for this script to run; but test yourself and adjust accordingly.

I hope that this is of some use to you!

You can also find this over on the Nagios Exchange site here: http://exchange.nagios.org/directory/Plugins/Network-Connections%2C-Stats-and-Bandwidth/check_speedtest-2Dcli/details

Jon

113 thoughts on “Nagios Speedtest plugin

  1. Hi man
    As you may know, speedtest-cli is no more functionnal as Ookla decommissionned the server lists urls (now use json formatted url https://speedtest.net/api/js/servers)
    Also, I guess speedtest-cli or other projects like speedtest-go are no longer necessary as we can use genuine “speedtest” cli package from Ookla : https://speedtest.net/apps/cli

    I totally reworked your original Nagios plugin “check_speedtest-cli.sh” and made it new as “check_speedtest.sh”, so the plugin can work with Ookla “speedtest” output. You can check it on my github page https://github.com/TheITguy21/check_speedtest.sh

    I’m a total newbie on github, I have no idea how to properly release new code based on an existing outdated project without failing credits and license from original project. Can you please check the github page and my “check_speedtest.sh” script code and let me know if everything is ok to you with disclaimer/comments ?

    Sorry if I did it wrong, it was not intended, I’m ready to fix it according to your feedback 😉

    Let me know
    Cheers

Leave a Reply

Your email address will not be published. Required fields are marked *