系统环境:Centos7.4,系统自带python2.7.5

登录psutil官网,下载psutil的tar包:psutil-5.4.6.tar.gz,并使用命名sha256sum和官网的包进行核对,确保下载的包没有进行篡改。

  此次试验是下载到/mnt/下,依次执行如下操作:

  tar zxf psutil-5.4.6.tar.gz

  cd psutil-5.4.6

  python setup.py  install

  python

如果安装psutil没有问题,则:

[root@localhost ~]# python
Python 2.7.5 (default, Jul 13 2018, 13:06:57)
[GCC x.x.x xxxxxxxx (Red Hat xxxx-xxx)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil

>>>exit()

此时证明安装psutil模块没有问题,可以直接使用。python脚本需要以.py结尾。文件开头:

#!/usr/bin/python   ##python的安装路径

#-*- coding: utf-8 -*-       ##编码格式的定义

import psutil    ##导入需要使用的模块

为了便于显示效果,以下是在Python命令行执行:

>>> import psutil

>>> psutil.cpu_percent()    ##CPU平均使用率
0.0

>>> psutil.cpu_percent(percpu=True)    ##每颗CPU的使用率

[0.1, 0.3, 0.2, 0.2]

>>> psutil.cpu_count()      ##CPU物理颗数
4
>>> psutil.virtual_memory()    ##内存使用情况
svmem(total=1911857152, available=1534185472, percent=19.8, used=222138368, free=1521319936, active=154025984, inactive=89636864, buffers=16433152, cached=151965696, shared=9072640, slab=64802816)

>>> psutil.swap_memory()    ##swap空间使用情况
sswap(total=21474832384, used=0, free=21474832384, percent=0.0, sin=0, sout=0)

>>> psutil.pids()        ##获取系统所有的进程ID
[1, 2, 3, 5, 7, 8, 9, 10, 11,……]

>>> psutil.Process(pid)    ##根据进程ID,查看进程名

>>> psutil.net_io_counters()    ##查看网络包情况
snetio(bytes_sent=113097, bytes_recv=292916, packets_sent=1228, packets_recv=3817, errin=0, errout=0, dropin=0, dropout=0)

>>> psutil.disk_partitions()         ##查看磁盘挂载情况
[sdiskpart(device='/dev/sda3', mountpoint='/', fstype='ext4', opts='rw,seclabel,relatime,data=ordered'), sdiskpart(device='/dev/sda1', mountpoint='/boot', fstype='ext4', opts='rw,seclabel,relatime,data=ordered'), sdiskpart(device='/dev/mapper/centos-var', mountpoint='/var', fstype='ext4', opts='rw,seclabel,relatime,data=ordered'), sdiskpart(device='/dev/mapper/centos-home', mountpoint='/home', fstype='ext4', opts='rw,seclabel,relatime,data=ordered'), sdiskpart(device='/dev/mapper/centos-data', mountpoint='/data', fstype='ext4', opts='rw,seclabel,relatime,data=ordered')]

>>> psutil.disk_usage("/")    ##具体某个挂载点的使用情况
sdiskusage(total=10186727424, used=1086652416, free=8559009792, percent=11.3)

python2.7系统性能监控psutil模块的更多相关文章

  1. [Python监控]psutil模块简单使用

    安装很简单 pip install psutil 官网地址为 https://pythonhosted.org/psutil/ (文档上有详细的api) github地址为 https://githu ...

  2. python之psutil模块(获取系统性能数据)

    psutil模块 1.介绍 psutil是一个跨平台库(http://code.google.com/p/psutil/),能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等) ...

  3. python之psutil模块(获取系统性能信息(CPU,内存,磁盘,网络)

    一.psutil模块 1. psutil是一个跨平台库(http://code.google.com/p/psutil/),能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等) ...

  4. 系统性能信息模块之psutil模块

    一.psutil模块介绍 官方网址:https://pypi.org/ psutil模块安装:https://github.com/giampaolo/psutil/blob/master/INSTA ...

  5. 1.python系统性能信息模块之psutil模块

    Psutil(进程和系统实用程序)是一个跨平台的库,用于在Python中检索有关运行进程和系统资源利用率(CPU,内存,磁盘,网络)的信息.它主要用于系统监视,分析和限制系统资源及运行进程的管理.它实 ...

  6. Python-添加psutil模块到python2.7版本

    一.问题描述 1.导入模块psutil时提示报错:ImportError: No module named psutil 2.下载psutil模块后,安装python setup.py install ...

  7. python之系统性能信息模块psutil

    系统性能信息模块psutil 跨平台库 轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等)信息. 主要用于系统监控,分析和限制系统资源及进程的管理 实现同等命令行工具提供的功能( ...

  8. 15.python笔记之psutil模块

    一.psutil模块 1. psutil是一个跨平台库(http://code.google.com/p/psutil/),能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等) ...

  9. 自动化之路 python psutil模块 收集硬件信息

    一.psutil模块 1. psutil是一个跨平台库,能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等)信息.它主要应用于系统监控,分析和限制系统资源及进程的管理.它实现了 ...

随机推荐

  1. [转载]Java web应用中的常见字符编码问题的解决方法

    以下是 Java web应用的常见编码问题 1. html页面的编码 在web应用中,通常浏览器会根据http header: Content-type的值来决定用什么encoding, 比如遇到Co ...

  2. python 统计单词出现次数

    #use python3.6 import re from collections import Counter FILESOURCE = './abc.txt' def getMostCommonW ...

  3. 第6条:在单次切片操作内,不要同时指定start、end和stride

    核心知识点: 1.使用负步进可以反转取值字符串及ASCII. 2.stride最好不要与start和end用在一起,会降低代码可读性. 除了基本的切片操作之外,python还提供了somelist[s ...

  4. 【leetcode刷题笔记】Decode Ways

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...

  5. 左侧图片 右侧块的实现方法---解决3像素bug的一种解决方案,不用浮动用绝对定位和margin-left

    google的实现方式是: <div class="mw"> <a href="/" id="mlogo">  &l ...

  6. hd acm1017

    Problem Description Given two integers n and m, count the number of pairs of integers (a,b) such tha ...

  7. B表中的pid对应A表中id,查询A表中数据,根据b表中对应a表中该id的数据数目排序

    B表中的pid对应A表中id,查询A表中数据,根据b表中对应a表中该id的数据数目排序 select a.*,count(*) as c from a left join b on a.id=b.ai ...

  8. explain分析sql效果

    1.id:  代表select 语句的编号, 如果是连接查询,表之间是平等关系, select 编号都是1,从1开始. 如果某select中有子查询,则编号递增.如下一条语句2个结果 mysql> ...

  9. SrpingCloud 之SrpingCloud config分布式配置中心搭建

    1.搭建git环境   目的:持久化存储配置文件信息 采用码云 创建后 继续创建文件夹  用来区分不同的项目 下面就是git上存放配置文件了.环境的区分 dev  sit pre prd   开发  ...

  10. SparkRDD内核

    Spark内核 RDD是基础,是spark中一个基础的抽象,是不可变的,比如我们加载进的数据RDD,如果想更改其中的内容是不允许的:分区的集合,可以并行来计算:RDD类中包含了很多基础的操作,例如ma ...