How does gNMI work, and what are its subscription modes?
Show the answer
Say this first
gNMI is a gRPC service with four RPCs: Capabilities (which models and encodings the target supports), Get, Set (delete, replace and update in one atomic request) and Subscribe. A subscription can be ONCE (send everything and stop), POLL (send when the client asks) or STREAM. Stream subscriptions are SAMPLE (every interval), ON_CHANGE (only when a value changes) or TARGET_DEFINED (the device picks per path).
Go deeper
Paths
gNMI paths are XPath-like with keys in brackets and no quotes:
/interfaces/interface[name=Ethernet1]/state/counters/in-octets. An optional origin (often
openconfig) says which model tree the path belongs to.
Subscribe in practice
gnmic -a 10.0.0.31:6030 -u netops -p secret --insecure capabilities
gnmic -a 10.0.0.31:6030 -u netops -p secret --insecure \
subscribe --path "/interfaces/interface[name=Ethernet1]/state/counters" \
--stream-mode sample --sample-interval 10s
gnmic -a 10.0.0.31:6030 -u netops -p secret --insecure \
subscribe --path "/interfaces/interface/state/oper-status" --stream-mode on-change--insecure is plaintext gRPC for a lab. With TLS use --tls-ca to verify the device certificate, or
--skip-verify to encrypt without checking it.
Which mode for what
| Data | Mode | Why |
|---|---|---|
| Interface counters, CPU, memory | SAMPLE, 10 to 30 s | Values change constantly |
| Oper-status, BGP session state, LLDP neighbors | ON_CHANGE | Rare, important changes, sent at once |
| Inventory, software version | ONCE or POLL | Rarely changes |
suppress_redundant and heartbeat_interval let SAMPLE skip unchanged values while still proving
the stream is alive.
Related gRPC services
gNOI for operations (reboot, file transfer, certificates, ping), gRIBI for injecting routes, P4Runtime for programmable forwarding pipelines.
Enabling it
management api gnmi
transport grpc defaultOther platforms have their own commands and default ports; check the release notes.
They will ask next
Why is ON_CHANGE better than polling oper-status every 10 seconds?
You learn about a flap within milliseconds instead of up to 10 seconds later, and you do not send the same "up" value thousands of times a day. It only works if the platform supports on-change for that path.
What is the difference between dial-in and dial-out?
gNMI Subscribe is dial-in: the collector connects to the device and subscribes. In dial-out the device is configured to connect to the collector, as with IOS-XE
telemetry ietf subscriptionand gRPC receivers. Dial-out survives collector restarts without re-subscribing; dial-in keeps all config on the collector side.
Traps
- Using SAMPLE every second on thousands of paths and overloading the device CPU and the collector.