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 LAN speed between the Zabbix Server and a Zabbix Agent, we need use a host in the network to periodically run iperf3 and save the result. Next, Zabbix Server will process the data.
After logging in into your Zabbix Agent, install iperf3:
$ sudo apt-get install iperf3
Clone the template repository in your Zabbix agent:
$ cd /tmp
$ git clone https://git.cdp.li/polcape/zabbix/tree/master/zabbix-speedtest-lan
Next, copy record_speedtest.sh into your locally:
$ sudo cp /tmp/zabbix-speedtest-lan/speedtest-lan.sh /usr/local/bin
$ sudo chmod +x /usr/local/bin/speedtest-lan.sh
Next, edit speedtest-lan.sh to point it to Zabbix Server:
$ sudo vim /usr/local/bin/speedtest-lan.sh
IPERF_NUMBER=1 # Number of iperf servers
IPERF_IP[0]="zabbixserver.lan.mydomain.com" # IP/FQDN of Zabbix/iperf server
IPERF_NAME[0]="Zabbix server" # Zabbix server hostname (as shown on UI)
IPERF_TR_DL[0]="10"
IPERF_TR_UL[0]="10"
Copy speedtest-lan.conf to your Zabbix Agent config folder:
$ sudo cp /tmp/zabbix-speedtest-lan/speedtest-lan.conf /etc/zabbix/zabbix_agent2.d
Complete configuration on Zabbix agent by restarting the agent:
$ sudo systemctl restart zabbix-agent2
Configuring Zabbix Server through Web UI
After logging in into your Zabbix Server, install iperf3:
$ sudo apt-get install iperf3
Clone the template repository in your Zabbix Server:
$ cd /tmp
$ git clone https://github.com/zabbix/community-templates.git
$ git clone https://git.cdp.li/polcape/zabbix.git
On your Zabbix Server, go to Configuration >> Templates and click on Import button, select /tmp/community-templates/Network_Appliances/template_speedtest_lan_monitoring/6.0/template_speedtest_lan_monitoring.yaml.
Next, navigate 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 iperf hostname
- Templates: App Speedtest LAN
- 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
Finish the host creation by clicking Update.
Finally, we need to make sure iperf3 is always up and running as server. We will create a systemd startup script for that purpose:
$ sudo vim /etc/systemd/system/iperf3.service
[Unit]
Description=iperf3 server
After=syslog.target network.target auditd.service
[Service]
ExecStart=/usr/bin/iperf3 -s
[Install]
WantedBy=multi-user.target
Let’s make sure it will start with the system boot:
$ sudo systemctl start iperf3
$ sudo systemctl enable iperf3
That is it, let’s try it. Go to Monitoring >> Latest data. In the filter section, type the name of your iperf 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 Zabbix server – Download, etc
That is it, have fun!
There is a bug in the
https://git.cdp.li/polcape/zabbix/-/blob/master/zabbix-speedtest-lan/speedtest-lan.sh
file, lines 34 and 35 reference the same result, even though they are saved for “upload” and “download” speeds.
I believe “download” should grep “receiver”, not “sender”
[…]
else
download=$(iperf3 -f m -c “$1″ -R | grep sender | awk -F ” ” ‘{print $7}’)
upload=$(iperf3 -f m -c “$1″ | grep sender | awk -F ” ” ‘{print $7}’)
my bad. I hadnt realized the “-R” in the download variable.