bandwidth monitoring script for nagios (CentOS) – bw_watch.sh

Bash script for nagios, that monitors bandwidth usage on remote host.
# usage ./bw_watch bw_warning bw_critical pkt_warning pkt_critical
It takes momentary 5 secs average bandwidth from “vnstat”, and returns value for nagios.

bc and vnstat packages at host side are necessary.
bc package should be in default centos repository, vnstat and nrpe You can find in EPEL repo.

Script itself, that You have to put to nagios plugins directory. In my case it was: /usr/lib64/nagios/plugins/

Script bw_watch.sh has to be in server that has to be checked.
Download link

Download link

On host, that has to be checked, you have to add to nrpe.conf (usually /etc/nagios/nrpe.cfg)

restart nrpe

nagios command definition at monitoring server (usually commands.cfg):

define service at monitoring server (where monitored host configuration is located):
Parameters are: bandwidth_warning, bandwidth_critical, packets_warning, packets_critical
Bandwidth is metered in kbits/s.

And reload nagios configuration

Insipration source: nagios bandwidth plugin

6 comments
      • Yeh, it seems to work fine.

        But … should the check cmd in command.cfg actually be something more like:

        check_command check_bandwidth!100!200!300!400

        ?

        • it is possible to do that, but in my example – no.
          The way it works in this tutorial is:
          check_command check_bandwidth

          Nagios server uses only “check_bandwidth” command (without arguments) to check the bandwidth.

          This command is defined like that (also no arguments):
          command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_bandwidth -t60

          It basically just executes ‘check_bandwidth’ command that is described on the monitored host.

          And Your monitored host should have that ‘check_bandwidth’, but this time with the parameters:
          in nrpe.cfg:
          command[check_bandwidth]=/usr/lib64/nagios/plugins/bw_watch.sh 2048 4096 2048 4096

          To be able to “pass” arguments to nrpe, need to redo the logic of nagios configs. It won’t work on the current described setup.

  1. HI ,

    I have installed vnstat tool on server.I can able to view the traffic usage,But Executed your bw_watch.sh script i am getting some error .can you please help me on this issue.

    Error :-

    ./bw_watch.sh 2048 4096 2048 4096
    ./bw_watch.sh: line 28: [: ==: unary operator expected
    ./bw_watch.sh: line 33: [: ==: unary operator expected
    ./bw_watch.sh: line 42: [: 4096: unary operator expected
    ./bw_watch.sh: line 42: [: 4096: unary operator expected
    ./bw_watch.sh: line 42: [: 4096: unary operator expected
    ./bw_watch.sh: line 42: [: 4096: unary operator expected
    ./bw_watch.sh: line 46: [: 2048: unary operator expected
    ./bw_watch.sh: line 46: [: 2048: unary operator expected
    ./bw_watch.sh: line 46: [: 2048: unary operator expected
    ./bw_watch.sh: line 46: [: 2048: unary operator expected

Leave a Reply