The owner wants LibreNMS-like 5-minute polling by default and the option
to poll a given device faster or slower. Devices gain poll_interval_s
(new migration; 0 means the default, otherwise 30 to 3600 s), settable in
the device edit dialog and through PUT /api/v1/devices/{slug}; the
poller picks it up on the next inventory refresh.
Everything that assumed one-minute samples now follows the device's
interval: graph and p95 rate windows are at least two polls, the max
series uses irate, the up-series lookback, the no_data warning, the
"unheard of for three polls" fallback and the rollup's thin-window check.
interface_errors widens to 10 m. profiletest keeps 60 s because the
expect budgets are keyed by the 1m group. Recorded as DEVIATIONS 49.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017TuKgyKve2XLFtrrXWMi2w
15 KiB
Operating nmon
How to run, secure, back up and maintain a production nmon. Design background: docs/spec/spec.md ("Auth", "Operations").
Starting
nmon serve --data-dir /var/lib/nmon --secret-key-file /etc/nmon/secret.key \
--tls-cert /etc/nmon/tls.crt --tls-key /etc/nmon/tls.key
- HTTPS is the default. Pass a certificate pair (
--tls-cert,--tls-key;SIGHUPreloads them without dropping connections) or Let's Encrypt (--acme-host nmon.example.netrepeatable,--acme-email you@example.net; nmon answers the http-01 challenge on--acme-listen, default:80, certificates are cached in<data-dir>/acme). Without either,serverefuses to start and says so.--insecure-httpis for development: plain HTTP, cookies withoutSecure. - A sign-in method is required over TLS (
auth.oidcand/orauth.break_glass_fileinconfig.yaml). With--insecure-httpand neither configured nmon runs in dev-open mode (everyone is admindev; a banner says so); never expose that port. - Behind a reverse proxy, list it in
auth.trusted_proxies;X-Forwarded-*is ignored from anyone else.
Sign-in
config.yaml:
auth:
oidc:
issuer: https://idp.example.net/realms/net
client_id: nmon
client_secret_name: oidc-client # the secret itself is never in this file
redirect_url: https://nmon.example.net/auth/callback
groups_claim: groups
admin_group: nmon-admins # members are admins; every other user is a viewer
break_glass_file: /etc/nmon/breakglass # bcrypt hash, "hash" or "user:hash", created by you
Store the client secret before the first start: printf '%s\n' "$SECRET" | nmon secret set oidc-client --data-dir D --secret-key-file K (it can also be set later with PUT /api/v1/secrets/oidc-client; OIDC stays off until the secret exists). The break-glass file holds one bcrypt hash ($2a$/$2b$), made with any bcrypt tool (the source tree's nmon-devtools bcrypt PASSWORD works); keep it readable by the nmon user only.
- There is no login page. Opening nmon without a session redirects to the IdP and back; API clients use a token. If the IdP is down, open
/auth/breakglass: the browser asks for the local admin user and password (HTTP Basic), and a successful sign-in lands on the page you asked for. - Break-glass: five wrong passwords lock the source address for 15 minutes; every use and every lock is audited and raises an alert.
nmon unlock [IP|all] --data-dir Dclears locks, also while nmon runs. - API tokens: an admin mints viewer, admin or push tokens (
POST /api/v1/tokens, or Settings, API tokens). UseAuthorization: Bearer nma_.... A push token works for ingest only. Revoking takes effect on the next request. GET /api/v1/audit(admin) lists who did what.
Backup and restore
A running nmon owns the stores, so copying the data folder is not a backup.
nmon backup /backups/nmon.tar --api https://nmon.example.net --token nma_... # key NOT included
nmon backup /backups/nmon.tar --include-key --api ... --token ... # key included
Every run prints whether the key file is in the archive. Lose the key file and a restore has an inventory with no SNMP credentials. The nightly schedule is backup: {at: "02:30", dir: /var/backups/nmon, keep: 7} (time in the configured timezone, default dir <data-dir>/backups); a failed run raises the backup_failed alert. A backup is refused when the disk is below its 5% reserve.
Restore with nmon stopped, into a clean directory:
nmon restore /backups/nmon.tar --data-dir /var/lib/nmon-restored --secret-key-file /etc/nmon/secret.key
It verifies inventory row counts and a sample of series before it says done. Then start nmon on that directory. Restore needs the embedded stores (the normal release build).
Keys
nmon key rotate --data-dir D --secret-key-file K (nmon stopped) adds a new key version, re-encrypts every SNMP credential and secret under it, and keeps the old key in the file so older backups still restore. Remove old keys only after a release.
Configuration
Edit in Settings (admin) or config.yaml + SIGHUP. An invalid document is rejected and the running configuration stays. Alert receivers, the outbound allow-list, trusted proxies, the backup schedule, disk thresholds and the purge period apply live; everything else is listed as restart_required until the next restart. disk: {alert_used: 0.8, admit_used: 0.9, reserve_free: 0.05}: alert at 80% used, no new series at 90%, ingest throttled / rollup paused / backups refused below 5% free.
Metric stores
The supervisor restarts a crashed store; after three restarts in ten minutes it raises store_failed and stops. nmon store restart [hot|long] --api URL --token T (or SIGHUP) resumes it.
Interface-down alerts are opt-in
Since v1.1 the bell and the group switch only mark ports: interface_down alerts for them only where an alert policy for interface_down uses the alert_down matcher (template "Bell-marked ports: interface_down"). Mark ports in one at a time (the bell on the device page's interface table), all at once (the "Alert on down" control in the interfaces card header, or POST /api/v1/devices/{slug}/interfaces/alert-down), or through a group (the group's "Alert when member ports go down" switch; PUT /api/v1/interfaces/{id} with {"alert_down": true} for one port). A port in a group with the switch on alerts for as long as its membership is in force. Changes reach the evaluator at once; opting a port out closes its open alert silently as retired.
Alert policies: nothing alerts until you add one
Alerts fire only where an alert policy binds a rule to a scope. A fresh install has no policies and records no alerts at all: no metric rule, no device_down or device_warning, no system alarm (ingest caps, late p95, rollup, disk guard, break-glass, backup). The startup log says so once ("no alert policies: nothing will alert"). Upgrading from v1.0 seeds nothing: the first cycle closes every open alert that no policy binds, silently, as retired (no "resolved" notices go out).
Manage policies under Alerts > Alert policies (admins edit, viewers read) or with GET/POST /api/v1/alert-policies and GET/PUT/DELETE /api/v1/alert-policies/{id}. GET /api/v1/alert-rules lists the rule names. POST /api/v1/alert-policies/preview counts the devices and ports a draft scope covers. Changes apply on the next cycle with no restart. Removing or disabling a policy retires its open alerts quietly.
A policy has a rule (a metric rule, device_down, device_warning, or system), an action (alert or ignore), a priority, optional severity, threshold and for overrides, and a scope. Scope fields are ANDed and any entry of a list may match: all, groups (a port is in force as a member now; a device matches if any port does), devices (slugs globs, profiles, roles, sites, kinds) and interfaces (if_types, if_name and if_alias as RE2, min_speed_mbps, max_speed_mbps, alert_down). For one entity and rule the matching policy with the highest priority decides; on a tie ignore beats alert, then the lowest name. A policy threshold beats a rule's group override, the profile threshold and the default. Interface matchers are refused on device-level rules, and a system policy takes only all: true.
Fiber and uplinks alert on any error, WiFi never alerts on errors:
{"name": "Fiber + uplinks: errors", "rule": "interface_errors", "action": "alert", "threshold": 0,
"scope": {"interfaces": {"if_types": [6], "if_alias": "(?i)fib|uplink|core"}}}
{"name": "WiFi: no error alerts", "rule": "interface_errors", "action": "ignore", "priority": 10,
"scope": {"interfaces": {"if_types": [71]}}}
Alert rules: built-in and custom
The shipped rules (interface_down, interface_errors, cpu_high, memory_high, disk_full, ups_on_battery, ups_runtime_low, printer_supply_low, printer_supply_empty, temp_high) are read-only built-in rules, listed with their generated query under Alerts > Alert rules. cpu_high, ups_on_battery and printer_supply_empty have Copy to custom, which clones them into an editable builder rule; the others join, filter or union series and say why they cannot be copied. Rules in config.yaml (alerting.rules) still work but are deprecated, and the startup log says so; define rules in the UI instead. A rule name is unique across all kinds, and device_down, device_warning, system and the subsystem alarm names stay reserved.
Admins add their own rules with the builder (UI or POST /api/v1/alert-rules). There is no free-form query: nmon builds it from whitelisted parts, and the generated MetricsQL is shown read-only. Test runs the draft once and shows how many entities breach now. Edits apply on the next cycle; disabling a rule or deleting it retires its open alerts silently, and deleting a rule that a policy still names is refused (409, naming the policies).
- Metric rule, "CPU over 80 % on role=server for 15 min": metric
hrProcessorLoad, aggregatemax(one value per device), op>, threshold80, hold time15m; then a policy for this rule withdevices.roles: [server]. Transforms arevalue,rate(counters, per second) andpercent_of(metrics with anof, such ashrStorageUsed); the window defaults to 5 min (at least twice the poll interval). Push-ingested metrics are device-level. - Inventory rule, "Uplink without description": interface fields
if_alias emptyANDif_speed_mbps >= 10000. - Inventory rule, "Device not seen for 1 h": device field
last_seen_age older_than 1h.
A custom rule, like a built-in, alerts nowhere until an alert policy binds it: the rule defines what is measured and its default threshold and hold time, and the policy defines where it applies and may override severity, threshold and for. Several policies can bind one rule to different scopes.
Retired devices
POST /api/v1/devices/{slug}/purge (admin) deletes a retired device's series from both stores once it has been retired for retired_purge_after (default 1y).
CSV import
Devices (name,address,site,role,credential,parents,...) and port descriptions (device,ifname,alias) from Settings or POST /api/v1/devices/import. Port descriptions are stored in the operator-owned description field, which discovery never overwrites. A dependency cycle is rejected with its path; nothing is written unless the whole import is valid.
Find host: MAC, ARP and FDB lookup
The L2 table job walks the bridge forwarding tables, VLAN names and ARP / IPv6 neighbour tables of every SNMP device every l2.interval and keeps them with first and last seen in the inventory, so the Find host page (and the header search, for a MAC, IP, CIDR or vendor:name) answers "which switch port is this host plugged in at, in which VLAN, and when did we last see it", with the uplinks that also saw it collapsed underneath. A MAC is seen on every switch it passes through, so the answer is the edge port: one that carries at most l2.edge_max_macs MACs, has no LLDP neighbour and is not a LAG.
l2:
interval: 15m # default 15m, minimum 5m
keep: 90d # history kept by last_seen, pruned daily
edge_max_macs: 8 # a port with more MACs is an uplink
concurrency: 4 # devices walked at once
device_timeout: 2m # a slower device is skipped for the cycle
oui:
fetch: true # IEEE vendor registry; false never touches the network
refresh: 7d
All of these apply from the next cycle after a reload (Settings save or SIGHUP) with no restart. The job never runs on the poll path and yields to the poller the way the rollup job does. A device that does not answer in time is skipped for that cycle and named on the Poller page (l2 status and an l2_devices_skipped note); it never delays the other devices. A Cisco IOS switch keeps one bridge table per VLAN: the cisco-ios profile sets l2.per_vlan_context: true, which lists the VLANs from CISCO-VTP-MIB and walks each with community <community>@<vlan> (v3: context vlan-<vlan>). Other devices use Q-BRIDGE-MIB, then BRIDGE-MIB (VLAN unknown).
API: GET /api/v1/l2/search?q=, GET /api/v1/devices/{slug}/{l2,fdb,arp,l2/ports}, GET /api/v1/interfaces/{id}/macs. On a device, the L2 tab (MAC table with a VLAN filter, ARP / ND, VLAN list) appears once the job has read it, and the Ports tab shows each port's MAC count linking to that port's MACs.
MAC vendors (optional IEEE registry)
If a registry is loaded, each MAC shows its vendor, a locally administered address (typical of randomised phone and VM MACs) shows a "private" badge, and vendor:ubiquiti lists the current MACs of a vendor. nmon works fully without it: the vendor is simply empty, and the Poller page notes oui_unavailable (not an alert).
The registry is the IEEE's public data: MA-L (https://standards-oui.ieee.org/oui/oui.csv), MA-M (.../oui28/mam.csv) and MA-S (.../oui36/oui36.csv), downloaded weekly through the outbound allow-list (standards-oui.ieee.org must be allowed when an allow-list is configured) with timeouts, a size cap and a row-count sanity check, so a truncated or wrong download keeps the previous file. The compact result is <data-dir>/oui/registry.gz (checksummed, written atomically, included in nmon backup). Where nmon may not fetch, set oui.fetch: false and load the CSVs by hand: nmon oui import <dir-or-file> --data-dir DIR (a running nmon notices within an hour). The CSVs are not part of this repository.
BGP
Router profiles collect BGP session state, uptime, accepted prefixes per address family and update rates every 5 minutes (see docs/coverage.md for which profiles and MIBs). The BGP page lists every session on every device, the ones that are down first, filterable by state, AS, family and text; a device's Routing tab shows its sessions with click-to-graph on prefixes and updates.
The built-in rule bgp_peer_down (critical, state not established for 2 minutes) fires only where a policy binds it, like every rule: use the template "Routers: BGP peer down" under Alerts > Alert policies. Its notification names the peer and, from discovery, the peer's AS and description. A prefix-drop alert is a custom rule (v1.2); an example will be added here once custom rules are in.
Poll interval
SNMP interface counters are polled every 300 s by default. An admin can set a different interval for one device (Device settings, "Poll interval", 30 to 3600 s; blank returns it to the default) or through PUT /api/v1/devices/{slug} with poll_interval_s. The poller picks it up at once, no restart. Graph rate windows, reachability fallbacks and the rollup follow the device's own interval (see docs/DEVIATIONS.md row 49). ICMP is still probed every 15 s. nmon serve --poll-interval changes the default for dev and tests only.