Configure network monitoring with SNMP and Grafana dashboards for infrastructure visibility

Intermediate 45 min Apr 05, 2026 88 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up comprehensive network monitoring using SNMP with Prometheus and Grafana to monitor network devices, collect performance metrics, and create visual dashboards for infrastructure visibility.

Prerequisites

  • Root or sudo access
  • Network devices with SNMP enabled
  • At least 2GB RAM
  • Basic understanding of networking concepts

What this solves

Network monitoring with SNMP provides real-time visibility into your network infrastructure, allowing you to track device performance, bandwidth utilization, and system health across switches, routers, and servers. This tutorial shows you how to configure Net-SNMP, integrate it with Prometheus using snmp_exporter, and create comprehensive Grafana dashboards for network device monitoring.

Step-by-step installation

Update system packages

Start by updating your package manager to ensure you get the latest versions of all components.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install Net-SNMP daemon and tools

Install the SNMP daemon and utilities that will handle SNMP requests and provide monitoring data.

sudo apt install -y snmp snmpd snmp-mibs-downloader
sudo dnf install -y net-snmp net-snmp-utils net-snmp-libs

Configure Net-SNMP daemon

Create a secure SNMP configuration with community strings and access controls. This configuration enables monitoring while maintaining security.

# Basic SNMP configuration for network monitoring

Community string configuration

rocommunity monitoring_read default -V systemonly rocommunity6 monitoring_read default -V systemonly

System information

sysLocation Network Operations Center sysContact admin@example.com sysServices 72

Process monitoring

proc sshd proc cron proc rsyslog

Disk monitoring

disk / 10000 disk /var 5000

Load monitoring

load 12 10 5

Network interface monitoring

interface eth0 interface lo

Enable AgentX for extending functionality

master agentx agentXSocket tcp:localhost:705

Access control

view systemonly included .1.3.6.1.2.1.1 view systemonly included .1.3.6.1.2.1.25.1 view systemonly included .1.3.6.1.2.1.2 view systemonly included .1.3.6.1.2.1.3 view systemonly included .1.3.6.1.2.1.4 view systemonly included .1.3.6.1.2.1.6 view systemonly included .1.3.6.1.2.1.10

Configure SNMP v3 security

Set up SNMPv3 with authentication and encryption for secure monitoring. This provides better security than community strings.

sudo systemctl stop snmpd
sudo net-snmp-create-v3-user -ro -A monitoring123! -X encryption456! -a SHA -x AES monitoruser

Add the v3 configuration to the SNMP daemon config:

# SNMPv3 configuration (append to existing config)
rouser monitoruser

v3 access control

group MyROGroup v3 monitoruser view all included .1 80 access MyROGroup "" any auth exact all none none

Install Prometheus

Download and install Prometheus to collect metrics from the SNMP exporter.

cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v2.48.0/prometheus-2.48.0.linux-amd64.tar.gz
tar -xzf prometheus-2.48.0.linux-amd64.tar.gz
sudo mv prometheus-2.48.0.linux-amd64/prometheus /usr/local/bin/
sudo mv prometheus-2.48.0.linux-amd64/promtool /usr/local/bin/
sudo mkdir -p /etc/prometheus /var/lib/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus
sudo useradd --no-create-home --shell /bin/false prometheus

Install SNMP Exporter

Download and configure the Prometheus SNMP exporter to bridge SNMP data into Prometheus metrics format.

cd /tmp
wget https://github.com/prometheus/snmp_exporter/releases/download/v0.24.1/snmp_exporter-0.24.1.linux-amd64.tar.gz
tar -xzf snmp_exporter-0.24.1.linux-amd64.tar.gz
sudo mv snmp_exporter-0.24.1.linux-amd64/snmp_exporter /usr/local/bin/
sudo mkdir -p /etc/snmp_exporter
sudo useradd --no-create-home --shell /bin/false snmp_exporter

Configure SNMP Exporter

Create configuration for the SNMP exporter to define how it should query SNMP devices and which metrics to collect.

auths:
  public_v2:
    community: monitoring_read
    security_level: noAuthNoPriv
    auth_protocol: MD5
    priv_protocol: DES
    version: 2
  
  secure_v3:
    username: monitoruser
    security_level: authPriv
    auth_protocol: SHA
    auth_password: monitoring123!
    priv_protocol: AES
    priv_password: encryption456!
    version: 3

modules:
  if_mib:
    walk:
    - 1.3.6.1.2.1.2.2.1.2   # ifDescr
    - 1.3.6.1.2.1.2.2.1.3   # ifType
    - 1.3.6.1.2.1.2.2.1.5   # ifSpeed
    - 1.3.6.1.2.1.2.2.1.8   # ifOperStatus
    - 1.3.6.1.2.1.2.2.1.10  # ifInOctets
    - 1.3.6.1.2.1.2.2.1.16  # ifOutOctets
    - 1.3.6.1.2.1.2.2.1.14  # ifInErrors
    - 1.3.6.1.2.1.2.2.1.20  # ifOutErrors
    
  system_mib:
    walk:
    - 1.3.6.1.2.1.1.1.0     # sysDescr
    - 1.3.6.1.2.1.1.3.0     # sysUpTime
    - 1.3.6.1.2.1.25.1.1.0  # hrSystemUptime
    - 1.3.6.1.2.1.25.2.2    # hrMemorySize
    - 1.3.6.1.2.1.25.3.3.1.2 # hrProcessorLoad

Create systemd service files

Set up systemd services for both Prometheus and SNMP exporter to manage them as system services.

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
    --config.file /etc/prometheus/prometheus.yml \
    --storage.tsdb.path /var/lib/prometheus/ \
    --web.console.templates=/etc/prometheus/consoles \
    --web.console.libraries=/etc/prometheus/console_libraries \
    --web.listen-address=0.0.0.0:9090 \
    --web.enable-lifecycle

[Install]
WantedBy=multi-user.target
[Unit]
Description=SNMP Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=snmp_exporter
Group=snmp_exporter
Type=simple
ExecStart=/usr/local/bin/snmp_exporter --config.file=/etc/snmp_exporter/snmp.yml
Restart=always

[Install]
WantedBy=multi-user.target

Configure Prometheus to scrape SNMP targets

Set up Prometheus configuration to collect metrics from SNMP devices through the exporter.

global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'snmp_exporter'
    static_configs:
      - targets: ['localhost:9116']

  - job_name: 'snmp_devices_if_mib'
    static_configs:
      - targets:
        - 203.0.113.10  # Network switch
        - 203.0.113.11  # Router
        - 203.0.113.12  # Server
    metrics_path: /snmp
    params:
      module: [if_mib]
      auth: [public_v2]
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: localhost:9116

  - job_name: 'snmp_devices_system_mib'
    static_configs:
      - targets:
        - 203.0.113.10
        - 203.0.113.11
        - 203.0.113.12
    metrics_path: /snmp
    params:
      module: [system_mib]
      auth: [secure_v3]
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: localhost:9116

Install Grafana

Install Grafana to create visual dashboards for your SNMP monitoring data.

wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install -y grafana
sudo dnf install -y https://dl.grafana.com/oss/release/grafana-10.2.0-1.x86_64.rpm

Set correct permissions

Ensure all configuration files have the correct ownership and permissions for security and functionality.

Never use chmod 777. It gives every user on the system full access to your files. Instead, fix ownership with chown and use minimal permissions.
sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus
sudo chown -R snmp_exporter:snmp_exporter /etc/snmp_exporter
sudo chmod 644 /etc/prometheus/prometheus.yml
sudo chmod 644 /etc/snmp_exporter/snmp.yml
sudo chmod 640 /etc/snmp/snmpd.conf
sudo chown root:snmp /etc/snmp/snmpd.conf

Start and enable all services

Enable and start all monitoring services to begin collecting SNMP data.

sudo systemctl daemon-reload
sudo systemctl enable --now snmpd
sudo systemctl enable --now snmp_exporter
sudo systemctl enable --now prometheus
sudo systemctl enable --now grafana-server

Configure firewall rules

Open the necessary ports for SNMP monitoring and web interfaces while maintaining security.

sudo ufw allow 161/udp comment 'SNMP'
sudo ufw allow 9090/tcp comment 'Prometheus'
sudo ufw allow 9116/tcp comment 'SNMP Exporter'
sudo ufw allow 3000/tcp comment 'Grafana'
sudo ufw reload
sudo firewall-cmd --permanent --add-port=161/udp
sudo firewall-cmd --permanent --add-port=9090/tcp
sudo firewall-cmd --permanent --add-port=9116/tcp
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload

Configure Grafana data source

Add Prometheus as a data source in Grafana to enable dashboard creation. Access Grafana at http://your-server:3000 with admin/admin credentials.

Name: Prometheus-SNMP
Type: Prometheus
URL: http://localhost:9090
Access: Server (default)
Scrape interval: 15s

Create network monitoring dashboard

Import or create a comprehensive dashboard for network device monitoring. This configuration provides key network metrics visualization.

# Network Interface Traffic (bytes/sec)
rate(ifInOctets[5m]) * 8

Interface Status

ifOperStatus

Interface Errors Rate

rate(ifInErrors[5m])

System Uptime

sysUpTime / 100

Verify your setup

Test your SNMP monitoring configuration to ensure all components are working correctly.

sudo systemctl status snmpd
sudo systemctl status snmp_exporter
sudo systemctl status prometheus
sudo systemctl status grafana-server
# Test SNMP v2c query
snmpwalk -v2c -c monitoring_read localhost 1.3.6.1.2.1.1.1.0

Test SNMP v3 query

snmpwalk -v3 -u monitoruser -l authPriv -a SHA -A monitoring123! -x AES -X encryption456! localhost 1.3.6.1.2.1.1.1.0
# Check Prometheus targets
curl http://localhost:9090/api/v1/targets

Test SNMP exporter

curl 'http://localhost:9116/snmp?target=localhost&module=if_mib&auth=public_v2'

You can also explore the monitoring setup by linking to our related HAProxy and Consul monitoring tutorial for additional Prometheus and Grafana configuration examples.

Common issues

Symptom Cause Fix
SNMP queries timeout Community string mismatch or firewall blocking Check community string in config and verify port 161/udp is open
SNMPv3 authentication fails Incorrect credentials or protocol mismatch Verify username, passwords, and auth/priv protocols match exactly
Prometheus shows SNMP targets as down SNMP exporter configuration or network connectivity Test SNMP exporter endpoint directly and check target reachability
Grafana shows no data Prometheus data source misconfiguration Verify Prometheus URL in Grafana and check query syntax
Permission denied errors Incorrect file ownership or service user permissions Use chown to set correct ownership, never use chmod 777
High CPU usage on monitored devices Too frequent SNMP polling Increase scrape_interval in Prometheus configuration to 30s or 60s

Next steps

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed devops services for businesses that depend on uptime. From initial setup to ongoing operations.