zoukankan      html  css  js  c++  java
  • Locust学习笔记(4)

    psutil是一个开源切跨平台的库,其提供了便利的函数用来获取才做系统的信息,比如CPU,内存,磁盘,网络等。此外,psutil还可以用来进行进程管理,包括判断进程是否存在、获取进程列表、获取进程详细信息等。而且psutil还提供了许多命令行工具提供的功能,包括:ps,top,lsof,netstat,ifconfig, who,df,kill,free,nice,ionice,iostat,iotop,uptime,pidof,tty,taskset,pmap。

    官网:https://github.com/giampaolo/psutil

    安装:

    pip install psutil

    示例:

    CPU
    print
    (psutil.cpu_count()) #查看CPU逻辑数量 print(psutil.cpu_count(logical=False)) #查看CPU物理核心 print(psutil.cpu_percent()) #查看CUP利用率 内存 print(psutil.virtual_memory()) #查看物理内存 print(psutil.swap_memory()) #查看交换内存
    磁盘 print(psutil.disk_usage('/')) # 磁盘使用情况 print(psutil.disk_partitions()) #磁盘分区信息 print(psutil.disk_io_counters()) #磁盘IO
    进程 print(psutil.pids()) #获取所有进程ID print(psutil.Process(492).name()) #获取ID为492的进程的进程名
    模拟ps的效果 print(psutil.test()) #模拟ps命令的效果

    运行结果:

    为了好看,没有包含模拟ps效果的命令

    进程列表缩减了一些

    8
    4
    0.0
    svmem(total=34325086208, available=23755714560, percent=30.8, used=10569371648, free=23755714560)
    sswap(total=36472569856, used=14665351168, free=21807218688, percent=40.2, sin=0, sout=0)
    sdiskusage(total=860924932096, used=595925602304, free=264999329792, percent=69.2)
    [sdiskpart(device='C:\', mountpoint='C:\', fstype='NTFS', opts='rw,fixed'), sdiskpart(device='D:\', mountpoint='D:\', fstype='NTFS', opts='rw,fixed')]
    sdiskio(read_count=1124755, write_count=1043495, read_bytes=70079310336, write_bytes=95704267264, read_time=910, write_time=490)
    [0, 4, 120, 492, 7580,10964, 21220]
    smss.exe

    一个实时打印系统CPU使用率,内存使用率的例子

    import psutil
    import time
    
    print("CPU使用率  内存使用率")
    delay = 1
    
    while True:
        time.sleep(delay)
        print(str(psutil.cpu_percent()) + "%      " + str(psutil.virtual_memory().percent) + "%     ")

    运行结果

  • 相关阅读:
    showModalDialog()、showModelessDialog()方法使用详解
    Oracle 8i在GNU/Linux上的安装笔记
    TURBOLinux 7.0下安装Oracle 8.1.7.0.1 release 3
    [Oracle]初识Oracle8i(8.0.5)
    (三)
    退出win不保存设置
    Windows 2000/NT/XP管理员密码丢失解决方法
    DCOM错误:DefaultLaunchPermssion 访问被拒绝
    找到一些工具
    O/R MAP 和 ObjectSpaces 资料
  • 原文地址:https://www.cnblogs.com/ronyjay/p/13804046.html
Copyright © 2011-2022 走看看