Hello togehter,
I wrote a script for measuring Download and Upload Speed via iperf3 and sending the Data to a Zabbix Trapper.
Requirements: iperf3; zabbix_agent
You can tell your iperf3 server (I've got mine from https://iperf.fr/) and if the Port is blocked, it counts the portMin one up and test it again.
You can also thell the number of parallel Tests.
I hope this will help some people testing network performance and show this gaphically at the end.
Badly you need to execute it via cronjob.
The Test needs about 24 seconds. Caused of this I couldn't set it as UserParameter. Maybe anyone of you got a better Idea.
I wrote a script for measuring Download and Upload Speed via iperf3 and sending the Data to a Zabbix Trapper.
Requirements: iperf3; zabbix_agent
You can tell your iperf3 server (I've got mine from https://iperf.fr/) and if the Port is blocked, it counts the portMin one up and test it again.
You can also thell the number of parallel Tests.
I hope this will help some people testing network performance and show this gaphically at the end.
Badly you need to execute it via cronjob.
The Test needs about 24 seconds. Caused of this I couldn't set it as UserParameter. Maybe anyone of you got a better Idea.
Code:
#!/bin/bash
#Variabeln für iperf3 Test
IPERFS=bouygues.iperf.fr #Server
portMin=5200 #Mindestport
portMax=5209 #Maximalport
bolDownload=0 #Hilfsflag ob Downloadtest erfolgreich war
bolUpload=0 #Hilfsflag ob Uploadtest erfolgreich war
log=/home/pi/iperf3_erfolgreich.txt #Pfad der Logdatei der Errors
speedlog=/home/pi/iperf3_erfolgreich.txt #Pfad der Logdatei der Erfolgreichen Tests
parallel=3 #Anzahl der Parallelen Tests
#Zabbix Sender Variabeln
ZSERV=10.10.20.107 #Zabbix Server
ZPORT=10051 #Zabbix Trapper Port (default:10051)
THOST='xyz' #Zabbix Name des Hosts (nicht der Hostname vom ZabbixServer!)
ZITEMDOWN=xyz.iperf3.speedtest.down #Zabbix Itemkey für Download
ZITEMUP=xyz.iperf3.speedtest.up #Zabbix Itemkey für Upload
set -o pipefail
#echo "$(date +%x_%T)" Script gestartet >> /home/pi/Scriptstart.txt
while [ $bolDownload == 0 -o $bolUpload == 0 ]
do
if [ $portMin -le $portMax ] #Wenn PortMin kleiner gleich PortMax ist
then
##echo $portMin
#Download prüfen
if [ $bolDownload -eq 0 ]
then
DLOAD=`/usr/bin/iperf3 -f m -c $IPERFS -p $portMin -R -P $parallel |grep sender |grep SUM |awk -F " " '{print $6}'`
if [ "$?" -ne "0" ]; then
#Log
echo "$(date +%x_%T)" Bei DLOAD abgebrochen mit Port $portMin >> $log
else
#Download fertig
bolDownload=1
fi
fi
#Upload prüfen
if [ $bolUpload -eq 0 ]
then
ULOAD=`/usr/bin/iperf3 -f m -c $IPERFS -p $portMin -P $parallel |grep sender |grep SUM |awk -F " " '{print $6}'`
if [ "$?" -ne "0" ]; then
#Log
echo "$(date +%x_%T)" Bei ULOAD abgebrochen >> $log
else
#Upload fertig
bolUpload=1
fi
fi
#Wenn Up- oder Download noch nicht fertig, dann Port hochzählen
if [ $bolDownload == 0 -o $bolUpload == 0 ]; then
#Port hochzählen
let portMin=$portMin+1
fi
else
#Maximale Port-Grenze Erreicht -> Schleife beenden
break
fi done
#Wenn Up- und Download erfolgreich waren, in die Log schreiben
if [ $bolDownload == 1 -a $bolUpload == 1 ]
then
echo "$(date +%x_%T)" Server:$IPERFS" "Port:$portMin" "Download=" "$DLOAD" "Upload=" "$ULOAD >> $speedlog
fi
#Download Daten an Zabbix senden
if [ $bolDownload == 1 ]
then
/usr/bin/zabbix_sender -z "$ZSERV" -p "$ZPORT" -s "$THOST" -k "$ZITEMDOWN" -o $DLOAD
fi
#Upload Daten an Zabbix senden
if [ $bolUpload == 1 ]
then
/usr/bin/zabbix_sender -z "$ZSERV" -p "$PORT" -s "$THOST" -k "$ZITEMUP" -o $ULOAD
fi