Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 

Using 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 are running 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 support for psutil functions on devices that support Python automation scripts and are running Junos OS with upgraded FreeBSD. For more information about the psutil module and its functions, see the official documentation at https://psutil.readthedocs.io/en/latest/.

Table 1: Support for psutil Module Functions on Devices Running Junos OS

Function Category

Supported Functions

Functions Not Supported

CPU

cpu_count()

cpu_freq()

cpu_percent()

cpu_stats()

cpu_times()

cpu_times_percent()

Disk

disk_partitions()

disk_usage()

disk_io_counters()

Memory

virtual_memory()

swap_memory()

Network

net_connections()

net_if_addrs()

net_if_stats()

net_io_counters()

Processes

pid_exists()

pids()

process_iter()

wait_procs()

Sensors

sensors_battery()

sensors_fans()

sensors_temperatures()

System Info

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.

user@host> op psutil.py