Table of Contents

gnmi streaming with subscribe command is the most important feature of gnmi protocol, at least nowadays that netconf and restconf are the main yang based automation protocols.

In this section, you will learn how to subscribe to any data in the yang data model using gnmic to stream it to the subscriber on changes or at intervals.

gnmi subscribe command

In the previous sections, we have already discussed and implemented the gnmi get and set commands with gnmic tool.

In this section will be dedicated to the most interesting gnmi command, “subscribe”.

gnmi subscribe streaming modes
gnmi subscribe streaming modes

With “Subscribe”, any software can subscribe to any data in the yang data model structure in order to receive the data whenever it changes or at certain intervals.

In other words, the gnmi subscribe command can be used to stream data to all telemetry subscribers at any time.

With gnmi streaming “sample” mode, data will be streamed at regular interval and with gnmi streaming “on_change” mode, data will be streamed whenever it changes.

A good example for “on_change” mode is interface status. You subscribe to receive the interface status whenever it changes.

A good example of “sample” mode is the interface bandwidth. You subscribe to receive inbound and outbound interface statistics at regular intervals to monitor inbound and outbound bandwidth usage.

gnmi streaming mode is typically used in conjunction with monitoring packages like Influxdb, telegraf, and grafana software package for monitoring purposes.

gnmi streaming examples with gnmic

To better understand gnmi subscribe command and streaming mode, I have prepared two examples. Interface incoming traffic statistics with sample streaming mode and interface status with on_change streaming mode.

monitor interface statistics with gnmi subscribe sample mode

This is the command to monitor incoming traffic of interface ethernet1 with sample streaming mode.

Instead of the “get” or “set” command, we use the “subscribe” command in this example.

The path is known to us since we have already discussed in gnmi “get” command and gnmic interactive mode.

With “stream-mode” parameter in which we see in the subscribe command, we have definedthe streaming mode as “sample”. And sampling interval is also configured to 5 seconds.

gnmic -a -u rayka -p --insecure subscribe --path /interfaces/interface[name=Ethernet1]/state/counters/in-octets --stream-mode sample --sample-interval 5s

Let’s run the command to see how the incoming statistics of the Ethernet1 interface are displayed in the output every 5 seconds.

gnmi streaming sample mode
gnmi streaming sample mode

monitor interface status with gnmi subscribe on_change mode

In the second example, we monitor the status of the Ethernet1 interface and the streaming mode is configured as “on_change” mode, which means that every interface status changes are streamed to the subscribers.

gnmic -a -u rayka -p --insecure subscribe --path /interfaces/interface[name=Ethernet1]/state/oper-status --stream-mode on_change

To see the example, let’s run the command and then manually disable and enable the interface using the “shutdown” and “no Shutdown” commands.

It is expected that whenever there is a status change, the new status will be streamed to the subscriber.

gnmi streaming on_change mode
gnmi streaming on_change mode

From these two examples, I hope that the application of gnmi streaming mode or subscribe command is clear to us.

But in this link, which we also discussed in the previous section, you can see some other examples of gnmi streaming mode with Arista network devices.

Back to: YANG based Network Automation using NETCONF RESTCONF gNMI > Network Automation using gRPC/gNMI

Leave a Reply

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

Post comment