Track Packets per Second In Zabbix

Since this metric was not available on all my monitored devices, I had to create a solution.

First, create this script and put it where it goes, chmod as needed:

!/bin/sh
#network interface (eth0/wlan0)
ifname=$1
#in or out (rx/tx)
rxtx=$2
DAT1=cat /sys/class/net/$ifname/statistics/${rxtx}_packets
sleep 1
DAT2=cat /sys/class/net/$ifname/statistics/${rxtx}_packets
DATDIFF=expr $DAT2 - $DAT1
echo "$DATDIFF"

Now add the UserParameter in the config file:

UserParameter=network.ifinfo[*],/etc/zabbix/scripts/pps.sh $1 $2

Now you can create an item, using keys such as:

network.ifinfo[wlan0, rx]
network.ifinfo[wlan0, tx]