Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Subscribing to Telemetry Data Using gNMI

The gNMI protocol defines the Subscribe RPC for subscribing to telemetry data. The telemetry collector uses this RPC to request updates from the network device for state and configuration data.

Requests for new subscriptions are encapsulated within a SubscribeRequest message containing one or more resource paths. The subscribed paths relate to specific data instances on the target network device. The request can contain paths based on the OpenConfig or native Junos schemas.

The subscription request must also include one of the following modes:

  • ONCE - a one-time request for data.

  • POLL - for periodic, on-demand retrieval of data.

  • STREAM - a long-lived subscription that streams data according to specified triggers.

Subscriptions in STREAM mode must specify one of the following sub-modes:

  • ON_CHANGE - data updates are only sent when the value of the data item changes.

  • SAMPLE - data updates are sent once per sample interval based on an interval period specified in the subscription request. The default sample interval is 30 seconds.

  • TARGET_DEFINED - the network device receiving the subscription request determines the best type of delivery for the data on a per-leaf basis. If the path specified within the message refers to event-driven data, then an ON_CHANGE subscription might be created. For data that represents counter values a SAMPLE subscription might be created.

    Note:

    The TARGET_DEFINED subscription requests for configuration paths are treated as ON_CHANGE requests only.

For ONCE, ON_CHANGE and SAMPLE subscriptions, the collector can request an initial update containing the current state of the paths in the subscription. This update, also known as an initial sync, is valuable because:

  • The collector has a complete view of the current state of every field on the device for that sensor path.

  • Event-driven data (ON_CHANGE) is received by the collector at least once before the next event is seen. In this way, the collector is aware of the data state before the next event happens.

  • Packet Forwarding Engine sensors that contain zero counter values that normally do not show up in streamed data due to zero-suppression are sent. This ensures that all fields from each line card are known to the collector.

The target device responds to the subscription request with a SubscribeResponse message. If the subscription request calls for an initial sync, the target sends the data followed by the response message with the sync_response flag set to true. After the intial sync, the target device proceeds with updates for the paths according to the subscription mode.

The SubscribeRequest message includes a flag called updates_only. When this flag is set to true, the target device does not send an initial sync, only subsequent updates as follows:

  • For STREAM subscriptions in SAMPLE mode, the update is sent at the next sample interval.

  • For STREAM subscriptions in ON_CHANGE mode, the update is sent upon the next value change.

  • For ONCE subscriptions, only the SubscribeResponse is sent with sync_response set to false, and the subscription is closed.

  • TARGET_DEFINED subscriptions are treated as ON_CHANGE for configuration paths and the update is sent upon the next value change.

The contents of the SubscribeRequest and SubscribeResponse messages are defined in gnmi.proto file. For more information on the Subscribe RPC and subscription modes, see the gNMI specification at: gNMI Specification: Subscribing to Telemetry Updates.

Note:

The following limitations apply to configuration paths:

  • POLL subscriptions are not supported.

  • Prefix paths are not included in the update messages.

  • The gNMI response is not supported for Juniper-specific metadata operations, such as active/inactive, insert before/after, comment/annotate, and protect/unprotect. These might appear in the message but are not valid.

  • Unsupported parameters in the SubscribeRequest include suppress_redundant, heartbeat_level, allow_aggregation, and qos.

  • Only PROTO encoding is supported.

  • Extensions in SubscribeRequest messages are not supported

  • Filtering of the subscription paths is supported only at a key level.

  • The following commit variants are not supported for ON_CHANGE and TARGET_DEFINED subscriptions:

    commit at, commit prepare/activate, and batch commits.
  • Commits are not supported from the

    edit dynamic and edit private edit or configure modes.
  • Update messages are not sent for presence containers.

  • For subscription lists where the identifier or key is the only leaf configured, there might not be an update message.

Examples

The following examples show subscription requests and responses made by a gNMI client and target device in protobuf format.

Example: ONCE mode

The following example shows a subscription request sent from a gNMI client in protobuf format. The subscription mode is ONCE and the OpenConfig resource path is /system/aaa/authentication/users:

The target responds with a one-time update:

Example: ON_CHANGE

The following example shows a subscription request in STREAM mode with ON_CHANGE sub-mode. The OpenConfig resource path is /system/aaa/authentication/users/user[username="test1"]:

The OpenConfig configuration at the time of the subscription request:

The example response message shows the values for the configuration paths and the sync_response flag set to true:

The following configuration changes are made to the subscribed paths:

  • Add username for test1.

  • Delete password for test1.

The target device sends the following update in response:

Example: SAMPLE

The following example shows a subscription request in STREAM mode and SAMPLE sub-mode. The OpenConfig resource path is /system/aaa/authentication/users/user[username="test1"]:

The OpenConfig configuration at the time of the subscription request:

The example response messages show an initial update sent with the sync_response flag set to true and subsequent updates sent at 5 second intervals: