Monitoring MikroTik routers and GPON OLTs with Prometheus, Grafana and Telegram alerts
Every ISP dashboard I have inherited started the same way: a ping check per customer, a green dot when the reply came back, and a support ticket when it did not. That works until it doesn't. Ping tells you a device answered. It does not tell you the optical receiver is at -27 dBm, the uplink is at 94% utilisation for six hours, or the router rebooted twice last night and came back before the next poll.
This is the monitoring stack I actually run for a small ISP on a single 4 vCPU VPS: snmp_exporter to collect, Prometheus to store, Alertmanager to decide what deserves a human, and Telegram as the pager. It covers MikroTik routers, a ZTE C320 GPON OLT, and the Linux boxes in between. Nothing here needs a vendor platform or a per-device licence.
Why ping-only monitoring fails
Three failure classes account for most of the outages I have handled, and none of them show up in an ICMP check:
- Degraded optical links. An ONU at -26.8 dBm still replies to ping. It starts dropping packets under load an hour later, and the customer calls before any alert fires.
- Saturation. A 100 Mbit backhaul at 95% for an afternoon is "up" the entire time and produces complaints that look like random slowness.
- Fast reboots. RouterOS that restarts and returns within 40 seconds is invisible to a 60-second ping poll. The only trace is sysUpTime going backwards and a burst of PPPoE reconnects.
All three are visible in SNMP counters that are cheap to collect: interface octets, operational status, optical receive level, and uptime.
Architecture
RouterOS / OLT ──SNMP──▶ snmp_exporter ──▶ Prometheus ──▶ Alertmanager ──▶ Telegram
│ ▲
└──SSH CLI (ONU optical)──▶ python collector ──textfile──▶ node_exporter
Two collection paths, on purpose. SNMP handles everything that is exposed as a scalar or table. The OLT's per-ONU optical values are easier to read from the CLI than from the vendor MIB, so a small Python script parses them and writes a Prometheus textfile that node_exporter picks up. Both end up in the same database, so alerting and dashboards do not care where a metric came from.
Step 1 — Enable SNMP on RouterOS
Read-only, restricted to the monitoring host. If you are still on SNMPv2c, at least bind the community to one address:
/snmp set enabled=yes contact="[email protected]" location="Banyuwangi-POP1"
/snmp community add name=monitor addresses=10.20.0.5/32
/ip firewall filter add chain=input protocol=udp dst-port=161 \
src-address=10.20.0.5 action=accept place-before=1 comment="snmp monitor"
On RouterOS 7 I prefer SNMPv3 with auth and privacy, which removes the "community string in a config file" problem entirely:
/snmp user add name=monitor group=read \
authentication-protocol=SHA1 authentication-password="…" \
encryption-protocol=AES encryption-password="…"
/snmp set enabled=yes
Verify from the monitoring host before touching any config file. If this fails, everything downstream is wasted effort:
snmpwalk -v3 -l authPriv -u monitor -a SHA -A '…' -x AES -X '…' \
10.20.0.1 1.3.6.1.2.1.1.3.0 # sysUpTime
snmpwalk -v3 -l authPriv -u monitor -a SHA -A '…' -x AES -X '…' \
10.20.0.1 1.3.6.1.2.1.31.1.1.1.6 # ifHCInOctets, one row per interface
Step 2 — snmp_exporter with the generator
Hand-writing SNMP mappings is how people give up. snmp_exporter ships a generator: you give it a YAML walk list, it produces the module. This is the core of my generator.yml:
modules:
routeros:
walk:
- 1.3.6.1.2.1.1.3 # sysUpTime
- 1.3.6.1.2.1.2.2.1.8 # ifOperStatus
- 1.3.6.1.2.1.31.1.1.1.6 # ifHCInOctets
- 1.3.6.1.2.1.31.1.1.1.10 # ifHCOutOctets
- 1.3.6.1.2.1.31.1.1.1.15 # ifHighSpeed
- 1.3.6.1.2.1.31.1.1.1.18 # ifAlias
- 1.3.6.1.2.1.2.2.1.2 # ifDescr
lookups:
- source_indexes: [ifIndex]
lookup: ifAlias
- source_indexes: [ifIndex]
lookup: ifDescr
overrides:
ifAlias:
ignore: true # carried as a label by the lookup above
Generate and restart:
./generator generate -g generator.yml -o snmp.yml
systemctl restart snmp_exporter
One practical note about RouterOS vendor metrics: temperature, voltage and fan state live under MikroTik's enterprise branch 1.3.6.1.4.1.14988, but the exact leaves differ across RouterOS versions and board families. Do not copy OIDs from a blog post — walk the branch on your own device and add what returns a number:
snmpwalk -v3 … 10.20.0.1 1.3.6.1.4.1.14988.1.1.3 | head -40
Step 3 — Scrape configuration
Each router gets its own target with labels that make alerts readable. The module parameter selects the generator block, and role is what I use later to route alerts differently for core versus access devices:
scrape_configs:
- job_name: mikrotik
metrics_path: /snmp
scrape_interval: 30s
scrape_timeout: 20s
params:
module: [routeros]
static_configs:
- targets:
- 10.20.0.1 # core-router
- 10.20.0.2 # pop2-router
labels:
role: core
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
Step 4 — Make the numbers mean something
Raw octet counters are not what you alert on. Two recording rules turn them into something a human can act on. Utilisation is computed against ifHighSpeed so it works for both 1G and 100M interfaces:
groups:
- name: network-recording
interval: 30s
rules:
- record: if_utilization:ratio
expr: |
(rate(ifHCInOctets[5m]) * 8)
/ (ifHighSpeed * 1000000)
and on(instance, ifIndex) ifOperStatus == 1
- record: device_uptime:seconds
expr: sysUpTime / 100 # RouterOS reports ticks (1/100 s)
sysUpTime is the cheapest reboot detector you will ever deploy. A 40-second reboot is invisible to ping but obvious here, and correlating it with a spike in PPPoE reconnects tells you whether to blame the device or the uplink.
Step 5 — Alerts that deserve a human
These four rules have survived two years without being muted. The durations matter more than the thresholds:
groups:
- name: network-alerts
rules:
- alert: InterfaceDown
expr: ifOperStatus == 2
for: 2m
labels: { severity: critical }
annotations:
summary: "{{ $labels.instance }} {{ $labels.ifAlias }} down"
- alert: InterfaceFlapping
expr: changes(ifOperStatus[15m]) > 2
for: 5m
labels: { severity: warning }
annotations:
summary: "{{ $labels.ifAlias }} flapping on {{ $labels.instance }}"
- alert: UplinkSaturated
expr: if_utilization:ratio > 0.90
for: 15m
labels: { severity: warning }
- alert: DeviceRebooted
expr: device_uptime:seconds < 300
for: 1m
labels: { severity: info }
for: 2m on the down alert is what killed most of my false positives: PPPoE re-negotiation, SFP re-training and scheduled config changes all resolve well inside two minutes. The flap rule catches the case that matters — a link that is technically up but unusable.
Step 6 — OLT optics via the CLI
The C320 exposes ONU state through SNMP, but per-ONU optical values are far easier to read from the CLI than to map through the vendor MIB. The trick is to stop treating that as a problem: parse the CLI output, write a Prometheus textfile, and let node_exporter publish it.
import re, subprocess, pathlib, time
OUT = pathlib.Path("/var/lib/node_exporter/textfile_collector/olt_optical.prom")
CMD = ["ssh", "-i", "/root/.ssh/olt_ro", "-o", "BatchMode=yes",
"[email protected]", "show gpon onu optical-info"]
raw = subprocess.run(CMD, capture_output=True, text=True, timeout=60).stdout
lines = ["# HELP olt_onu_rx_dbm ONU receive power in dBm",
"# TYPE olt_onu_rx_dbm gauge"]
for row in raw.splitlines():
# gpon-onu_1/2/3:7 -21.43 2.51 ...
m = re.match(r"\s*(gpon-onu_[\d/]+:\d+)\s+(-?\d+\.\d+)", row)
if m:
onu, rx = m.group(1).replace("/", "_").replace(":", "_"), m.group(2)
lines.append(f'olt_onu_rx_dbm{{onu="{onu}"}} {rx}')
tmp = OUT.with_suffix(".tmp")
tmp.write_text("\n".join(lines) + "\n")
tmp.replace(OUT) # atomic: node_exporter never reads a half file
print(f"wrote {len(lines) - 2} ONU samples at {time.strftime('%H:%M:%S')}")
Alerting on optics is then a one-liner, and this is the alert that actually prevents customer calls:
- alert: OnuOpticalWeak
expr: olt_onu_rx_dbm < -27
for: 10m
labels: { severity: warning }
annotations:
summary: "ONU {{ $labels.onu }} receive level {{ $value }} dBm"
What broke in production
Four things, in the order they cost me time:
- Scrape timeouts on the core router. 220 interfaces with a 20-second timeout produced partial scrapes and gaps in graphs. Fix: raise the timeout to 25s and scrape the core router on its own job with a 60s interval.
- Counter resets after reboot.
rate()handles resets, but a device that reboots every few hours makes utilisation meaningless. That is why the reboot alert exists — it tells you the graph is lying before you trust it. - Alert storms during scheduled OLT maintenance. Every ONU behind the OLT fires at once. Fix: Alertmanager inhibit rules — silence downstream ONU alerts while the OLT-level alert is active.
- Missing
ifAlias. Half the interfaces had no description, so every alert saidifIndex 17. Fix: a naming convention enforced at provisioning time, not at monitoring time.
What I would do differently
Start with uptime and interface status only, and add optics once the naming is clean. The temptation is to collect everything on day one; the result is a dashboard nobody reads and alerts everyone mutes. Three metrics that are named properly beat forty that are not.
The full stack — snmp_exporter module, Prometheus rules, Alertmanager receiver and the OLT collector — fits on one VPS and has run for two years without a licence or a vendor portal. If you are maintaining a network with more than a handful of sites, that trade is worth making.