How to Install and Configure Prometheus SNMP Exporter

karneliuk.com/2023/01/to...

Here’s a visual overview of how the Prometheus SNMP Exporter fits into your monitoring stack—acting as the bridge between Prometheus and SNMP-enabled devices.


How to Install and Configure Prometheus SNMP Exporter

If you want to monitor network devices like routers, switches, and firewalls via SNMP using Prometheus, here’s a complete step-by-step guide:


1. Download and Install the Exporter

  • Visit the GitHub Releases page for snmp_exporter to fetch the appropriate binary for your system. (sbcode.net, GitHub)
  • Example: wget https://github.com/prometheus/snmp_exporter/releases/download/v0.19.0/snmp_exporter-0.19.0.linux-amd64.tar.gz tar xzf snmp_exporter-0.19.0.linux-amd64.tar.gz
  • Copy the executable and sample config: sudo cp snmp_exporter /usr/local/bin/ sudo cp snmp.yml /usr/local/bin/

2. Run via Systemd

Create a dedicated user (if not already present):

sudo useradd --system prometheus

Create a systemd service unit (/etc/systemd/system/snmp-exporter.service):

[Unit]
Description=Prometheus SNMP Exporter Service
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/bin/snmp_exporter --config.file="/usr/local/bin/snmp.yml"

[Install]
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable snmp-exporter
sudo systemctl start snmp-exporter

Verify it’s running and accessible (default port is 9116):

curl http://localhost:9116
``` :contentReference[oaicite:2]{index=2}

---

### 3. **(Optional) Alternative Setup – from Workshops**

A more managed approach often seen in educational or institutional deployments involves:

1. Placing the exporter under `/opt` and symlinking for version control  
2. Using an options file (e.g., `/etc/default/snmp_exporter`) to pass flags like `--config.file` and `--web.listen-address`  
3. Keeping config under `/etc/prometheus/snmp/snmp.yml`  
4. Starting and enabling via systemd similarly as above :contentReference[oaicite:3]{index=3}

---

### 4. **Configure the Exporter (`snmp.yml`)**

- The `snmp.yml` maps SNMP OIDs to meaningful Prometheus metrics using modules.
- You can customize modules like `if_mib` or create a new one such as `if_mib_v3` for SNMPv3:
  ```yaml
  if_mib_v3:
    <<: *if_mib
    version: 3
    timeout: 3s
    retries: 3
    auth:
      security_level: authNoPriv
      username: admin
      password: your_password
      auth_protocol: SHA
  • Then reload the exporter to apply changes: sudo systemctl reload snmp-exporter ``` :contentReference[oaicite:4]{index=4}
  • For a more automated workflow, use the generator to parse MIB files and produce a tailored snmp.yml—especially helpful if you’re dealing with vendor-specific or complex OIDs. (Grafana Labs, performance-monitoring-with-prometheus.readthedocs.io)

5. Add SNMP Targets to Prometheus

Configure your prometheus.yml to scrape via the SNMP exporter:

- job_name: 'snmp'
  metrics_path: /snmp
  params:
    module: [if_mib]
  static_configs:
    - targets:
      - 192.168.1.1  # Your SNMP device IP
  relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: 127.0.0.1:9116  # SNMP exporter host:port

After editing:

promtool check config /etc/prometheus/prometheus.yml
sudo systemctl restart prometheus
``` :contentReference[oaicite:6]{index=6}

---

### 6. **(Optional) Use Docker or Kubernetes**

- **Docker**: some guides (e.g., Grafana's network monitoring tutorial) suggest containerizing both the exporter and generator for easier deployment. :contentReference[oaicite:7]{index=7}
- **Kubernetes**: You can deploy using a Helm chart, such as `prometheus-snmp-exporter`, which simplifies managing versions and configurations. :contentReference[oaicite:8]{index=8}

---

##  Summary at a Glance

| Step | Action |
|------|--------|
| 1. | Download and unpack snmp_exporter |
| 2. | Install binary and default config |
| 3. | Set up systemd service for automation |
| 4. | Edit `snmp.yml` or generate config via generator |
| 5. | Add job to `prometheus.yml` and reload Prometheus |
| 6. | (Optional) Use Docker or Helm for container-based deployment |

---

Let me know if you'd like help with SNMPv3 credentials, creating a `generator.yml`, or building Grafana dashboards to visualize your SNMP metrics!
::contentReference[oaicite:9]{index=9}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *