Bandwidth monitor via Zabbix server

Loading

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.

Please find the related video for this.

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

21 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

  2. Parthiban says:

    I do above configuration in centos server( zabbix client) and in zabiix server showing wrong data, wt to do

    1. try2answer says:

      Hello Parthiban,

      Sorry for late reply, is your vnstat is showing correct data by command line? are all data (Monthly, daily, Hourly) showing the same thing. If yes please send me the screen shot in my email address. I will like to resolve the issue.

      Thanks
      Shubhankar

  3. Alexander Garcia says:

    Hi,
    i am using zabbix server 3.4, i tried to importe *xml template but it is no compatible.

    do you know if there is a *xml for 3.4 version?

    Rgs
    Alexander

    1. try2answer says:

      Hello Alexander,

      Yes, zabbix 3.4 is supported for xml file as a template.

  4. cool says:

    I do above configuration in centos server( zabbix client) and in zabiix server showing wrong data, wt to do

    1. try2answer says:

      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

  5. ITPILOT says:

    I am trying to Monitor Daily, Weekly and Monthly Bandwidth Usage of 200 + Local and Remote Workstations / Laptops with Zabbix

    I also need the Bandwidth Usage to be Emailed

    How can i do this in Zabbix?

    Any help greatly appreciated

    1. try2answer says:

      Hello,

      Yes, it can be easily possible via the zabbix. Please follow the tutorial, this is very easy, I think if you follow every steps, you will resolve your issue.

      For sending email, please use a proper SMTP server to send the mail from zabibx and create trigger as you want.

      If anything else you need help from me, kindly email me with your queries to my email, I will surely answer them.

      Thanks
      Shubhankar

  6. Quentin says:

    Hey Shubhankar,

    nice tutorial – I’m trying to debug the script as I probably have a different vnstat version then your, meaning when I run the script manually it outpout a blank data,

    here is the outpost of vnstat -m

    #$ vnstat -m

    eth0 / monthly

    month rx | tx | total | avg. rate
    ————————+————-+————-+—————
    2020-08 16.81 MiB | 10.67 MiB | 27.48 MiB | 245 bit/s
    ————————+————-+————-+—————
    estimated 45.98 MiB | 28.10 MiB | 74.08 MiB |

    the script not working are currently the one with the hour, – here is the output of vnstat -h

    #$

    eth0 / hourly

    hour rx | tx | total | avg. rate
    ————————+————-+————-+—————
    2020-08-11
    15:00 939.69 KiB | 1.02 MiB | 1.94 MiB | 4.51 kbit/s
    16:00 2.13 MiB | 3.74 MiB | 5.87 MiB | 13.69 kbit/s
    17:00 2.42 MiB | 1.11 MiB | 3.54 MiB | 8.24 kbit/s
    18:00 2.90 MiB | 1.05 MiB | 3.95 MiB | 9.21 kbit/s
    19:00 3.14 MiB | 1.34 MiB | 4.47 MiB | 10.43 kbit/s
    20:00 4.65 MiB | 2.04 MiB | 6.69 MiB | 15.59 kbit/s
    21:00 979.88 KiB | 725.79 KiB | 1.67 MiB | 15.53 kbit/s
    ————————+————-+————-+—————

    I’m sure that an issue with the awk but I’m not sure the logic behind tempin1 and tempin2

    thanks!

  7. Avi Milbaum says:

    Hello

    Zabbix 5.0
    After import the xml file Network-For-Linux.xml and get import successfully,
    I can’t find the items under the network in the Monitoring \ latest data

    Thanks
    Avi

  8. Avi Milbaum says:

    ok I find that I need to mark the Show items without data.
    so I need help to find the reason that I don’t get values

  9. Avi Milbaum says:

    hello

    I installed in zabbix agent release_5.0-1
    run # vnstat
    and get Database updated: Sun Sep 27 16:02:49 2020

    run # vnstat –live
    and get Monitoring eth0…and see the numbers

    but in the zabbix server 5.0 I don’t get the values and the last check is empty

    Where to check why the data does not reach from the zabbix agent to the zabbix server

    Thanks
    Avi

  10. Mislav says:

    Hi.

    Thank you very much for this.

    The following 3 scripts were showing errors:
    total_bandwidth_for_current_hour.sh
    total_inbound_for_current_hour.sh
    total_outbound_for_current_hour.sh
    total_bandwidth_for_previous_hour.sh
    (standard_in) 1: syntax error

    The problem was that in awk you were printing 10 / 11 column, however in vnstat only 9 exists. So I simply replaced 10 with 8 and 11 with 9 and everything is working.

    Have a nice day!

    1. try2answer says:

      Thanks for your comment

  11. Lishin says:

    Hi, I am unable to get information on windows networks’ bandwidth details. My contact number is 9591019145. Could you please call me?
    Thanks

  12. Akash says:

    Hi @try2answer,

    I was using Whatsup Gold, so I want to export into Excel of links device up and down time in zabbix. Can u suggest me for this.
    And one more thing

  13. Sohaib says:

    Hi,

    I am using cento7 and getting sytax error while executing script.

    the output of vnstat –oneline is
    vnstat –oneline
    1;ens32;09/21/2022;4.20 MiB;4.07 MiB;8.27 MiB;2.50 kbit/s;Sep ’22;4.20 MiB;4.07 MiB;8.27 MiB;0.04 kbit/s;4.20 MiB;4.07 MiB;8.27 MiB

    the output of vnstat -m

    ens32 / monthly

    month rx | tx | total | avg. rate
    ————————+————-+————-+—————
    Sep ’22 4.20 MiB | 4.07 MiB | 8.27 MiB | 0.04 kbit/s
    ————————+————-+————-+—————
    estimated 5 MiB | 5 MiB | 10 MiB |
    [root@nl5 bwmonitor]#

    please suggest me what i need to modify in script.

    1. try2answer says:

      Hello Sohaib,

      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 to Mislav Cancel reply

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