MARWAN docs NOC knowledge base
DocsMonitoring

Monitor a campus network with Prometheus and Grafana

Collect SNMP traffic counters from switches and routers and server metrics with Prometheus, and graph them in Grafana, all in Docker Compose on one Linux host.

Published Sami Ait Ali Oulahcen
About this guide

Based on the monitoring lab of the RIMER 2025 campus networks workshop (Nouakchott, February 2025), updated and expanded for this site in November 2026. See also the Managing campus networks slides.

What you'll build#

Almost every managed switch, router, firewall and access point speaks SNMP. Prometheus can turn those SNMP counters into time series, keep them, and alert on them. Grafana draws the graphs.

Component Job Port
Prometheus Scrapes metrics on a schedule, stores them in its time-series database, answers PromQL queries 9090
snmp_exporter Translates a Prometheus scrape into SNMP requests to a network device 9116
node_exporter Exposes CPU, memory, disk and network metrics of a Linux server 9100
Grafana Dashboards and graphs on top of Prometheus 3000
flowchart LR
  G["Grafana :3000"] -- PromQL --> P["Prometheus :9090"]
  P -- "/snmp?target=…" --> S["snmp_exporter :9116"]
  S -- "SNMP (UDP 161)" --> D["Switches, routers,<br/>firewalls, APs"]
  P -- "/metrics" --> N["node_exporter :9100<br/>on each server"]

Everything runs in Docker Compose on one Linux host. A small VM (2 vCPU, 4 GB RAM, 50 GB disk) is plenty for a campus with a few hundred devices.

Before you start#

  • A Linux host with Docker Engine and the Compose plugin (docker compose). On Debian, follow Docker's install guide. A Proxmox VE VM works well.
  • SNMP enabled on your devices, read-only, reachable from the monitoring host. Use a community string that isn't public, and restrict it to the monitoring host's address with an ACL.
  • In the examples, the monitoring host is 192.0.2.10 and the devices are 192.0.2.1 (core router) and 192.0.2.2 (distribution switch). Replace them with your own.

On a Cisco device, read-only SNMPv2c limited to the monitoring host looks like this:

Cisco IOS
ip access-list standard SNMP-RO
 permit 192.0.2.10
snmp-server community <your-community> RO SNMP-RO

Set up the folder#

mkdir -p /opt/monitoring/{prometheus,snmp-exporter,grafana/provisioning/datasources}
cd /opt/monitoring

docker-compose.yml#

/opt/monitoring/docker-compose.yml
services:
  prometheus:
    image: prom/prometheus:v3
    restart: unless-stopped
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus
      - --storage.tsdb.retention.time=400d
    volumes:
      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus-data:/prometheus
    ports:
      - "127.0.0.1:9090:9090"

  snmp-exporter:
    image: prom/snmp-exporter:v0
    restart: unless-stopped
    command:
      - --config.file=/etc/snmp_exporter/snmp.yml
      - --config.file=/etc/snmp_exporter/auth.yml
    volumes:
      - ./snmp-exporter/auth.yml:/etc/snmp_exporter/auth.yml:ro

  node-exporter:
    image: prom/node-exporter:v1
    restart: unless-stopped
    pid: host
    command:
      - --path.rootfs=/host
    volumes:
      - /:/host:ro,rslave

  grafana:
    image: grafana/grafana:13.2
    restart: unless-stopped
    environment:
      GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/grafana_admin
    secrets:
      - grafana_admin
    volumes:
      - ./grafana/provisioning:/etc/grafana/provisioning:ro
      - grafana-data:/var/lib/grafana
    ports:
      - "3000:3000"

secrets:
  grafana_admin:
    file: ./grafana/admin_password

volumes:
  prometheus-data:
  grafana-data:

Prometheus only listens on 127.0.0.1: it has no login, so people reach the data through Grafana. The exporters aren't published at all; Prometheus reaches them by service name on the Compose network. 400d keeps a bit more than a year of history, so you can compare with last year.

The SNMP community#

The snmp_exporter image ships a default snmp.yml with ready-made modules for interfaces (if_mib) and many vendors. You only add your own credentials in a second file:

/opt/monitoring/snmp-exporter/auth.yml
auths:
  campus_v2:
    version: 2
    community: <your-community>

For SNMPv3, which encrypts the exchange, use instead:

/opt/monitoring/snmp-exporter/auth.yml
auths:
  campus_v3:
    version: 3
    security_level: authPriv
    username: monitoring
    auth_protocol: SHA
    password: <auth-password>
    priv_protocol: AES
    priv_password: <priv-password>

Keep this file readable only by root (chmod 600), and keep it out of git.

prometheus.yml#

/opt/monitoring/prometheus/prometheus.yml
global:
  scrape_interval: 1m
  evaluation_interval: 1m
  external_labels:
    site: campus

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

  - job_name: node
    static_configs:
      - targets: ["node-exporter:9100"]
        labels: { host: monitoring }

  - job_name: snmp
    metrics_path: /snmp
    params:
      auth: [campus_v2]
      module: [if_mib]
    static_configs:
      - targets: ["192.0.2.1"]
        labels: { device: core-router }
      - targets: ["192.0.2.2"]
        labels: { device: dist-switch-1 }
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: snmp-exporter:9116

The relabel_configs block is the part people find confusing. Prometheus can only scrape HTTP endpoints, so each device address is passed to snmp_exporter as a target parameter, kept as the instance label, and the actual scrape goes to snmp-exporter:9116.

A one-minute interval is a good default for interface counters. Going lower adds load on the devices' CPUs without making the graphs more useful.

Grafana data source#

Let Grafana find Prometheus on its own when it starts:

/opt/monitoring/grafana/provisioning/datasources/prometheus.yml
apiVersion: 1
datasources:
  - name: Prometheus
    type: prometheus
    access: proxy
    url: http://prometheus:9090
    isDefault: true

Then set the admin password:

openssl rand -base64 18 > grafana/admin_password
chmod 600 grafana/admin_password snmp-exporter/auth.yml

Start it#

$ docker compose up -d
$ docker compose ps

Check that Prometheus reaches every target. From the monitoring host:

$ curl -s localhost:9090/api/v1/targets | grep -o '"health":"[a-z]*"' | sort | uniq -c

All targets should be up. To see the raw SNMP result for one device:

$ docker compose exec prometheus wget -qO- \
    'http://snmp-exporter:9116/snmp?target=192.0.2.1&auth=campus_v2&module=if_mib' | head

A timeout here almost always means the community, the device's SNMP ACL, or a firewall between the two.

Open Grafana at http://192.0.2.10:3000, sign in as admin with the password from grafana/admin_password, and put it behind HTTPS (a reverse proxy such as nginx) before you give the address to anyone else.

Useful queries#

Interface counters only ever go up. rate() turns them into a speed. Multiply by 8 for bits per second:

PromQL
# Inbound and outbound traffic per interface, in bit/s
rate(ifHCInOctets{device="core-router"}[5m]) * 8
rate(ifHCOutOctets{device="core-router"}[5m]) * 8

# Link use as a percentage of interface speed (ifHighSpeed is in Mbit/s)
rate(ifHCInOctets[5m]) * 8 / (ifHighSpeed * 1e6) * 100

# Interfaces that are administratively up but operationally down
ifAdminStatus == 1 and ifOperStatus != 1

# Input errors per second
rate(ifInErrors[5m]) > 0

The if_mib module adds the interface name (ifName) and description (ifAlias) as labels, so you can filter with {ifName="Gi0/1"} or use the descriptions you gave your uplinks.

Dashboards#

In Grafana, Dashboards → New → Import takes a dashboard ID from grafana.com/grafana/dashboards. Good places to start:

  • 1860, Node Exporter Full, for the Linux servers.
  • Search "SNMP interface" for ready-made switch and router dashboards built on if_mib.

A dashboard of your own, with one panel per uplink using the traffic query above, is often more useful than a large imported one.

Add more#

  • More servers: run node_exporter on each server (it's packaged as prometheus-node-exporter in Debian and Ubuntu) and add server:9100 to the node job.
  • Vendor details: the default snmp.yml has modules for Cisco, Juniper, Arista, MikroTik, APC and others. Add them next to if_mib, for example module: [if_mib, cisco_device]. Look for the module names in the default snmp.yml.
  • Alerts: add rule files to Prometheus and an Alertmanager to send email or chat messages, for example when an uplink goes down or runs above 80% for 15 minutes.
  • Proxmox: the Proxmox VE exporter exposes nodes, VMs and storage the same way.

Upgrades and backups#

$ cd /opt/monitoring
$ docker compose pull
$ docker compose up -d

The image tags (v3, v0, v1, 13.2) follow major or minor versions, so pull brings bug and security fixes without surprise major upgrades. Back up /opt/monitoring and the two named volumes (prometheus-data, grafana-data); Grafana's volume holds your dashboards and users.