
Monitoring the bandwidth and latency of our Internet connection
Another curiosity that we can do with monitoring is to be able to measure the bandwidth of our organization's Internet connection. Very simply, using a script we can do a speed test with a nearby server and monitor it with Centreon, We will be able to receive alerts as long as the bandwidth is lower than the values we are interested in!
We installed a requirement that will support the script we'll use with Centreon:
[SourceCode]PIP Install SpeedTest-CLI[/SourceCode]
Download the script we'll use from: https://exchange.nagios.org/directory/Plugins/Network-Connections%2C-Stats-and-Bandwidth/check_speedtest-2Dcli/details and we leave it in the Centreon machine, we move it to the Centreon plugin path and make it executable:
[SourceCode]MV check_speedtest-cli.sh /usr/lib/centreon/plugins
cd /usr/lib/centreon/plugins/
chmod +x check_speedtest-cli.sh[/SourceCode]
We edit the script and in the line 175 we will modify STb= to STb=”/usr/bin”
And also, If we want the graphs to work for us… We'll have to edit the line 401 and add right after “# append perfout if argument was passed to script” we add in the following line:
[SourceCode]PerfData="TRUE"[/SourceCode]
And finally on the line 406 modify and leave it as it is to also enter the latency value in the graph, that if we look at it, only the download and upload speed passes:
[SourceCode]perfout="|'latency'=$ping 'download'=$download;$DLw;$Dlc;0;$(Echo $MaxDL*1.05|bc) 'upload'=$upload;$ULw;$ULc;0;$(Echo $MaxUL*1.05|bc)"[/SourceCode]
With “Speedtest –list | less” We take out the nearest servers, we write down the ID or URL of the one we are most interested in checking.
10512) Sarenet (Zamudio, Spain) [14.89 km]
5161) Imatel (Donostia / San Sebastian, Spain) [83.06 km]
4158) iperf.fr (Bayonne, France) [125.01 km]
15961) Sisnet (Pamplona, Spain) [126.35 km]
9646) KNET (La Rioja, Spain) [129.96 km]
11677) Axione (Pau, France) [213.71 km]
11431) TeleCable (Gijón, Spain) [217.92 km]
3276) Telecable (Oviedo, Spain) [228.14 km]
…
We are now going to register the Command in Centreon, since “Configuration” > “Commands” > “Add…” We created it:
- Comman Name: The name of the Command, We usually use the script name directly, in this case check_speedtest-cli.sh
- Command Type: Check
- Command Line: The command that will execute, We replace the path where the plugin is with variables, and the arguments that we will pass on to you. Something like: “$CENTREONPLUGINS$/check_speedtest-cli.sh -w $ARG 1$ -c $ARG 2$ -W $ARG 3$ -C $ARG 4$ -l e -s $ARG 5$”
Click on “Describe arguments” and we define the arguments of the command, that they will be, The First Argument The Download Speed Warning (in MB) and the second argument the value of when it warns us with Critical if the download speed is even lower than the Warning. The third argument will be the Warning of the upload speed and the fourth argument will be the Critical value of the upload. What I said, Warning values must be higher than Critical, the lower the available bandwidth, the worse, No? 😉
And we create the service that will check every minute that we indicate the maximum download and upload speed against the server we indicate, and also if you download less than 40 will notify us with Warning and if the download is less than 30 will alert with a critical event. Since “Configuration” > “Services” We add a service:
- Description: It is the name with which we will see this item monitored, something like “Bandwidth Test” or similar more than enough.
- Linked with Hosts: We will bind this service normally to the Router or Firewall, It doesn't matter.
- Template: Normally we will choose generic-active-service-custom.
- Check Command: Select the newly created Command in the previous step 'check_speedtest-cli.sh'.
- Arguments: And here is the usual, we fill in the values as we see fit and that's it!
Click on “Save” and proceed to record the Centreon configuration & Reload.
And that's it! We will already have the capacity of our line or Internet connection monitored, we will be able to see if the ISP always meets its SLA and we have good speeds both for uploads and downloads, as well as the always necessary latency times! Well, From the monitoring view we will be able to see the status of the service that we have just added, perfect, No? I hope you find it useful!