Generating xpaths from Yang for Cisco gRCP telemetry

There is a Python tool called pyang that can read yang files. To install it on Linux machine:

apt install git python3-pip
pip install pyang

Now, git clone yang data model to your linux machine:

cd ~;git clone

Pyang by itself is capable of reading yang and present it as a tree. To get xpath, we need to install additional plugin from here:
Find your pyang installation, and put the the xpath plugin to the plugin folder:

find /usr/local/lib -iname pyang

Download plugin:

wget -O /usr/local/lib/python3.10/dist-packages/pyang/plugins/

Go to Yang model you cloned a few steps back (in this example, we’ll find xpath for Cisco IOS-XE cpu usage:

cd ~/yang/vendor/cisco/xe/1781/

Use xpath module on yang file to get xpath:

pyang -f xpath Cisco-IOS-XE-process-cpu-oper.yang 
>>> module: Cisco-IOS-XE-process-cpu-oper

This are all xpaths, but we still need a prefix to construct a full path. It’s written at the start of the file:

grep prefix Cisco-IOS-XE-process-cpu-oper.yang
  prefix process-cpu-ios-xe-oper;

The whole xpath (level 1 depth) would look like this:


Depends on the depth and data needed, you can use this xpath with Cisco IOS-XE switch. Example:

telemetry ietf subscription 3305
 encoding encode-kvgpb
 filter xpath /process-cpu-ios-xe-oper:cpu-usage/cpu-utilization
 stream yang-push
 update-policy periodic 3000
 receiver ip address 57000 protocol grpc-tcp


Leave a Reply

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