Bandwidth monitor via Zabbix server

2,888 total views, 4 views today

Zabbix server gives you bandwidth calculation via “net.if.in[eth0,bytes]” and “net.if.out[eth0,bytes]” functions. But sometime you might face some issue with this functions, e.g. sometime might be your actual bandwidth data mismatch with the Zabbix server shown data. So, for the mitigate this problem you can use this solution. If you face any issue regarding this please comment on these post.

Here I am using vnstat tool for the collecting of all bandwidth data from agent servers.

Dependency Package (Ubuntu, CentOS):

  • vnstat
  • bc
  • zip, unzip
  • dos2unix

This Tutorial gives you 

  • Total Outbound for today
  • Total OutBound For Current Hour
  • Total Inbound for today
  • Total Inbound For Current Hour
  • Total Bandwidth For Previous Hour
  • Total Bandwidth For Current Hour
  • Total Bandwidth for Today
  • Total Bandwidth for last 7 days
  • Total Bandwidth for the current Month
  • Last 2 month bandwidth (current+previous)

In Agent server (Login to the agent server SSH)

First Install all package along with the dependencies.

# apt-get install vnstat bc unzip zip dos2unix -y

Setup the vnstat interface and create interface database for vnstat. Edit below code () with your server network interface.

# vnstat -u -i $interface

Now create a directory for Bandwidth calculation script and go to the directory.

# mkdir /etc/zabbix/script
# cd /etc/zabbix/script

Download the below link and unzip the file.

# wget https://www.try2answer.com/wp-content/uploads/2018/10/bandwidth.zip
# unzip bandwidth.zip

Give the executive permission to the all script files

# chmod +x *

Add below cron for automatic Bandwidth Update.

echo "*/5 * * * * sh /etc/zabbix/script/update.sh"

to removing all hidden windows characters from script files

# dos2unix *.sh

Add UserParameter to the zabbix agent conf file

# echo "UserParameter=system.monthlybandwidth,/etc/zabbix/script/zabbix_total_month_bandwidth.sh
UserParameter=system.todaybandwidth,/etc/zabbix/script/zabbix_todays_total_bandwidth.sh
UserParameter=system.todayinbound,/etc/zabbix/script/zabbix_todays_total_inbound.sh
UserParameter=system.todayoutbound,/etc/zabbix/script/zabbix_todays_total_outbound.sh
UserParameter=system.last7daybandwidth,/etc/zabbix/script/zabbix_last_7_days_total_bandwidth.sh
UserParameter=system.currenthour,/etc/zabbix/script/total_bandwidth_for_current_hour.sh
UserParameter=system.previoushour,/etc/zabbix/script/total_bandwidth_for_previous_hour.sh
UserParameter=system.last2month,/etc/zabbix/script/last_2_month_total_bandwidth.sh
UserParameter=system.currenthourin,/etc/zabbix/script/total_inbound_for_current_hour.sh
UserParameter=system.currenthourout,/etc/zabbix/script/total_outbound_for_current_hour.sh" >> /etc/zabbix/zabbix_agentd.conf

Restart the zabbix agent 

For Ubuntu
# /etc/init.d/zabbix-agent restart
For CentOS
# systemctl restart zabbix-agent

Check once the zabbix agent server is running or not.

# netstat -tlnp | grep zabbix

You have done in the Zabbix agent Part, Now login to the zabbix server Dashboard.

In Zabbix Server (Login to the Zabbix server Dashboard)

Download the below Template and unzip

After unzip, Login to the zabbix Dashboard –> Configuration –> Templates –> Click on Import –> Select the xml template file –> Click on Import

After the template successfully add to the zabbix server, select the host server and attach the newly added template.
dashboard –> Configuration –> Hosts –> Select Host –> Template Tab –> Link New template –> Add –> Update.

After Update the host, Wait some time we will get all Bandwidth Calculation report.

You are all Done!

 

Extra Data from This tutorials

By Default Below two items are disabled and you will not get below two data.

  • Total Outbound for today
  • Total Inbound for today

But If you want to see this data, you can enable it anytime from your zabbix dashboard.
Dashboard –> Configuration –> Templates –> Network for Linux –> Items –> Check 2 Item that are disabled –> Click on Enable.



If You face any issue regarding this please comment below:
Thank You

3 Comments to “Bandwidth monitor via Zabbix server”

  1. Den says:

    Last 2 month bandwidth (current+previous) 2019-09-09 12:11:37 (standard_in) 1: syntax error

    1. try2answer says:

      Hello Den,

      Sorry for the late response!
      Actually all the script is completely depend on the vnstat output format. Output format of vnstat will be differed on the each Linux distribution (Ubuntu, Centos). So in that case can you please provide the output of below commands. so that I can check from my end and update the script respectively.

      # vnstat –oneline
      # vnstat –m

      Also, as all the script are written in windows system, so it is recommended that please run dos2unix command before using all the script.

      Thanks
      Shubhankar

Leave a Reply

Your email address will not be published. Required fields are marked *