Last Updated on January 3, 2023 by Thiago Crepaldi
From previous posts, we have deployed Zabbix Server on a Proxmox container. We also hardened the installation through Let’s Encrypt certificates for the web frontend and TLS encryption for the communication between Server and Agents/Proxies, after all, although encrypted Zabbix Server <-> Agent/Proxy communication with PSK or SSL certificates 🙂
In this post I will cover how to monitor WAN bandwidth through Speedtest using Zabbix Agent template. Templates are great because they already pack a bunch of monitoring items, actions, triggers, etc that we would have to add one by one otherwise. Using template is smart because when we need to make changes, we just do it in the template and all hosts that use them will see the new settings. On a manual setup, you would have to make the change in each host, one by one…
This post assumes you already installed and configured your Zabbix Agent, but if you didn’t, refer to How to install and configure Zabbix agent and resume from here when you are done.
Configuring Zabbix Agent
In order to allow the Zabbix Server to monitor WAN speed, we need use a host in the network to periodically run speedtest and save the result Next, Zabbix Server will collect the data.
After logging in into your Zabbix Agent, install speedtest-cli as described by speedtest.net:
sudo apt-get install curl git
curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash
sudo apt-get install speedtest
Run speedtest
manually once with the user you will run the zabbix agent with to Accept the Speedtest terms and conditions.
Next make sure timeout
and zabbix-sender
are installed on your system
sudo apt install -y coreutils zabbix-sender
Clone the template repository in your Zabbix agent:
$ cd /tmp
$ git clone https://github.com/zabbix/community-templates.git
On your Zabbix Server, go to Configuration >> Templates and click on Import button, select /tmp/community-templates/Applications/Template_App_Speedtest_Wan/6.2/Template_App_Speedtest_Wan.yaml.
Next, copy record_speedtest.sh into your Zabbix Agent host:
$ sudo cp /tmp/community-templates/Applications/Template_App_Speedtest_Wan/6.2/record_speedtest.sh /usr/local/bin
$ sudo chmod +x /usr/local/bin/record_speedtest.sh
Next, edit record_speedtest.sh to point it to Zabbix Server:
$ sudo vim /usr/local/bin/record_speedtest.sh
PSKID="AgentPSK" # PSK ID configured, if you used PSK encryption
PSKFILE="/etc/zabbix/zabbix_agent2.psk" # PSK file, if you used PSK encryption
ZABSRV="zabbixserver.lan.mydomain.com" # Zabbix Server IP/FQDN
SPDHOST="zabbixagent" # Zabbix Agent Hostname
Configure crontab with the user it will run speedtest with to feed Zabbix Server with data every hour. Note that you should use the full path where the script was saved:
$ crontab -e
0 */1 * * * /usr/local/bin/record_speedtest.sh # feed speedtest info into zabbix every 1 hour
Configuring Zabbix Server through Web UI
Go to Configuration >> Hosts and click on Create Host button. When the configuration dialog open, the Host tab should be the default one. Fill in the following fields and leave the rest as-is:
- Host
- Host name: Type the Speedtest WAN hostname
- Templates: Template_App_Speedtest_Wan
- Host Groups: Application or whatever describes your Agent
- Interfaces:
- Add a new interface
- Type: Agent
- IP Address: Type the server IP to be ping’ed
- DNS Name: Type the server FQDN to be ping’ed
- Connect to: Select IP or DNS
- Port: 10050
- Description: Do your thing here
- Monitored by Proxy: (no proxy)
- Add a new interface
- Macros
- Click on Add
- Macro: {$NO_SPDTST_DATA_SECS}
- Value: 21900
- Description: The number of seconds that Zabbix will alert when it’s received no new speedtest data
- Click on Add
- Macro: {$BWIDTH_DL_ALERT}
- Value: 209715200Â
- Description: The threshold for alerting if download bandwidth drops below this value
- Click on Add
- Macro: {$BWIDTH_UL_ALERT}
- Value: 209715200
- Description: The threshold for alerting if upload bandwidth drops below this value
- Click on Add
Finish the host creation by clicking Update.
That is it, let’s try it. Go to Monitoring >> Latest data. In the filter section, type the name of your Speedtest agent in the Hosts box, Speedtest in the Name and finally hit Apply. A list of items should be displayed for it, such as Speedtest – Download Bandwidth, etc
That is it, have fun!
Template author here. Please check out the below. The poster had some minor issues with instructions here.
https://www.reddit.com/r/zabbix/s/3FIC1IFbg9