我要写个(python)运维监控软件

psuitl模块学习
CPU

psutil.cpu_count( ) CPU逻辑数量
1

psutil.cpu_count( logical=False ) CPU物理数量
1
内存

psutil.virtual_memory( ) 内存的信息
svmem(total=2078871552, available=368168960, percent=82.3, used=1467621376, free=72568832, active=1025441792, inactive=517386240, buffers=692224, cached=537989120, shared=50515968, slab=233480192)

m = psutil.virtual_memory( )
m.total 内存总数
2078871552

m.free 未使用的内存
72425472

交换分区

psutil.swap_memory( ) 交换分区信息
sswap(total=3171475456, used=4202496, free=3167272960, percent=0.1, sin=6545408, sout=9482240)

磁盘
psutil.disk_io_counters( psutil.disk_partitions( psutil.disk_usage( 磁盘信息的命令

psutil.disk_partitions( ) 磁盘完整信息
[sdiskpart(device=’/dev/mapper/centos-root’, mountpoint=’/’, fstype=‘xfs’, opts=‘rw,relatime,attr2,inode64,noquota’), sdiskpart(device=’/dev/sda1’, mountpoint=’/boot’, fstype=‘xfs’, opts=‘rw,relatime,attr2,inode64,noquota’), sdiskpart(device=’/dev/sr0’, mountpoint=’/run/media/root/CentOS 7 x86_64’, fstype=‘iso9660’, opts=‘ro,nosuid,nodev,relatime,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500’)]

psutil.disk_usage( “/” ) 磁盘分区的使用情况
sdiskusage(total=18238930944, used=8913346560, free=9325584384, percent=48.9)

psutil.disk_io_counters( ) 磁盘的读写情况
sdiskio(read_count=76739, write_count=35629, read_bytes=5081857024, write_bytes=774587392, read_time=2445606, write_time=4432420, read_merged_count=1515, write_merged_count=7474, busy_time=690300)

网络
psutil.net… 查看网络情况

用户
psutil.users( ) 当前用户的信息
[suser(name=‘root’, terminal=’:0’, host=‘localhost’, started=1561507200.0, pid=2232), suser(name=‘root’, terminal=‘pts/0’, host=‘localhost’, started=1561507200.0, pid=3222), suser(name=‘root’, terminal=‘pts/1’, host=‘1,1,1,1’, started=1561598720.0, pid=41107

进程

psutil.pids( )
[1, 2, 3, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 27, 28, 29, 30, 38, 40, 41, 42, 44, 57, 89, 266, 267, 268, 274, 275, 278, 280, 281 …

p = psutil.Process(41107)
p.name( )
‘bash’

p.status( )
‘sleeping’

p.num_threads( )
1

你可能感兴趣的:(我要写个(python)运维监控软件)