Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

How to Use the psutil Module to Retrieve Process and System Information on Devices Running Junos OS

The psutil Python module is available on certain devices that support Python automation scripts and that are running either Junos OS Evolved or Junos OS with upgraded FreeBSD. You can use the psutil module in Python scripts to retrieve information about running processes and system utilization on the device, for example, information about the CPU, memory, disks, and processes. The module implements the functionality of many command-line tools such as ps and uptime, among others.

Table 1 outlines the supported psutil functions. For more information about the psutil module and its functions, see the official documentation at https://psutil.readthedocs.io/en/latest/.

Table 1: psutil Module Functions

Function Category

Supported Functions
(Junos OS with
Upgraded FreeBSD)

Supported Functions
(Junos OS Evolved)

CPU

cpu_count()

cpu_count()
cpu_freq()
cpu_percent()
cpu_stats()
cpu_times()cpu_times_percent()

Disk


disk_partitions()
disk_usage()

disk_io_counters()
disk_partitions()
disk_usage()

Memory


virtual_memory()

swap_memory()
virtual_memory()

Network

net_connections()
net_if_addrs()
net_if_stats()
net_io_counters()

Processes

pid_exists()
pids()
process_iter()
wait_procs()

pid_exists()
pids()
process_iter()
wait_procs()

Sensors

System Info

boot_time()
users()

boot_time()
users()

The following sample Python op script demonstrates calls to the psutil functions to retrieve information about the system and processes on the given device running Junos OS:

When you execute the op script, the script prints the requested information about the device. Some of the sample output has been truncated for brevity.