Efficient Network Monitoring with 'gnmic subscribe' (with examples)
The gnmic subscribe
command is a powerful tool used for obtaining real-time network device state updates. This command is part of the gNMI client collection, designed to communicate with network devices supporting the gNMI specification. It allows network administrators to view continuous information about network state changes and manage their network infrastructure efficiently by subscribing to particular paths or event updates based on different criteria. This can be particularly useful in large and dynamic network environments where constant monitoring is crucial for maintaining network performance and reliability.
Use case 1: Subscribe to target state updates under the subtree of a specific path
Code:
gnmic --address ip:port subscribe --path path
Motivation:
This use case is useful when network administrators need to monitor a specific section of the network device data. By subscribing to a particular subtree, they can keep track of changes or updates in that area without being overwhelmed by the entire dataset. This helps in quickly identifying and troubleshooting issues related to specific network components.
Explanation:
--address ip:port
: Specifies the IP address and port of the target network device. This tellsgnmic
where to connect for obtaining updates.subscribe
: The action of subscribing to updates.--path path
: Defines the GNMI path to which we subscribe. This path should be under which the desired data is located.
Example output:
After executing the command, the expected output would be a stream of updates specific to the path specified. These updates will continue as long as changes occur under the specified subtree in the network device.
Use case 2: Subscribe to a target with a sample interval of 30s (default is 10s)
Code:
gnmic -a ip:port subscribe --path path --sample-interval 30s
Motivation:
This use case is optimal when real-time updates aren’t necessary, and reducing the frequency of data collection is acceptable. By extending the sampling interval to 30 seconds, network traffic from monitoring is reduced, which can be helpful in minimizing bandwidth usage in scenarios where device changes are less frequent or the network is congested.
Explanation:
-a ip:port
: Shortcut for--address
, specifying where to connect.subscribe
: Initiates the subscription mode ingnmic
.--path path
: Defines the path to subscribe to.--sample-interval 30s
: Sets the frequency of data updates to every 30 seconds. This changes the default interval from 10 seconds.
Example output:
The output will consist of updates from the specified path, reported every 30 seconds, thus providing regular insights into the device’s status at a slower pace than the default setting.
Use case 3: Subscribe to a target with sample interval and updates only on change
Code:
gnmic -a ip:port subscribe --path path --stream-mode on-change --heartbeat-interval 1m
Motivation:
This use case is advantageous when network administrators only need to react to changes in the network device state rather than at every sample interval. Updates are sent only if there is a change, reducing unnecessary data flow and processing in scenarios where stability is expected.
Explanation:
-a ip:port
: Defines the target device to connect.subscribe
: The command to start receiving telemetry data.--path path
: The GNMI path under which changes are detected.--stream-mode on-change
: Specifies that updates should be sent only upon change.--heartbeat-interval 1m
: Even if no changes occur, a heartbeat message is sent every 60 seconds to indicate the connection is still alive.
Example output:
You will receive updates only when there’s a change in the tracked data, with additional heartbeat signals every minute in absence of changes. This minimalistic output is especially useful in stable environments.
Use case 4: Subscribe to a target for only one update
Code:
gnmic -a ip:port subscribe --path path --mode once
Motivation:
This use case caters to scenarios where a snapshot of current device data is necessary, without the need for ongoing updates. Network administrators might use this for initial checks or diagnostics on demand.
Explanation:
-a ip:port
: Specifies the address of the device to collect data from.subscribe
: Starts the data collection process.--path path
: The specified GNMI path to gather initial state.--mode once
: The mode indicates that subscription should retrieve data only once.
Example output:
A single set of data describing the state of the target at the time of the subscription, providing a quick snapshot for analysis or record-keeping.
Use case 5: Subscribe to a target and specify response encoding (json_ietf)
Code:
gnmic -a ip:port subscribe --path path --encoding json_ietf
Motivation:
Different systems and applications might require data in different formats. By specifying JSON-IETF encoding, compatibility with certain analytics tools or storage systems can be ensured, allowing for seamless integration with existing IT infrastructure.
Explanation:
-a ip:port
: Determines where to establish the subscription.subscribe
: Initiates the telemetry streaming.--path path
: Identifies the data subset to be streamed.--encoding json_ietf
: Indicates the desired format, in this case, JSON-IETF, for easier parsing and compatibility reasons.
Example output:
Data will be output in JSON-IETF format, readily integratable into systems that support this encoding, facilitating subsequent processing and storage tasks.
Conclusion:
The gnmic subscribe
command provides a robust set of features that facilitate a variety of network monitoring tasks. From real-time updates to change-only alerts and format-specific output, it enables efficient, tailored network management based on specific requirements and infrastructure capabilities. Each use case highlights different configurations that can optimize network device state monitoring, ensuring administrators achieve the necessary insights with minimal resource use.