Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to understand the cross-platform library psutil

Shulou Source: shulou.com Published: 2022-05-31 15:27:34 09月21日 Update

Cross-platform library psutil how to understand, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this can learn, I hope you can gain something.

psutil is a cross-platform library that makes it easy to get information about the processes and system utilization (including CPU, memory, disk, network, etc.) of the system running. It is mainly used for system monitoring, analysis and limitation of system resources and process management. It implements the functionality provided by equivalent command line tools such as ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap, etc.

http://psutil.readthedocs.io/en/latest/ Detailed use cases

1、CPU

1 psutil.cpu_times(percpu=False)

Return cpu usage time ancestor. If percpu=True, returns a list of CPU usage.

1 psutil.cpu_percent(interval,percpu) #Returns CPU utilization

2 psutil.cpu_times_percent(interval=None, percpu=False)

3 psutil.cpu_count(logical=True) #Return system logical CPU

4 psutil.cpu_stats() #Returns CPU statistics

5 psutil.cpu_freq(percpu=False) #Returns the CPU frequency

2. Memory

1 psutil.virtual_memory() #Returns statistics on system memory usage

2 psutil.swap_memory() #Returns system swap memory statistics

3. Disk

1 psutil.disk_partitions(all=False) #Returns a list of all mounted disk devices, including devices, mount points, and file system ancestors

2 psutil.disk_usage(path) #Returns disk statistics

3 psutil.disk_io_counters(perdisk=False, nowrap=True) #Returns disk IO statistics

4. Network

1 psutil.net_io_counters(pernic=False) #Returns system network IO statistics

2 psutil.net_connections(kind ='inet ') #return system socket connections

3 psutil.net_if_addrs() #Returns the IP, subnet mask and broadcast address bound to the NIC

4 psutil.net_if_stats() #Returns information about the NIC

5. Sensors

1 psutil.sensors_temperatures(Fahrenheit=False) #Returns the temperature of hardware

2 psutil.sensors_fans() #Returns hardware fan speed

3 psutil.sensors_battery() #Returns battery status

6. Other

1 psutil.boot_time() #System boot time

2 psutil.users() #List of users connected to the system

Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

Tags: System information statistics disk memory network utilization situation time hardware network card device process meta-ancestor help clarity sensor content function command Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Redmi vpn Huawei Docker