Learn to set up a comprehensive SNMP monitoring solution using InfluxDB 2.7 for time-series storage and Telegraf for data collection. Configure monitoring for network devices, system metrics, and create visualization dashboards with Grafana.
Prerequisites
- Root or sudo access
- Network devices with SNMP enabled
- At least 4GB RAM
- Basic understanding of networking concepts
- Familiarity with time-series databases
What this solves
SNMP (Simple Network Management Protocol) monitoring provides essential visibility into network devices, servers, and infrastructure components. This tutorial shows you how to build a production-grade monitoring stack using InfluxDB 2.7 for time-series data storage, Telegraf for SNMP data collection, and Grafana for visualization. You'll learn to monitor network interfaces, system resources, and custom OIDs across your infrastructure.
Step-by-step installation
Update system packages
Start by updating your package manager to ensure you get the latest versions of dependencies.
sudo apt update && sudo apt upgrade -y
sudo apt install -y wget curl gnupg2 software-properties-common apt-transport-https
Install InfluxDB 2.7
Add the InfluxData repository and install InfluxDB 2.7 for time-series data storage.
wget -qO- https://repos.influxdata.com/influxdata-archive_compat.key | sudo apt-key add -
echo "deb https://repos.influxdata.com/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt update
sudo apt install -y influxdb2
Configure InfluxDB service
Enable and start InfluxDB, then configure the initial setup through the web interface.
sudo systemctl enable --now influxdb
sudo systemctl status influxdb
Open your web browser and navigate to http://your-server-ip:8086 to complete the initial setup. Create your organization, bucket, and obtain the API token.
Install Telegraf
Install Telegraf to collect SNMP metrics and send them to InfluxDB.
sudo apt install -y telegraf snmp snmp-mibs-downloader
Configure Telegraf for SNMP monitoring
Create a comprehensive Telegraf configuration that includes SNMP inputs and InfluxDB output. This configuration monitors network interfaces, system resources, and custom metrics.
# Global Agent Configuration
[agent]
interval = "30s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
precision = ""
hostname = ""
omit_hostname = false
InfluxDB v2 Output Plugin
[[outputs.influxdb_v2]]
urls = ["http://localhost:8086"]
token = "your-influxdb-token-here"
organization = "your-org"
bucket = "snmp-metrics"
timeout = "5s"
SNMP Plugin for Network Interfaces
[[inputs.snmp]]
agents = ["192.168.1.1:161", "192.168.1.2:161"]
version = 2
community = "public"
name = "network_interfaces"
timeout = "5s"
retries = 3
# Interface Statistics
[[inputs.snmp.field]]
name = "hostname"
oid = "1.3.6.1.2.1.1.5.0"
is_tag = true
[[inputs.snmp.table]]
name = "interface"
inherit_tags = ["hostname"]
oid = "1.3.6.1.2.1.2.2"
[[inputs.snmp.table.field]]
name = "name"
oid = "1.3.6.1.2.1.2.2.1.2"
is_tag = true
[[inputs.snmp.table.field]]
name = "type"
oid = "1.3.6.1.2.1.2.2.1.3"
[[inputs.snmp.table.field]]
name = "speed"
oid = "1.3.6.1.2.1.2.2.1.5"
[[inputs.snmp.table.field]]
name = "admin_status"
oid = "1.3.6.1.2.1.2.2.1.7"
[[inputs.snmp.table.field]]
name = "oper_status"
oid = "1.3.6.1.2.1.2.2.1.8"
[[inputs.snmp.table.field]]
name = "in_octets"
oid = "1.3.6.1.2.1.2.2.1.10"
conversion = "float"
[[inputs.snmp.table.field]]
name = "out_octets"
oid = "1.3.6.1.2.1.2.2.1.16"
conversion = "float"
[[inputs.snmp.table.field]]
name = "in_errors"
oid = "1.3.6.1.2.1.2.2.1.14"
[[inputs.snmp.table.field]]
name = "out_errors"
oid = "1.3.6.1.2.1.2.2.1.20"
SNMP Plugin for System Resources
[[inputs.snmp]]
agents = ["192.168.1.1:161", "192.168.1.2:161"]
version = 2
community = "public"
name = "system_resources"
timeout = "5s"
retries = 3
[[inputs.snmp.field]]
name = "hostname"
oid = "1.3.6.1.2.1.1.5.0"
is_tag = true
[[inputs.snmp.field]]
name = "uptime"
oid = "1.3.6.1.2.1.1.3.0"
conversion = "float"
[[inputs.snmp.field]]
name = "cpu_usage"
oid = "1.3.6.1.4.1.2021.11.9.0"
conversion = "float"
[[inputs.snmp.field]]
name = "memory_total"
oid = "1.3.6.1.4.1.2021.4.5.0"
conversion = "float"
[[inputs.snmp.field]]
name = "memory_free"
oid = "1.3.6.1.4.1.2021.4.6.0"
conversion = "float"
[[inputs.snmp.field]]
name = "disk_usage"
oid = "1.3.6.1.4.1.2021.9.1.9.1"
conversion = "float"
Configure SNMP community and security
Update the Telegraf configuration with your actual SNMP settings. Replace the placeholder values with your network configuration.
sudo cp /etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf.backup
sudo nano /etc/telegraf/telegraf.conf
Install and configure Grafana
Install Grafana for creating dashboards and visualizing SNMP metrics from InfluxDB.
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
Enable and start all services
Start Telegraf and Grafana services and ensure they start automatically on boot.
sudo systemctl enable --now telegraf
sudo systemctl enable --now grafana-server
sudo systemctl status telegraf grafana-server
Configure firewall rules
Open the necessary ports for InfluxDB (8086) and Grafana (3000) web interfaces.
sudo ufw allow 8086/tcp comment "InfluxDB"
sudo ufw allow 3000/tcp comment "Grafana"
sudo ufw reload
Configure Grafana data source
Access Grafana at http://your-server-ip:3000 (admin/admin) and add InfluxDB as a data source. Use the following settings for the InfluxDB connection.
URL: http://localhost:8086
Database: (leave empty for InfluxDB 2.x)
Organization: your-org
Token: your-influxdb-token-here
Default Bucket: snmp-metrics
Create SNMP monitoring dashboard
Import or create a dashboard for SNMP metrics. Here's a sample query for network interface traffic monitoring.
from(bucket: "snmp-metrics")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "interface")
|> filter(fn: (r) => r["_field"] == "in_octets" or r["_field"] == "out_octets")
|> derivative(unit: 1s, nonNegative: true)
|> map(fn: (r) => ({ r with _value: r._value * 8.0 }))
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: "mean")
Configure advanced SNMP monitoring
Add custom OID monitoring
Extend your Telegraf configuration to monitor custom OIDs specific to your equipment. This example shows how to add vendor-specific metrics.
# Custom OID monitoring for specific devices
[[inputs.snmp]]
agents = ["192.168.1.10:161"]
version = 2
community = "monitoring"
name = "custom_metrics"
timeout = "10s"
retries = 3
# Custom temperature monitoring (example Cisco OID)
[[inputs.snmp.field]]
name = "device_name"
oid = "1.3.6.1.2.1.1.5.0"
is_tag = true
[[inputs.snmp.field]]
name = "temperature"
oid = "1.3.6.1.4.1.9.9.13.1.3.1.3.1"
conversion = "float"
# Power supply status
[[inputs.snmp.field]]
name = "power_status"
oid = "1.3.6.1.4.1.9.9.13.1.5.1.3.1"
# Fan speed monitoring
[[inputs.snmp.field]]
name = "fan_speed"
oid = "1.3.6.1.4.1.9.9.13.1.4.1.3.1"
conversion = "float"
Configure SNMP v3 authentication
For production environments, configure SNMPv3 with authentication and privacy for secure monitoring.
[[inputs.snmp]]
agents = ["192.168.1.1:161"]
version = 3
timeout = "5s"
retries = 3
# SNMPv3 Authentication
sec_name = "monitoring_user"
auth_protocol = "SHA"
auth_password = "strong_auth_password"
sec_level = "authPriv"
priv_protocol = "AES"
priv_password = "strong_priv_password"
name = "secure_monitoring"
[[inputs.snmp.field]]
name = "hostname"
oid = "1.3.6.1.2.1.1.5.0"
is_tag = true
Set up alerting rules
Configure InfluxDB alerts or Grafana alerts to notify you of critical SNMP metrics. This example shows setting up a high CPU usage alert.
sudo systemctl restart telegraf
sudo journalctl -u telegraf -f
Verify your setup
Check that all services are running correctly and collecting data.
# Verify all services are running
sudo systemctl status influxdb telegraf grafana-server
Check Telegraf is collecting SNMP data
sudo journalctl -u telegraf --since "5 minutes ago" | grep -i snmp
Test SNMP connectivity manually
snmpwalk -v2c -c public 192.168.1.1 1.3.6.1.2.1.1.5.0
Check InfluxDB data ingestion
curl -H "Authorization: Token your-token" "http://localhost:8086/api/v2/query?org=your-org" \
-d 'from(bucket:"snmp-metrics") |> range(start: -1h) |> limit(n:10)'
Verify Grafana is accessible
curl -s http://localhost:3000/api/health
Performance optimization
Optimize data retention
Configure appropriate data retention policies in InfluxDB to manage storage usage for time-series data.
# Create retention policy for SNMP data (30 days)
influx bucket create \
--name snmp-metrics-30d \
--org your-org \
--retention 720h \
--token your-token
Create downsampling task for long-term storage
influx task create \
--org your-org \
--token your-token \
--file downsample-task.flux
Configure collection intervals
Adjust Telegraf collection intervals based on your monitoring requirements and network capacity.
# High-frequency monitoring for critical interfaces
[[inputs.snmp]]
agents = ["192.168.1.1:161"]
interval = "10s"
# ... interface configuration
Standard monitoring for general metrics
[[inputs.snmp]]
agents = ["192.168.1.2:161", "192.168.1.3:161"]
interval = "60s"
# ... system configuration
Common issues
| Symptom | Cause | Fix |
|---|---|---|
| SNMP timeout errors | Network connectivity or wrong community string | Test with snmpwalk -v2c -c public target-ip 1.3.6.1.2.1.1.1.0 |
| No data in InfluxDB | Wrong token or organization name | Verify token with influx auth list and check Telegraf logs |
| Telegraf startup fails | Configuration syntax error | Test config with telegraf --config /etc/telegraf/telegraf.conf --test |
| High memory usage | Too many metrics or short intervals | Increase intervals, reduce OID count, or add metric filtering |
| Missing MIB information | MIB files not installed | Install with sudo apt install snmp-mibs-downloader and update /etc/snmp/snmp.conf |
| Grafana connection failed | Wrong InfluxDB URL or credentials | Test connection from Grafana data source configuration page |
Next steps
- Set up Prometheus and Grafana monitoring stack with Docker compose for container-based monitoring
- Configure network interface monitoring with ICMP ping and connectivity testing for network health monitoring
- Configure InfluxDB clustering for high availability for production scalability
- Set up Telegraf custom plugins for application monitoring to extend monitoring capabilities
- Implement Grafana alerting with Prometheus and InfluxDB for comprehensive alerting
Automated install script
Run this to automate the entire setup
#!/usr/bin/env bash
set -euo pipefail
# Colors
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[1;33m'
readonly NC='\033[0m'
# Configuration
INFLUX_ORG="${INFLUX_ORG:-monitoring}"
INFLUX_BUCKET="${INFLUX_BUCKET:-telegraf}"
INFLUX_USERNAME="${INFLUX_USERNAME:-admin}"
INFLUX_PASSWORD="${INFLUX_PASSWORD:-$(openssl rand -base64 32)}"
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
cleanup() {
log_error "Installation failed. Cleaning up..."
systemctl stop influxdb telegraf grafana-server 2>/dev/null || true
}
trap cleanup ERR
usage() {
cat << EOF
Usage: $0 [OPTIONS]
Install SNMP monitoring with InfluxDB and Telegraf
Options:
-o, --org NAME InfluxDB organization name (default: monitoring)
-b, --bucket NAME InfluxDB bucket name (default: telegraf)
-u, --username NAME InfluxDB admin username (default: admin)
-p, --password PASS InfluxDB admin password (auto-generated if not set)
-h, --help Show this help message
Example:
$0 --org mycompany --bucket snmp-metrics
EOF
}
while [[ $# -gt 0 ]]; do
case $1 in
-o|--org) INFLUX_ORG="$2"; shift 2 ;;
-b|--bucket) INFLUX_BUCKET="$2"; shift 2 ;;
-u|--username) INFLUX_USERNAME="$2"; shift 2 ;;
-p|--password) INFLUX_PASSWORD="$2"; shift 2 ;;
-h|--help) usage; exit 0 ;;
*) log_error "Unknown option: $1"; usage; exit 1 ;;
esac
done
# Check prerequisites
if [[ $EUID -ne 0 ]]; then
log_error "This script must be run as root"
exit 1
fi
# Detect distribution
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
ubuntu|debian)
PKG_MGR="apt"
PKG_INSTALL="apt install -y"
PKG_UPDATE="apt update && apt upgrade -y"
FIREWALL_CMD="ufw"
;;
almalinux|rocky|centos|rhel|ol|fedora)
PKG_MGR="dnf"
PKG_INSTALL="dnf install -y"
PKG_UPDATE="dnf update -y"
FIREWALL_CMD="firewall-cmd"
;;
amzn)
PKG_MGR="yum"
PKG_INSTALL="yum install -y"
PKG_UPDATE="yum update -y"
FIREWALL_CMD="firewall-cmd"
;;
*) log_error "Unsupported distro: $ID"; exit 1 ;;
esac
else
log_error "Cannot detect distribution"
exit 1
fi
log_info "[1/8] Updating system packages"
$PKG_UPDATE
if [[ "$PKG_MGR" == "apt" ]]; then
$PKG_INSTALL wget curl gnupg2 software-properties-common apt-transport-https snmp-utils
else
$PKG_INSTALL wget curl gnupg2 yum-utils net-snmp-utils
fi
log_info "[2/8] Installing InfluxDB 2.7"
if [[ "$PKG_MGR" == "apt" ]]; then
wget -qO- https://repos.influxdata.com/influxdata-archive_compat.key | apt-key add -
echo "deb https://repos.influxdata.com/ubuntu $(lsb_release -cs) stable" > /etc/apt/sources.list.d/influxdb.list
apt update
$PKG_INSTALL influxdb2
else
cat > /etc/yum.repos.d/influxdb.repo << 'EOF'
[influxdb]
name = InfluxDB Repository
baseurl = https://repos.influxdata.com/rhel/$releasever/$basearch/stable/
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdata-archive_compat.key
EOF
$PKG_INSTALL influxdb2
fi
systemctl enable influxdb
systemctl start influxdb
log_info "[3/8] Installing Telegraf"
if [[ "$PKG_MGR" == "apt" ]]; then
$PKG_INSTALL telegraf
else
$PKG_INSTALL telegraf
fi
log_info "[4/8] Installing Grafana"
if [[ "$PKG_MGR" == "apt" ]]; then
wget -q -O - https://packages.grafana.com/gpg.key | apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" > /etc/apt/sources.list.d/grafana.list
apt update
$PKG_INSTALL grafana
else
cat > /etc/yum.repos.d/grafana.repo << 'EOF'
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
EOF
$PKG_INSTALL grafana
fi
systemctl enable grafana-server
systemctl start grafana-server
log_info "[5/8] Configuring InfluxDB"
sleep 10
INFLUX_TOKEN=$(influx setup \
--username "$INFLUX_USERNAME" \
--password "$INFLUX_PASSWORD" \
--org "$INFLUX_ORG" \
--bucket "$INFLUX_BUCKET" \
--force 2>/dev/null | grep -o 'token: .*' | cut -d' ' -f2 || echo "")
if [[ -z "$INFLUX_TOKEN" ]]; then
INFLUX_TOKEN=$(influx auth list --json 2>/dev/null | grep -o '"token":"[^"]*"' | cut -d'"' -f4 | head -1)
fi
if [[ -z "$INFLUX_TOKEN" ]]; then
log_error "Failed to get InfluxDB token"
exit 1
fi
log_info "[6/8] Configuring Telegraf"
cat > /etc/telegraf/telegraf.conf << EOF
[global_tags]
[agent]
interval = "60s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
precision = ""
hostname = ""
omit_hostname = false
[[outputs.influxdb_v2]]
urls = ["http://localhost:8086"]
token = "$INFLUX_TOKEN"
organization = "$INFLUX_ORG"
bucket = "$INFLUX_BUCKET"
[[inputs.snmp]]
agents = ["localhost:161"]
version = 2
community = "public"
interval = "60s"
timeout = "10s"
retries = 3
[[inputs.snmp.field]]
name = "hostname"
oid = "1.3.6.1.2.1.1.5.0"
is_tag = true
[[inputs.snmp.field]]
name = "uptime"
oid = "1.3.6.1.2.1.1.3.0"
[[inputs.snmp.table]]
name = "interface"
inherit_tags = ["hostname"]
oid = "1.3.6.1.2.1.2.2"
[[inputs.snmp.table.field]]
name = "ifIndex"
oid = "1.3.6.1.2.1.2.2.1.1"
is_tag = true
[[inputs.snmp.table.field]]
name = "ifDescr"
oid = "1.3.6.1.2.1.2.2.1.2"
is_tag = true
[[inputs.snmp.table.field]]
name = "ifInOctets"
oid = "1.3.6.1.2.1.2.2.1.10"
[[inputs.snmp.table.field]]
name = "ifOutOctets"
oid = "1.3.6.1.2.1.2.2.1.16"
EOF
chown telegraf:telegraf /etc/telegraf/telegraf.conf
chmod 640 /etc/telegraf/telegraf.conf
systemctl enable telegraf
systemctl start telegraf
log_info "[7/8] Configuring firewall"
if command -v ufw >/dev/null; then
ufw --force enable
ufw allow 8086/tcp comment "InfluxDB"
ufw allow 3000/tcp comment "Grafana"
ufw allow 161/udp comment "SNMP"
elif command -v firewall-cmd >/dev/null; then
systemctl enable firewalld
systemctl start firewalld
firewall-cmd --permanent --add-port=8086/tcp
firewall-cmd --permanent --add-port=3000/tcp
firewall-cmd --permanent --add-port=161/udp
firewall-cmd --reload
fi
log_info "[8/8] Verifying installation"
sleep 5
if ! curl -s http://localhost:8086/health | grep -q '"status":"pass"'; then
log_error "InfluxDB health check failed"
exit 1
fi
if ! curl -s http://localhost:3000/api/health | grep -q '"database":"ok"'; then
log_warn "Grafana may still be starting up"
fi
if ! systemctl is-active --quiet telegraf; then
log_error "Telegraf is not running"
exit 1
fi
log_info "Installation completed successfully!"
echo
echo "InfluxDB: http://localhost:8086"
echo "Grafana: http://localhost:3000 (admin/admin)"
echo "Organization: $INFLUX_ORG"
echo "Bucket: $INFLUX_BUCKET"
echo "Token: $INFLUX_TOKEN"
echo
echo "To add SNMP devices, edit /etc/telegraf/telegraf.conf and restart telegraf"
Review the script before running. Execute with: bash install.sh