← Back to list

Linux server bandwidth monitor using nagios

Monitoring bandwidth on a Linux server is not optional in a production-grade environment — it’s a core observability and control mechanism…

Zakir Hossain · 2026-04-08 08:50 · 2 claps · 2.2 min read
#nagios #graph #nrpe #bandwidth
Open on Medium ↗
Wiki topics: 🔓 · Open Source

Linux server bandwidth monitor using nagios

Monitoring bandwidth on a Linux server is not optional in a production-grade environment — it’s a core observability and control mechanism. From a systems and network engineering perspective, it directly impacts performance, security. Today i will share an easy method to monitor Linux server bandwidth using nagios without 3rd party plugin.

Scenario:

Bandwidth Monitor

Bandwidth Monitor

Pre-requisites:

  1. Nagios
  2. NRPE agent
  3. nagiosgraph or PNP4nagios
  4. sendemail

Consider all the above Pre-requites are already installed.

Step 01: Create Bandwidth Monitor Plugin

Login into your Nagios agent and create a plugin file.

[$] vim /usr/local/nagios/libexec/check_bandwidth.sh
#!/bin/bash
#--------------------------------------------
# Name: Bandwidth Monitor Using nagios      -
# Developer: Md. Zakir Hossain              -
# Mail: zakirpcs@gmail.com                  -
# Version: 1.0                              -
# Release Date: 08-04-2026                  -
# check_bandwidth.sh                        -
# Usage: check_bandwidth.sh <interface>     -
#--------------------------------------------

IFACE=$1
if [ -z "$IFACE" ]; then
    echo "Usage: $0 <interface>"
    exit 3
fi

# Read initial RX/TX bytes
RX1=$(cat /sys/class/net/$IFACE/statistics/rx_bytes)
TX1=$(cat /sys/class/net/$IFACE/statistics/tx_bytes)

# Wait 1 second to measure rate
sleep 1

# Read again
RX2=$(cat /sys/class/net/$IFACE/statistics/rx_bytes)
TX2=$(cat /sys/class/net/$IFACE/statistics/tx_bytes)

# Calculate bytes per second
DOWNLOAD=$((RX2 - RX1))
UPLOAD=$((TX2 - TX1))

# Output in Nagios performance data format
echo "Interface $IFACE Bandwidth - Download: $DOWNLOAD B/s, Upload: $UPLOAD B/s | download=${DOWNLOAD}B upload=${UPLOAD}B"

[$] chmod +x check_bandwidth.sh

Step 02: Configure NRPE agent

# Find interface name using following command

[$] ip a 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:50:56:aa:74:d2 brd ff:ff:ff:ff:ff:ff
    altname enp11s0
    inet 172.16.10.30/24 brd 172.16.10.255 scope global noprefixroute ens192
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:feaa:74d2/64 scope link
       valid_lft forever preferred_lft forever

[$] vim /usr/local/nagios/etc/nrpe.cfg
command[check_bw]=/usr/local/nagios/libexec/check_bandwidth.sh ens192

Step 03: Configure Service in the Nagios Server

[$] vim /usrlocal/nagios/etc/object/services.cfg
# Add below line at the end of the services.cfg file
# Interface Bandwidth Monitor
define service {
    use                     important-service,nagiosgraph
    host_name               w4-ns01
    service_description     Interface Bandwidth
    check_command           check_nrpe!check_bw
    process_perf_data       1
    contact_groups          sysadmin
}

# Ensure ns01 hostname is present in the host.cfg file. 
# And change contact_groups name as per your configuration.

Finally reload the Nagios server and restart the nrpe service

# at nagios server
[$] systemctl reload nagios

# at nagios agent server
[$] systemctl restart nrpe

Step 04: Check service status in Nagios dashboard

Login into Nagios and search for your hostname that you configure for bandwidth monitor.

nagios agent services

nagios agent services

Now click on the setting gear icon then you will get the respective bandwidth graph

Linux Interface Bandwidth Graph

Linux Interface Bandwidth Graph

That’s it. Hope this will help.


메타데이터
post_id
111c773a3ed2
slug
linux-server-bandwidth-monitor-using-nagios-111c773a3ed2
url
https://medium.com/@zakirpcs/linux-server-bandwidth-monitor-using-nagios-111c773a3ed2
canonical_url
https://medium.com/@zakirpcs/linux-server-bandwidth-monitor-using-nagios-111c773a3ed2
author_url
https://medium.com/@zakirpcs
status
ok
fetched_at
2026-07-11 11:04:43