mac下python实现vmstat
mac下没有linux/unix 的vmstat,只有vm_stat;
sh-3.2# vm_stat
Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free: 191876.
Pages active: 433086.
Pages inactive: 141819.
Pages speculative: 23119.
Pages throttled: 0.
Pages wired down: 254606.
Pages purgeable: 11895.
"Translation faults": 20445131.
Pages copy-on-write: 1435992.
Pages zero filled: 10414067.
Pages reactivated: 39459.
Pages purged: 23388.
File-backed pages: 172905.
Anonymous pages: 425119.
Pages stored in compressor: 12595.
Pages occupied by compressor: 3399.
Decompressions: 5824.
Compressions: 26966.
Pageins: 1626450.
Pageouts: 4218.
Swapins: 1487.
Swapouts: 5130.
不想用下面这个复杂top命令
sh-3.2# top -l 1 -s 0 | grep PhysMem
PhysMem: 3277M used (992M wired), 817M unused.
用下面这个python
#!/usr/bin/python import subprocess
import re # Get process info
ps = subprocess.Popen(['ps', '-caxm', '-orss,comm'], stdout=subprocess.PIPE).communicate()[0]
vm = subprocess.Popen(['vm_stat'], stdout=subprocess.PIPE).communicate()[0] # Iterate processes
processLines = ps.split('\n')
sep = re.compile('[\s]+')
rssTotal = 0 # kB
for row in range(1,len(processLines)):
rowText = processLines[row].strip()
rowElements = sep.split(rowText)
try:
rss = float(rowElements[0]) * 1024
except:
rss = 0 # ignore...
rssTotal += rss # Process vm_stat
vmLines = vm.split('\n')
sep = re.compile(':[\s]+')
vmStats = {}
for row in range(1,len(vmLines)-2):
rowText = vmLines[row].strip()
rowElements = sep.split(rowText)
vmStats[(rowElements[0])] = int(rowElements[1].strip('\.')) * 4096 print 'Wired Memory:\t\t%d MB' % ( vmStats["Pages wired down"]/1024/1024 )
print 'Active Memory:\t\t%d MB' % ( vmStats["Pages active"]/1024/1024 )
print 'Inactive Memory:\t%d MB' % ( vmStats["Pages inactive"]/1024/1024 )
print 'Free Memory:\t\t%d MB' % ( vmStats["Pages free"]/1024/1024 )
print 'Real Mem Total (ps):\t%.3f MB' % ( rssTotal/1024/1024 )
sh-3.2# ./mem.py
Wired Memory: 1013 MB
Active Memory: 1951 MB
Inactive Memory: 573 MB
Free Memory: 423 MB
Real Mem Total (ps): 3180.027 MB
mac下python实现vmstat的更多相关文章
- Mac下python初学之Image库(PIL)
Mac下python 使用Image库 安装PIL,下载http://www.pythonware.com/products/pil/ 解压PIL源码包,阅读README知道需要使用python se ...
- mac下python环境pip报错[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) 的解决方法
1.mac下python环境pip报错: issuserdeMacBook-Pro:~ issuser$ pip install pyinstallerCollecting pyinstaller ...
- Mac 下 python 环境问题
一.Mac下,可能存在的 python 环境: 1.Mac系统自带的python环境在(由于不同的 mac 系统,默认自带的 python 版本可能不一样): Python 2.7.10: /Syst ...
- Mac下Python和Pycharm之virtualenv
一.python如何配置virtualenv 1.安装virtualenv pip3 install virtualenvpip install -i https://pypi.tuna.tsin ...
- mac 下 python 虚拟环境的安装和配置
前言:继续安装中,这节记录 mac 安装 python 虚拟环境,多版本共存... 1. 安装 pip -- python的包管理工具: sudo easy_install pip 安装成功,出现下面 ...
- mac下Python安装路径的说明
Python安装路径的说明 mac在安装Python时, 对不同的安装方式 不同的型号均会安装在不同的文件夹下 安装方式 路径 系统默认(2.7) /System/Library/Frameworks ...
- 在MAC下 Python+Django+mysql配置
今天在搭建Django+mysql环境的时候遇到了一点问题,记录下来. 安装环境:OS X 10.10操作系统,Python 2.7. MySQLdb其实包含在MySQL-python包中,因此无论下 ...
- [转]mac下Python升级到指定的版本
以2.7升级到3.3为例1.删除原版本a)删除系统库中的版本sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7 b) ...
- mac下python安装MySQLdb模块
参考:http://blog.csdn.net/yelyyely/article/details/41114449 1.调整到anaconda下的python 2.安装有关程序 brew instal ...
随机推荐
- 使用的组件:Jcrop
JcropImage cropping for jQuery Jcrop 是一个功能强大的 jQuery 图像裁剪插件,结合后端程序(例如:PHP)可以快速的实现图片裁剪的功能. 官网地址:http: ...
- Spring <context:annotation-config/> 解说
在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-config/>这样一条配置,他的作用是式地向 Spring 容器注册 AutowiredA ...
- QT中QProcess调用命令行的痛苦经历
在QT程序中需要将某些目录和文件压缩为一个rar的压缩包,于是想到了在QT中通过QProcess类调用命令行的rar.exe来达到效果,但是没想到QProcess类用起来很麻烦,而且达不到效果,折腾了 ...
- [游戏模版11] Win32 动画 时间消息
>_<:This time we will study a new way to operate your picture.That is running your picture by ...
- CheckStyle, 强制你遵循编码规范
如今代码静态检查越来越重要,已经成为构建高质量软件的不可或缺的一个验证步骤.如果你使用的是java语言,那么CheckStyle则是一个利器. CheckStyle能够帮助程序员检查代码是否符合制定的 ...
- CSS Sticky Footer: 完美的CSS绝对底部
CSS的简单在于它易学,CSS的困难在于寻找更好的解决方案.在CSS的世界里,似乎没有完美这种说法.所以,现在介绍的CSS绝对底部,只是目前个人见过的方案中比较完美的吧. 先说我们为什么会使用到这个C ...
- js如何实现继承
js继承有5种实现方式:1.继承第一种方式:对象冒充 function Parent(username){ this.username = username; this.hello = ...
- MySQL分库分表总结参考
单库单表 单库单表是最常见的数据库设计,例如,有一张用户(user)表放在数据库db中,所有的用户都可以在db库中的user表中查到. 单库多表 随着用户数量的增加,user表的数据量会越来越大,当数 ...
- Eclipse连接到My sql数据库的操作总结/配置数据库驱动
Eclipse连接到MYSQL数据库的操作 (自己亲测,开始学习Eclipse(我的Eclipse版本是4.5.2,Jdbc驱动器的jar包版本是5.1.7,亲测可以使用)连接到数据库的时候,发现网上 ...
- 【锁】Oracle锁系列
[锁]Oracle锁系列 1 BLOG文档结构图 2 前言部分 2.1 导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~O(∩_∩)O~: ...