Junos PyEZ Table View for “show system process extensive”

Dineshbaburam
2 min readMar 11, 2022

“show system process extensive” is the CLI command in Junos which shows the running process in the device and its CPU and memory usages of each process.

root> show system processes extensivelast pid: 26688; load averages: 0.81, 0.95, 0.87 up 1+09:50:29 07:16:56448 threads: 10 running, 397 sleeping, 41 waitingCPU: 5.9% user, 0.0% nice, 11.8% system, 9.6% interrupt, 72.7% idleMem: 201M Active, 2796M Inact, 1348M Wired, 494M Buf, 11G FreeSwap: 3072M Total, 3072M FreePID USERNAME PRI NICE SIZE RES STATE C TIME WCPU COMMAND11828 root 4 0 924M 125M select 1 341:28 16.36% chassisd{chassisd}13733 root 22 0 775M 54M CPU1 1 115:33 5.37% jinsightd{jinsightd}13741 root 22 0 50M 27M RUN 1 88:10 4.05% na-grpcd{na-grpcd}26686 root 23 0 86M 69M select 0 0:00 1.76% cli13769 root 20 0 739M 28M select 0 9:58 0.10% agentd{agentd}11734 root 20 0 734M 23M select 1 7:27 0.10% eventd

The respective XML output for the CLI command is mentioned below:

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/22.3I0/junos"><output>
last pid: 26688; load averages: 0.81, 0.95, 0.87 up 1+09:50:29 07:16:56
448 threads: 10 running, 397 sleeping, 41 waitingCPU: 5.9% user, 0.0% nice, 11.8% system, 9.6% interrupt, 72.7% idleMem: 201M Active, 2796M Inact, 1348M Wired, 494M Buf, 11G FreeSwap: 3072M Total, 3072M FreePID USERNAME PRI NICE SIZE RES STATE C TIME WCPU COMMAND11828 root 4 0 924M 125M select 1 341:28 16.36% chassisd{chassisd}13733 root 22 0 775M 54M CPU1 1 115:33 5.37% jinsightd{jinsightd}13741 root 22 0 50M 27M RUN 1 88:10 4.05% na-grpcd{na-grpcd}26686 root 23 0 86M 69M select 0 0:00 1.76% cli13769 root 20 0 739M 28M select 0 9:58 0.10% agentd{agentd}11734 root 20 0 734M 23M select 1 7:27 0.10% eventd
</output>
</rpc-reply>

To retrieve the process information using the PyEZ table view, the regex keyword should be used.

from jnpr.junos.factory.factory_loader import FactoryLoader
import yaml
import json
from pprint import pprint

yaml_data = """
---
SystemProcExtTable:
command: show system processes extensive
key:
- pid
- cmd
title: ' PID '
view: SystemProcExtView

SystemProcExtView:
regex:
pid: '(\d+)'
size: '.* \S +(\d+(K|M|G))\s+'
res: '(\d+(K|M|G))'
wcpu: '.* (\d+\.\d+)%'
cmd: '[\w\-\{\}]+'

"""

with Device(host=’X.X.X.X’, user='XXX', password='XXX', port=22) as dev:
globals().update(FactoryLoader().load(yaml.load(yaml_data, Loader=yaml.FullLoader)))
proc = SystemProcExtTable(dev)
proc.get()
pprint(json.loads(proc.to_json()))

Output:

{"(1, 'init')": {'cmd': 'init',
'pid': 1,
'res': '636K',
'size': '9560K',
'wcpu': '0.00'},
"(10825, 'eventd')": {'cmd': 'eventd',
'pid': 10825,
'res': '15M',
'size': '734M',
'wcpu': '0.00'},
"(10831, 'jlaunchd')": {'cmd': 'jlaunchd',
'pid': 10831,
'res': '7112K',
'size': '750M',
'wcpu': '0.00'}
}

--

--