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

105 thoughts on “Nagios Speedtest plugin

  1. Hi Jon,
    Great job creating this plugin.
    In the U.S. there’s frequently a wide difference between download and upload speeds. For instance, according to ATT, my provider, my download DSL speed is “up to 12 Mbps” but my upload speed is “up to 0.94 Mbps”. I get an error when I try to use decimal Mbps settings. I assume that if I were to modify the upload values by multiplying them by 100 somewhere in the script I would get accurate monitoring of both my DL and UL speeds. Any suggestions?

    1. Hi Andrew,

      I will have a look at the script and see if I can adjust it to handle warning and critical values less than 1. I have an updated version which I need to post, so I will see if I can include this in it to.

      Out of interest; what is the error you get?

      Jon

    2. Hi Andrew,

      I have just been updating this script to version 1.1 (will upload it shortly) and tested out using decimal points for my upload critical and warning levels. It worked for me without any errors.

      The check I was using on the command line was this:

      “./check_speedtest-cli.sh -w 45 -c 40 -W 2.5 -C 0.5 -p -V”

      and it output this:

      “Download Warning Level = 45
      Download Critical Level = 40
      Upload Warning Level = 2.5
      Upload Critical Level = 0.5
      count = 9
      Ping: 23.286 ms
      Download: 67.51 Mbit/s
      Upload: 7.21 Mbit/s
      Ping = 23.286
      Download = 67.51
      Upload = 7.21
      Everything within bounds!
      PerfData requested!
      OK – Ping = 23.286 ms Download = 67.51 Mbit/s Upload = 7.21 Mbit/s|’download’=67.51;45;40 ‘upload’=7.21;2.5;0.5”

      Can you provide me with some more detail to the error you are getting?

      Thanks,
      Jon

  2. on my debian ,
    have
    : whereis speedtest

    speedtest: /usr/local/bin/speedtest

    not working on my , I have added on line 163

    STb=”/usr/local/bin”

    but still not working

    any help

    1. @clatramp

      From your screen grab it appears as if you are not passing the -s option. This is a required option too. If you run: “speedtest –list | less” you can scroll through and find your nearest server and then pass the integer code for that server to the -s option.

      You should be able to run the command on the cli and get some output before even trying to set up a service definition…

      Jon

  3. thanks now is working 🙂

    thanks a lot ,
    I would like to set up a graph like you ,
    any suggestions please ?

    or just write down the 2 services that you are using .

    thanks again

  4. “lovely graphs” mmm

    I have all the time a huge different speedtest result everytime I run the command , with the same machine e same server.

    did you have the same problem ?

    ./check_speedtest-cli.sh -w 45 -c 40 -W 2.5 -C 0.5 -p -V -s 2789
    Download Warning Level = 45
    Download Critical Level = 40
    Upload Warning Level = 2.5
    Upload Critical Level = 0.5
    count = 9
    Ping: 36.229 ms
    Download: 82.63 Mbits/s
    Upload: 55.81 Mbits/s
    Ping = 36.229
    Download = 82.63
    Upload = 55.81
    Everything within bounds!
    PerfData requested!
    OK – Ping = 36.229 ms Download = 82.63 Mbits/s Upload = 55.81 Mbits/s|’download’=82.63;45;40 ‘upload’=55.81;2.5;0.5

    ./check_speedtest-cli.sh -w 45 -c 40 -W 2.5 -C 0.5 -p -V -s 2789
    Download Warning Level = 45
    Download Critical Level = 40
    Upload Warning Level = 2.5
    Upload Critical Level = 0.5
    count = 9
    Ping: 19.722 ms
    Download: 95.33 Mbits/s
    Upload: 23.16 Mbits/s
    Ping = 19.722
    Download = 95.33
    Upload = 23.16
    Everything within bounds!
    PerfData requested!
    OK – Ping = 19.722 ms Download = 95.33 Mbits/s Upload = 23.16 Mbits/s|’download’=95.33;45;40 ‘upload’=23.16;2.5;0.5

    ./check_speedtest-cli.sh -w 45 -c 40 -W 2.5 -C 0.5 -p -V -s 2789
    Download Warning Level = 45
    Download Critical Level = 40
    Upload Warning Level = 2.5
    Upload Critical Level = 0.5
    count = 9
    Ping: 90.614 ms
    Download: 61.47 Mbits/s
    Upload: 21.62 Mbits/s
    Ping = 90.614
    Download = 61.47
    Upload = 21.62
    Everything within bounds!
    PerfData requested!
    OK – Ping = 90.614 ms Download = 61.47 Mbits/s Upload = 21.62 Mbits/s|’download’=61.47;45;40 ‘upload’=21.62;2.5;0.5

    1. My results do vary each time it is run; but not as much as yours appear to.

      Of course what other Internet activity is happening on your network at the time the test runs will play a part in what is reported as the available bandwidth. Over a week this is how my results graph out: Weekly Speedtest Results

      I would say that the check is working as expected from those results unless you were expecting vastly different figures?

      Jon

  5. This is a great article, I got it working with NRPE and I followed the nagiosgraphs instructions but I can’t get the bandwidth to graph.

    1. Hi Luiz,

      I have never tried to run this script over NRPE; I have only ever run on the nagios server itself; however I can’t see why that would be a problem for nagiosgraph.

      Have you got nagiosgraph successfully graphing other services?

      Jon

  6. Yes I was able to graph a few other service through NRPE but not your plugin. I will keep digging on my server and I will post any updates.

    Thank you

  7. The command was working properly. I did edit your script a little bit so nagiosgraph would graph correctly. On the “perfout” line I changed it to the following:

    perfout=”|download=$download;$DLw;$DLc; upload=$upload;$ULw;$ULc;”

    Thank you for you help.

  8. Help me! pliss

    (No output on stdout) stderr: /usr/local/nagios/libexec/check_speedtest-cli.sh: 131: /usr/local/nagios/libexec/check_speedtest-cli.sh: Syntax error: “(” unexpecte

      1. Hi Jon,

        same problem here:
        ./check_speedtest-cli.sh: 136: ./check_speedtest-cli.sh: Syntax error: “(” unexpected

        If i execute the script under root it all works fine. But with the nagios user i get the same error. bc is installed under /usr/bin/bc.

        Thanks,
        Matthias

        1. Hi Matthias,

          I would suspect that there is some issue with your nagios user running bc if all works as expected with your root user. Can you run bc as your nagios user without entering the full path?

          Jon

  9. Basically I followed the instrcutions and downloaded the github link and put your script and the speedtest.cli in the same dir (/usr/local/nagios/libexec
    -rwxr–r– 1 nagios root 9525 Oct 21 11:14 check_speedtest-cli.sh
    -rwxr-xr-x 1 nagios root 21791 Oct 21 10:31 speedtest-cli

    edited the script like this:
    STb=/usr/local/nagios/libexec

    Made a command and service as described.
    In the meantime the error changed to:
    “You do not have the expected number of indices in your output from SpeedTest. Is it correctly installed?”

    1. OK.. I used the PIP / Easy download option from the github which puts the script in /usr/local/bin…

      The error message means that speedtest.cli is not returning the expected format of result. What happens when you run the nagios check script n the command line and add the -V option to display debug info?

      If you run that along with your other options the script will output what it is doing at each step… There maybe some more clues in there to help us…

  10. [root@detvee-rhn00 libexec]# /usr/local/nagios/libexec/check_speedtest-cli.sh -w 10 -c 7 -W 15 -C 10 -s 2641 -p -V
    Download Warning Level = 10
    Download Critical Level = 7
    Upload Warning Level = 15
    Upload Critical Level = 10
    /usr/local/nagios/libexec/check_speedtest-cli.sh: line 253: /usr/local/nagios/libexec/speedtest: No such file or directory
    count = 0
    You do not have the expected number of indices in your output from SpeedTest. Is it correctly installed?

    line 253 is:
    command=$($STb/speedtest –server=$SEs –simple)

    I think this is part of the confusion. There’s no such thing as ‘speedtest’ on my system.
    If I run this:
    ./speedtest-cli –simple
    I get some readable output. Ping/download/upload.

    1. That is indeed the problem… When I used the PIP installer on the github I get an executable called speedtest on my Ubuntu system, not speedtest.cli .

      The script is trying to run “speedtest” from /usr/local/nagios/libexec/ not “speedtest.cli” If you cannot run “speedtest –simple” and get an output the script is not going to work!

      I suppose you have two options; hack my script so that it is looking for speedtest.cli or try and download speedtest.cli via the PIP installer and see if you get a speedtest command available to you… If you want to hack my script, I think you should only need to change it on line 253.

  11. Sorry for the late reply, but I got it working.
    Seems like the need for the speedtest was also partly the cause of the check not working… i.e. speed was too low for a short period.

    Thanks for the help.

  12. Hi Jon,
    Thanks for this great script. I’ve got it running on a Raspberry Pi with OpenWRT for half a year now. It does a great job testing the internet-speed at a remote site every 20 mins.

    But now I’d like to measure speed in a LAN. I want it to connect a speedtest-mini that is running in the server-room. However, there’s seems to be no way in your script to do a –mini instead the -s .

    Can you help me with that or at least give some hints for a not-so-expienced bash-hacker?

    Thanks,

    Erik

    1. Erik,

      Glad to hear that you have been making good use of the script. I would be interested to hear more about what you are doing with the Raspberry Pi and OpenWRT!

      You could simply hack the script to make it check via a Mini Server instead of an external one; but I actually think that this would be a really useful addition to the script.

      I am working on including this as an option in version 1.2 of the script, which should not take me too long. Watch this space!

      Jon

  13. Do you know why when i query the server list, it does not return the same server that I get when I access speedtest.net through a browser?

    My ISP is virgin, through the browser I get one of their servers, yet I dont see any Virgin UK servers in the output from –list

    I managed to find the server id for the one I normally get, but the script says its invalid…

    Any help would be greatly appreciated, thanks

  14. Hi, i have installed that check, which is working as i wanted! so grats on this plugin! i only have one question, which i will need help i guess. it display nothing on pnp4nagios as history mark. so im sort of confused here. i am using nagios core 3, with pnp4nagios 0.6.22. in nagios, when i clic on the graph icons, it brings me to the proper place in pnp4 nagios, i have no errors but i have no data. my check command in my service is

    define service{
    use local-service,srv-pnp
    hostgroup_name linux-servers
    service_description Check internet speed
    check_command check_speed
    notifications_enabled 1
    max_check_attempts 1
    check_interval 360
    }

    my command is

    define command{
    command_name check_speed
    command_line /usr/lib64/nagios/plugins/check_speedtest-cli.sh -w 20 -c 15 -W 8 -C 5 -l e -s 4393 -p
    }

    my other pnp4nagios are displaying data, my srv-pnp is

    define service {
    name srv-pnp
    action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
    register 0
    }

    in the lib folder /var/lib/pnp4nagios/mail , of pnp4nagios i see
    -rw-r–r– 1 nagios nagios 12408 Apr 23 22:22 Check_internet_speed.xml
    -rw-r–r– 1 nagios nagios 768224 Apr 23 22:22 Check_internet_speed.rrd

    #rrdtool dump Check_internet_speed.rrd
    show me empty data from the rrd file…

    but the xml show me data. inside pnp4nagios web interface, the graphs are empty. i have not played at all with pnp4nagios yet, i never did a custom thing in there, so i am in the dark.

    could you tell me what i am missing ? or point me somewhere? please!

    thanks and best regards.

    1. Hi Francois,

      Glad you have got it working… I have no experience of PNP4Nagios; I use Nagiosgraph myself. However, a couple of questions:
      1.) Have you got other services to graph yet? i.e. Is it confirmed as installed and working?
      2.) I have seen similar behaviour in Nagiosgraph when check intervals where too far apart. Is there a setting in PNP4Nagios that controls the check interval or freshness of the PerfData?

      Jon

      1. Hi Jon, yes, other graphs are working just perfectly, has been for more than a year! i have currently configured nagios check speed at each 6 hours.

        what i can say is the rrd file contains no data, timestamps are present, but no data. the XML with the same name have data tho. its like if only half is done. as i understand it, the problem is not pnp4nagios. Nagios is the one creating those data i guess. nagios details of the service is showing the following
        ‘download’=25.98;20;15 ‘upload’=10.32;8;5
        so i know that nagios does see the -p option of the check plugins.

        a dump of rrd shows “snippet”

        NaN NaN
        NaN NaN
        NaN NaN
        NaN NaN
        NaN NaN
        NaN NaN
        NaN NaN
        NaN NaN
        NaN NaN
        NaN NaN
        NaN NaN

        and the xml is showing this “snippet”

        OK – Ping = 29.518 ms Download = 25.98 Mbit/s Upload = 10.32 Mbit/s
        0.00
        ‘download’=25.98;20;15 ‘upload’=10.32;8;5
        /tmp/service-perfdata
        0
        OK

        i am still investigating what missing…

  15. what i can tell is that nagios is processing the perfdata, and then pnp4nagios is receiving the data, and he says

    2015-04-24 22:42:49 [14811] [2] Datatype set to ‘SERVICEPERFDATA’
    2015-04-24 22:42:49 [14811] [1] Found Performance Data for mail / Check_internet_speed (‘download’=24.09;20;15 ‘upload’=10.23;8;5)
    2015-04-24 22:42:49 [14811] [2] data2rrd called
    2015-04-24 22:42:49 [14811] [2] RRDs::update /var/lib/pnp4nagios/mail/Check_internet_speed.rrd 1429929769:24.09:10.23

    so obviously, i need to talk to pnp4nagios! as your check is providing the required information. thanks!

    1. All I would say is that a 6 hour check period is very long in Nagios terms. I saw similar happen with our disk capacity checks with Nagiosgraph and we had to increase the time which Nagiosgraph allowed between checks for it to graph. I imagine there will be a similar setting with PNP4Nagios.

      Good luck!

  16. I want to add to this conversation, what I found to fix a previously working instance of this check..

    I was getting this error after the plugin had been working for some time.

    “You do not have the expected number of indices in your output from SpeedTest. Is it correctly installed?”

    Turned out the speed test server I was connecting to was no longer around. So I just ran “speedtest –list | less” and updated my Nagios check with the new server ID

    Hope this helps someone else.

  17. Hi!

    I got it working but I have never used web-check-service and graphed-service.

    I instead used generic service. I also have nagiosgraph but check_speedtest doesn’t produce a graph.

    Can you please give me some advice on this?

    Btw, thanks for making this Nagios plugin. One of the best plugins in Nagios.

  18. I tried your script. But I looks to me that it does not react to the bounders. It doesn’t matter wich value I set up P always get OK – Ping ….

    I used the following command ./check_speedtest-cli.sh -w 45 -c 30 -W 1.0 -C 0.5 -l e -s 6472 -p -V

    And got the following output:
    Download Warning Level = 45
    Download Critical Level = 30
    Upload Warning Level = 1.0
    Upload Critical Level = 0.5
    Server Location = e
    Server URL or Integer = 6472
    External Server defined
    count = 9
    Ping: 50.451 ms
    Download: 19.72 Mbit/s
    Upload: 6.71 Mbit/s
    Ping = 50.451
    Download = 19.72
    Upload = 6.71
    Everything within bounds!
    PerfData requested!

    I thought it should be critical because of Download speed is lower than the parameter -c 30.
    Did I miss something?

    Thanks for your help.

    Ralf

      1. I have nagios running inside a docker container that didn’t have bc!

        I added `apt-get install bc -y` to my dockerfile and it works 🙂

  19. Thanks for making this plugin Jon!

    I just can’t seem to get it to exit non-zero, the following example should be a warning for both Download and Upload, right? It always says that it’s within bounds and if I run echo $? after I see a 0 exit code.

    root@7f35f1c0d270:/# /usr/lib/nagios/plugins/check_speedtest-cli -w 75 -c 25 -W 10 -C 5 -l e -s 3575 -p -V
    Download Warning Level = 75
    Download Critical Level = 25
    Upload Warning Level = 10
    Upload Critical Level = 5
    Server Location = e
    Server URL or Integer = 3575
    External Server defined
    count = 9
    Ping: 57.268 ms
    Download: 44.98 Mbit/s
    Upload: 9.76 Mbit/s
    Ping = 57.268
    Download = 44.98
    Upload = 9.76
    Everything within bounds!
    PerfData requested!
    OK – Ping = 57.268 ms Download = 44.98 Mbit/s Upload = 9.76 Mbit/s|’download’=44.98;75;25 ‘upload’=9.76;10;5
    root@7f35f1c0d270:/# /usr/lib/nagios/plugins/check_speedtest-cli -v
    Nagios speedtest-cli plugin. Version number: 1.2 2015022818.19

    Any thoughts?

  20. Hi Jon,
    Seems to be a great plugin, hope I will get it to work eventually 🙂
    I’m running on a Raspberry pi2 box install with wheeze.
    I can not get the script to give me a positive result, it ends up in the speedtest help text.
    $speedtest –simple works fine, bc is installed. And I have speedtest-cli in both /usr/local/nagios/libexec and in /usr/local/bin, speedtest –simple works from any folder.
    check_speedtest-cli.sh is located in /usr/local/nagios/libexec.

    Running:
    $speedtest –server 3707 –simple —>
    Ping: 15.212 ms
    Download: 88.14 Mbit/s
    Upload: 36.58 Mbit/s

    Running:
    $./check_speedtest-cli.sh -w 45 -c 40 -W 2.5 -C 0.5 -p -V -s 3707 —>
    ************************************************************************************

    Nagios speedtest-cli plugin – Version: 1.2 2015022818.19

    OPTIONS:
    -h Show this message
    -w Download Warning Level – *Required* – integer or floating point
    -c Download Critical Level – *Required* – integer or floating point
    -W Upload Warning Level – *Required* – integer or floating point
    -C Upload Critical Level – *Required* – integer or floating point
    -l Location of speedtest server – *Required * – takes either “i” or “e”. If you
    etc.
    .
    .
    .

    Have you any ideas to point my in the correct direction? thx!

  21. Finally I got it to work 🙂

    I had to add “e” to the arguments for the script to work, secondly I had to swap around the values download and upload, to achieve warnings and criticals for the correct up/down direction.

    define service{
    use generic-service
    host_name localhost
    service_description Internet Speed Test Check
    check_command check_internet_speed!80!75!40!35!e!3707
    normal_check_interval 10
    retry_check_interval 5
    }
    Thx for a great plugin.

  22. Hey there,

    there is one space missing.

    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
    }

    between $ARG5 and -s

    then your command_line will work 🙂

  23. Hi Jon,

    i used your fantastic plugin a long time with icinga. At the moment i migrate to check_mk and i want to ask you if i can use some of your functions to create an check_mk check.

    If it work i want to public the check … If you don’t want it i don’t publish the check!

    Regards
    Jonas

  24. Can you help me ?

    /usr/local/nagios/libexec# ./check_speedtest-cli.sh -w 45 -c 40 -W 2.5 -C 0.5 -p -V
    ******************************************************************************************

    Nagios speedtest-cli plugin – Version: 1.2 2015022818.19

    OPTIONS:
    -h Show this message
    -w Download Warning Level – *Required* – integer or floating point
    -c Download Critical Level – *Required* – integer or floating point
    -W Upload Warning Level – *Required* – integer or floating point
    -C Upload Critical Level – *Required* – integer or floating point
    -l Location of speedtest server – *Required * – takes either “i” or “e”. If you pass “i” for
    Internal then you will need to pass the URL of the Mini Server to the “s” option. If you pass
    “e” for External then you must pass the server integer to the “s” option.
    -s Server integer or URL for the speedtest server to test against – *Required* – Run
    “speedtest –list | less” to find your nearest server and note the number of the server
    or use the URL of an internal Speedtest Mini Server
    -p Output Performance Data
    -v Output plugin version
    -V Output debug info for testing

    This script will output the Internet Connection Speed using speedtest-cli to Nagios.

    You need to have installed speedtest-cli on your system first and ensured that it is
    working by calling “speedtest –simple”.

    See here: https://github.com/sivel/speedtest-cli for info about speedtest-cli

    First you MUST define the location of your speedtest install in the script or this will
    not work.

    The speedtest-cli can take some time to return its result. I recommend that you set the
    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.

    You also need to have access to bc on your system for this script to work and that it
    exists in your path.

    Your warning levels must be higher than your critical levels for both upload and download.

    Performance Data will output upload and download speed against matching warning and
    critical levels.

    Jon Witts

    ******************************************************************************************

  25. Hi Jon, I have an issue when using NRPE to check the speed in remote system :

    [nagios@HK1NAGL01 libexec]$ ./check_nrpe -H 123.123.123.123 -c check_internetspeed
    Download Warning Level = 10
    Download Critical Level = 7
    Upload Warning Level = 15
    Upload Critical Level = 10
    Server Location = e
    Server URL or Integer = 5120
    External Server defined count = 11
    You do not have the expected number of indices in your output from SpeedTest. Is it correctly installed?

    The script is working fine when running in the remote system. See if you have any idea.

    Thanks,
    Jerry

    1. The error is because you need to specify a valid speedtest server ID. run the speedtest binary with the following arguments:

      –list |less

      Then put the server ID at the end of your check command.

      1. Ido and Jerry,

        I saw this myself the other day. Every now and again it appears as if a speedtest server may no longer be available. I was getting this error and running “speedtest -list | less” on the server identified that the server I had defined was no longer available. I changed the server ID and all was working again as expected!

        Jon

  26. Hi Jon,
    It seems I’ve been asleep at the keyboard for a couple of years and never knew this existed.

    Installed your script and worked pretty much out-of-the-box for my Nagios install.

    My Nagios services screen shows a return like so.. WARNING – Ping = 1.129 ms Download = 319.54 Mbit/s Upload = 0.50 Mbit/s

    What i can’t seem to get working is NagiosGrapher 1.7.1 with it ..
    my serviceext/localhost.cfg has not updated.
    and a ‘ tail -f /usr/local/nagios/var/ngraph.log ‘
    does not show a return for the new service

    Did you need to do anything ‘manual’ to get NagiosGrapher to pick it up ? (i have plenty of other NGraphs that are working..)

    Did you have to create an /ngraph.d/templates/check_speedtest-cli.ncfg for your graph? (& could you share same)

    Did you create an entry for it in serviceext/localhost.cfg ?

    Thanks, Gar

    1. Hi Gar,

      I have never used NagiosGrapher before so I am not sure. We use this script successfully with NagiosGraph however… With NagiosGraph so long as your nagios check is outputting Perf Data it willgraph the data from that.

      Have you passed the flag to generate Perf Data with your check?

      Jon

      1. Oops.. missed that ‘p’ flag…Got it set now..

        Current Status: OK (for 0d 0h 4m 58s)
        Status Information: OK – Ping = 0.995 ms Download = 367.35 Mbit/s Upload = 0.79 Mbit/s
        Performance Data: ‘download’=367.35;350;300 ‘upload’=0.79;0.5;0.2
        Current Attempt: 1/2 (HARD state)
        Last Check Time: 2016-03-10 11:18:38
        Check Type: ACTIVE
        Check Latency / Duration: 0.172 / 37.887 seconds
        Next Scheduled Check: 2016-03-10 11:48:38
        Last State Change: 2016-03-10 11:18:38
        Last Notification: N/A (notification 0)
        Is This Service Flapping? N/A
        In Scheduled Downtime? NO
        Last Update: 2016-03-10 11:23:29 ( 0d 0h 0m 7s ago)

        Still not seeing it in ‘ tail -f /usr/local/nagos/var/ngraph.log ‘ though.. Hmm

  27. Stll not seeng t n ‘ tal -f /usr/local/nagos/var/ngraph.log ‘ though..

    Hmm.. Chars being dropped in reply.. P1CK the m1ss1ng vowel.. AEIOU

    Still not seeing it in ‘ tail -f /usr/local/nagios/var/ngraph.log ‘ though..

  28. Hi Jon, seems to be fixed now, as is my Nagiosgrapher issue.. (a lack of understanding on my part as to how Nagiosgrapher differs from other Nagios graphing addons)

  29. Hi Jon , see if you have any idea on below command output , I notice that the count is different when running with NRPE or local , the parameters were same.

    Run with NRPE
    ===================================
    [root@PERF-MON-01 plugins]# ./check_nrpe -H localhost -c check_intspeed
    Download Warning Level = 10
    Download Critical Level = 7
    Upload Warning Level = 15
    Upload Critical Level = 12
    Server Location = e
    Server URL or Integer = 1536
    External Server defined
    count = 11
    You do not have the expected number of indices in your output from SpeedTest. Is it correctly installed?
    ===================================

    Run in local
    ===================================
    root@PERF-MON-01 plugins]# /usr/lib64/nagios/plugins/check_speedtest-cli.sh -w 10 -c 7 -W 15 -C 12 -l e -s 1536 -p -V
    Download Warning Level = 10
    Download Critical Level = 7
    Upload Warning Level = 15
    Upload Critical Level = 12
    Server Location = e
    Server URL or Integer = 1536
    External Server defined
    count = 9
    Ping: 2.938 ms
    Download: 80.83 Mbit/s
    Upload: 43.98 Mbit/s
    Ping = 2.938
    Download = 80.83
    Upload = 43.98
    Everything within bounds!
    PerfData requested!
    OK – Ping = 2.938 ms Download = 80.83 Mbit/s Upload = 43.98 Mbit/s|’download’=80.83;10;7 ‘upload’=43.98;15;12
    ===================================

    1. This is strange as we have this running correctly over NRPE from two different servers; Linux and Windows. Can you post your NRPE command definition?

      1. I have the same problem. My Nrpe command look like this:

        command[check_internet_speed]=/usr/lib64/nagios/plugins/check_speedtest-cli.sh -w 10 -c 7 -W 10 -C 7 -l e -s 3707 -p

        When i run local:

        /usr/lib64/nagios/plugins/check_speedtest-cli.sh -w 10 -c 7 -W 10 -C 7 -l e -s 3707 -p

        OK – Ping = 5.534 ms Download = 480.62 Mbit/s Upload = 278.05 Mbit/s|’download’=480.62;10;7 ‘upload’=278.05;10;7

        And remove with nrpe:

        /usr/local/nagios/libexec/check_nrpe -H 10.41.24.239 -c check_internet_speed

        You do not have the expected number of indices in your output from SpeedTest. Is it correctly installed?

        Running nrpe 2.15

  30. How do i know if its working? I mean i can download speedtest.cli and get download and upload and if i run speedtest –simple i get the ping as well. Whats the script for ?

    1. Well the script is to be able to have Nagios perform the check for you and to report it through your Nagios install. It will also graph the available upload and download speed against time for you if you use a tool like Nagiosgraph.

  31. Jon,

    run the command ./check_speedtest-cli.sh -w 45 -c 40 -W 2.5 C 0.5 -p -s -V 6581 and appears this result , what am I doing wrong ?

    ./check_speedtest-cli.sh -w 45 -c 40 -W 2,5 -C 0,5 -p -V -s 6581

    my speedtest -cli is in /usr/bin/speedtest -cli

    in ./check_speedtest-cli.sh file line 170 put bST=/usr/bin/speedtest -cli
    ******************************************************************************************

    Nagios speedtest-cli plugin – Version: 1.2 2015022818.19

    OPTIONS:
    -h Show this message
    -w Download Warning Level – *Required* – integer or floating point
    -c Download Critical Level – *Required* – integer or floating point
    -W Upload Warning Level – *Required* – integer or floating point
    -C Upload Critical Level – *Required* – integer or floating point
    -l Location of speedtest server – *Required * – takes either “i” or “e”. If you pass “i” for
    Internal then you will need to pass the URL of the Mini Server to the “s” option. If you pass
    “e” for External then you must pass the server integer to the “s” option.
    -s Server integer or URL for the speedtest server to test against – *Required* – Run
    “speedtest –list | less” to find your nearest server and note the number of the server
    or use the URL of an internal Speedtest Mini Server
    -p Output Performance Data
    -v Output plugin version
    -V Output debug info for testing

    This script will output the Internet Connection Speed using speedtest-cli to Nagios.

    You need to have installed speedtest-cli on your system first and ensured that it is
    working by calling “speedtest –simple”.

    See here: https://github.com/sivel/speedtest-cli for info about speedtest-cli

    First you MUST define the location of your speedtest install in the script or this will
    not work.

    The speedtest-cli can take some time to return its result. I recommend that you set the
    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.

    You also need to have access to bc on your system for this script to work and that it
    exists in your path.

    Your warning levels must be higher than your critical levels for both upload and download.

    Performance Data will output upload and download speed against matching warning and
    critical levels.

    Jon Witts

    ******************************************************************************************

    1. Try this command “./check_speedtest-cli.sh -w 45 -c 40 -W 2,5 -C 0,5 -p -V -s 6581” but with full stops instead of commas for the decimal points…

  32. There was an update on PHP that put post_max_size at a default of 8M. That broke the speedtest mini site, which would make the check not work for internal tests. increase post_max_size to 10M and restart http server and that cleared it up for me.

  33. Hi Jon,

    I try to use your script in icinga2 but seems that the command definition and service definition should be declared differently?

    Could you help with that?

    1. object CheckCommand “server_internet_speedtest” {
      import “ipv4-or-ipv6”
      command = [ “/opt/github/nagios-speedtest/check_speedtest-cli.sh” ]

      arguments = {
      “-w” = “$speedtest_dl_warn$”
      “-c” = “$speedtest_dl_crit$”
      “-W” = “$speedtest_ul_warn$”
      “-C” = “$speedtest_ul_crit$”
      “-l” = “$speedtest_location$”
      “-s” = “$speedtest_server$”
      “-p” = {
      set_if = “$speedtest_performance_data$”
      }
      }

      vars.speedtest_dl_warn = “100”
      vars.speedtest_dl_crit = “50”
      vars.speedtest_ul_warn = “100”
      vars.speedtest_ul_crit = “50”
      vars.speedtest_location = “e”
      vars.speedtest_performance_data = true
      }

  34. Hey Jon,

    very nice Plugin! But i have a problem with it. I can get the Data via shell:
    ./check_speedtest-cli.sh -w 5.5 -c 4 -W 5.5 -C 4 -l e -s 6599 -p -V
    Download Warning Level = 5.5
    Download Critical Level = 4
    Upload Warning Level = 5.5
    Upload Critical Level = 4
    Server Location = e
    Server URL or Integer = 6599
    External Server defined
    count = 9
    Ping: 36.305 ms
    Download: 7.44 Mbit/s
    Upload: 8.19 Mbit/s
    Ping = 36.305
    Download = 7.44
    Upload = 8.19
    Everything within bounds!
    PerfData requested!
    OK – Ping = 36.305 ms Download = 7.44 Mbit/s Upload = 8.19 Mbit/s|’download’=7.44;5.5;4 ‘upload’=8.19;5.5;4

    But in my nagios i get the Error Unknown and in the result are only ******************************************************************

    I have insert the commands and the service

    Can u help me plz?

    Thanks a lot!

    HiTTi

    1. I solved the problem.

      define service{
      use generic-service

      host_name Gateway
      service_description Internet Speed Test Check
      check_command check_internet_speed!5.5!4!5.5!4!e!6599
      normal_check_interval 30
      retry_check_interval 5
      notifications_enabled 0
      }

      I used the -s -w …. statements… but i have to use !x!x!x!

  35. i have configured as said but i receive no output in nagios interface only receives
    the output as below :
    Internet Speed Test Check
    UNKNOWN 20-05-2017 14:31:00 0d 2h 51m 12s 3/3 ******************************************************************************************
    Please help

    1. Deepak,

      I will need a little more info than this to help… What output do you get if you run “speedtest-cli –simple” on the nagios server itself?

      Jon

  36. I am having problems getting this to work. I can run speedtest-cli fine but speedtest fails with

    Traceback (most recent call last):
    File “./speedtest”, line 7, in
    from speedtest import main
    ImportError: No module named speedtest

    Is there something I am missing on the install instructions ?

    1. How have you installed speedtest-cli? I have two executables after my install, speedtest-cli and speedtest. The check uses “speedtest –simple”, so you need to be able to run that on your nagios server for things to work…

  37. Anyone else got it working with NRPE? I am having tough time with it.
    I was getting openurl timeout so I added timeout to following line:
    command=$($STb/speedtest –timeout 40 –server=$SEs –simple)
    My /etc/nagios/nrpe.cfg entry looks like this(BTW other NRPE checks works fine)
    command[check_internet_speed]=/usr/lib/nagios/plugins/check_speedtest -w 200 -c 100 -W 33 -C 20 -l e -s 2629
    When I run command from nagios server I get
    # /usr/local/nagios/libexec/check_nrpe -H X.X.X.X -c check_internet_speed -t 300
    “You do not have the expected number of indices in your output from SpeedTest. Is it correctly installed?”
    There is no problem running script on server locally. Any help would be appreciated.

    1. What do you get when it runs verbosely? Also if you run the speedcheck command on the terminal of your NRPE machine what do you get?

      I have it running over NRPE but using Windows servers not Linux ones…

      1. This is what I get when script is ran on verbose mode:
        /usr/lib/nagios/plugins/check_nrpe -H localhost -c check_speed -t 300
        Download Warning Level = 200
        Download Critical Level = 100
        Upload Warning Level = 33
        Upload Critical Level = 20
        Server Location = e
        Server URL or Integer = 2629
        External Server defined
        count = 9
        Could not retrieve speedtest.net configuration:
        Ping = not
        Download = configuration:
        Upload = timed
        Upload less than critical limit. $upload = timed and $ULc = 20
        PerfData requested!
        CRITICAL – Ping = not retrieve Download = configuration: |’download’=configuration:;200;100 ‘upload’=timed;33;20

        Also I am interested to know how you achieve running it on windows box. That would work for me as well. Is it a different script.

        1. So your speedtest check is timing out before anything gets returned to the script… What is your timeout value on the NRPE check? I will see if I can get time to write up the Windows setup soon.

          1. I have given timeout value of 300. Would be amazing if you could share windows script to have NRPE speed check.

  38. Hi and thanks for creating this. Am struggling to getting it to run, though:

    ./check_speedtest-cli.sh -w 45 -c 40 -W 2.5 -C 0.5 -p -V
    Retrieving speedtest.net configuration…
    Testing from UPC Schweiz (x.x.x.x)…
    Retrieving speedtest.net server list…
    Selecting best server based on ping…
    Hosted by iway AG (Zurich) [39.50 km]: 16.676 ms
    Testing download speed……………………………………………………………………..
    Download: 187.82 Mbit/s
    Testing upload speed……………………………………………………………………………………
    Upload: 21.57 Mbit/s
    ******************************************************************************************
    Nagios speedtest-cli plugin – Version: 1.2 2017112810:20
    You have not defined the location of the speedtest binary in the script! You MUST do
    this before running the script. See line 171 of the script!
    ******************************************************************************************

    Couple of points:
    1. It runs, but it still exits with the above error
    2. In order to get the script running, I have to provide the full path (/usr/local/bin/speedtest-cli or /usr/local/bin/speedtest), otherwise (/usr/local/bin) I get the following error:
    ./check_speedtest-cli.sh: line 156: /usr/local/bin: Is a directory
    3. The variable $STb is defined on Line 156 and not 171

    Is there anything I’m doing wrong?

    1. Ah, found the culprit:
      Correct: STb=/usr/local/bin
      Incorrect: STb= /usr/local/bin

      The space after the = meant that the variable was empty and that the script tried executing the path. That’s why I saw speedtest running and then your script throwing the exception.
      Point 3 is also moot, I seem to have copied the script in a wrong way.

      All good now, thanks again!

  39. Hi There,

    Is it possible to use my private link just Nagios XI to branch e.g. MPLS, ADSL?
    If possible what is an endpoint of a branch can I run speed test mini server?

    Thank you.

  40. Hi, great work on this. I’m having an issue, please can you help?

    I have been getting the same as Deepak and HiTTi above.

    I receive the below in the gui service of nagios
    ******************************************************************************************

    Nagios speedtest-cli plugin – Version: 1.2 2017122011:01

    OPTIONS:
    -h Show this message
    -w Download Warning Level – *Required* – integer or floating point
    -c Download Critical Level – *Required* – integer or floating point
    -W Upload Warning Level – *Required* – integer or floating point
    -C Upload Critical Level – *Required* – integer or floating point
    -l Location of speedtest server – *Required * – takes either “i”………….”

    when I run speedtest.cli –simple on the nagios server, i get the results as expected..

    “speedtest-cli –simple
    Ping: 14.987 ms
    Download: 26.06 Mbit/s
    Upload: 9.38 Mbit/s”

    So the plugin works fine.

    when i run “./check_speedtest-cli.sh -w 20 -c 10 -W 10 -C 5 -l e -s 226 -p” i get the above issue again.

    Even if i change the server ID (-s), this does nothing. Any ideas?

  41. After spending days on my issue and writting my last reply to you, i figured it out, HA.

    Basically, i had to install BC on my pi as it wasn’t installed (apt-get install BC) and additionally had to remove the -p from “./check_speedtest-cli.sh -w 20 -c 10 -W 10 -C 5 -l e -s 226 -p” so “./check_speedtest-cli.sh -w 20 -c 10 -W 10 -C 5 -l e -s 226” and all was working!

    I’ve seen a few people with this issue, so hopefully that should resolve it for them. Great work on this!!

    1. Hi,
      first of all really great plugin, but it took some time to make it work.

      I have been getting the same error as Maverick, Deepak and HiTTi above with Nagios speedtest-cli plugin – Version: 1.2 2017122011:01
      speedtest-cli –simple was working, ./check_speedtest-cli.sh was not, instead it only showed the help. BC was already installed, so no issues there.

      Error 1 : I had a typo in the arguments and so I had two -c parameter, but no -C parameter
      wrong: ./check_speedtest-cli.sh -w 10 -c 5 -W 10 -c 5 -l e -s2002
      right: ./check_speedtest-cli.sh -w 10 -c 5 -W 10 -C 5 -l e -s2002

      Error 2: The -p options breaks it on the console
      wrong: ./check_speedtest-cli.sh -w 10 -c 5 -W 10 -C 5 -l e -s2002 -p
      right: ./check_speedtest-cli.sh -w 10 -c 5 -W 10 -C 5 -l e -s2002

      Now everything ist good. Maybe you can fix the -p or write an improved error handling?

      1. The -p option has always worked fine for me… I would need more info about *how* it is breaking it for you before I could try to resolve. I would suggest logging an issue over on the project’s GitHub page…

  42. Hi Jon,
    This plugin is really helpful for us to keep track of our ISP’s.

    When I observe the data when I run speedtest through browser we are getting good speed and when we run the same through command line speed is showing really bad.

    Can you please help us on this.

    1. Not really sure what advice I can offer. The plugin is just reporting the results from speedtest-cli. If you are observing the same difference between the online Speedtest and speedtest-cli I would suggest you log an issue over on the speedtest-cli GitHub page…

Leave a Reply

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