查看CPU占用高的top15进程

ps -eo pid,user,%cpu,%mem,argu --cols  | sort -nrk  | head -n 

查看内存占用高的top15进程

ps -eo pid,user,%cpu,%mem,argu --cols  | sort -nrk  | head -n 

查看IO占用高的top15进程

./ind_high_io_process.py 3 4 5。其中3表示间隔3秒获取一次数据。4表示获取读、写IO最高的前4个IO进程。5表示程序运行5次。

#!/bin/python
#-*- coding:utf-8 -*-
# Filename: ind_high_io_process
# Revision: 1.0
# Date: 2013-3-8
# Author: simonzhang
# web: www.simonzhang.net
# Email: simon-zzm@163.com
### END INIT INFO
import os
import re
import sys
import time
from string import strip sys_proc_path = '/proc/'
re_find_process_number = '^\d+$' #Get IO information from /proc/$pid/io def collect_info():
_tmp = {}
re_find_process_dir = re.compile(re_find_process_number)
for i in os.listdir(sys_proc_path):
if re_find_process_dir.search(i):
#get process name from /proc/${pid}/stat
process_name = open("%s%s/stat" % (sys_proc_path, i), "rb").read().split(" ")[1]
# get io information from /proc/${pid}/io
rw_io = open("%s%s/io" % (sys_proc_path, i), "rb").readlines()
for _info in rw_io:
cut_info = strip(_info).split(':')
if strip(cut_info[0]) == "read_bytes":
read_io = int(strip(cut_info[1]))
if strip(cut_info[0]) == "write_bytes":
write_io = int(strip(cut_info[1]))
_tmp[i] = {"name":process_name, "read_bytes":read_io, "write_bytes":write_io}
return _tmp def main(_sleep_time, _list_num):
_sort_read_dict = {}
_sort_write_dict = {}
#Get system io information
process_info_list_frist = collect_info()
time.sleep(_sleep_time)
process_info_list_second = collect_info() for loop in process_info_list_second.keys():
second_read_v = process_info_list_second[loop]["read_bytes"]
second_write_v = process_info_list_second[loop]["write_bytes"]
try:
frist_read_v = process_info_list_frist[loop]["read_bytes"]
except:
frist_read_v = 0
try:
frist_write_v = process_info_list_frist[loop]["write_bytes"]
except:
frist_write_v = 0
# compute
_sort_read_dict[loop] = second_read_v - frist_read_v
_sort_write_dict[loop] = second_write_v - frist_write_v
# sort
sort_read_dict = sorted(_sort_read_dict.items(),key=lambda _sort_read_dict:_sort_read_dict[1],reverse=True)
sort_write_dict = sorted(_sort_write_dict.items(),key=lambda _sort_write_dict:_sort_write_dict[1],reverse=True)
# print result
print "pid process read(bytes) pid process write(btyes)"
for _num in range(_list_num):
read_pid = sort_read_dict[_num][0]
write_pid = sort_write_dict[_num][0]
res = "%s" % read_pid
res += " " * (8 - len(read_pid)) + process_info_list_second[read_pid]["name"]
res += " " * (12 - len(process_info_list_second[read_pid]["name"])) + "%s" % sort_read_dict[_num][1]
res += " " * (12 - len("%s" % sort_read_dict[_num][1])) + write_pid
res += " " * (8 - len(write_pid)) + process_info_list_second[write_pid]["name"]
res += " " * (12 - len("%s" % process_info_list_second[write_pid]["name"])) + "%s" % sort_write_dict[_num][1]
print res
print "\n" * 1 if __name__ == '__main__':
try:
_sleep_time = sys.argv[1]
except:
_sleep_time = 3
try:
_num = sys.argv[2]
except:
_num = 3
try:
loop = sys.argv[3]
except:
loop = 1
for i in range(int(loop)):
main(int(_sleep_time), int(_num))

参考资料

https://zhidao.baidu.com/question/1882904486137130588.html

Linux查看CPU、内存、IO占用高的进程的更多相关文章

  1. linux 查看CPU内存 网络 流量 磁盘 IO

    使用vmstat命令来察看系统资源情况 在命令行方式下,如何查看CPU.内存的使用情况,网络流量和磁盘I/O? Q: 在命令行方式下,如何查看CPU.内存的使用情况,网络流量和磁盘I/O? A: 在命 ...

  2. linux 查看cpu 内存 硬盘 文件夹大小

    文件夹大小 显示cpu使用率 top 1 查看CPU 1.1 查看CPU个数 # cat /proc/cpuinfo | grep "physical id" | uniq | w ...

  3. linux查看cpu内存信息

    # 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数 cat /proc/cpuinfo| ...

  4. python glances来监控linux服务器CPU 内存 IO使用

    什么是 Glances? Glances 是一个由 Python 编写,使用 psutil 库来从系统抓取信息的基于 curses 开发的跨平台命令行系统监视工具. 通过 Glances,我们可以监视 ...

  5. 找出linux服务器IO占用高的程序

     一台服务器比较性能无外乎内存.cpu使用率.IO使用率,把这3样优化好了,你服务器的负载就要小很多,当然网络情况不在我的考虑范围,毕竟网络这个情况是很不稳定,就算你服务器上把网络优化得再好,idc不 ...

  6. Linux查看CPU和内存使用情况 【转】

    Linux查看CPU和内存使用情况 在系统维护的过程中,随时可能有需要查看 CPU 使用率,并根据相应信息分析系统状况的需要.在 CentOS 中,可以通过 top 命令来查看 CPU 使用状况.运行 ...

  7. Linux查看CPU和内存情况

    本文简单介绍在Linux上查看CPU和内存情况和一款系统资源查看工具htop. 查看CPU情况 以下是个人工作会经常使用到的服务器的信息. 查看所有CPU信息 可以通过如下命令查看所有CPU信息: # ...

  8. Linux查看CPU和内存使用情况总结

    Linux查看CPU和内存使用情况:http://www.cnblogs.com/xd502djj/archive/2011/03/01/1968041.html 在做Linux系统优化的时候,物理内 ...

  9. 如何在 Linux 中找出 CPU 占用高的进程

    1) 怎样使用 top 命令找出 Linux 中 CPU 占用高的进程 在所有监控 Linux 系统性能的工具中,Linux 的 top 命令是最好的也是最知名的一个.top 命令提供了 Linux ...

随机推荐

  1. windows 日志解决方法

    1.sql server 2012 报错 MSSQLSERVER 服务无法使用当前配置的密码以 .\MSSQL_SF_A9JGSK 身份登录,错误原因如下: 此帐户的密码已过期. 要确保服务配置正确, ...

  2. Python绘制2D图像

    封装了一个简单的2d绘图函数 from matplotlib import pyplot as plt def plot_line(*args, **kw): """ : ...

  3. xinetd网络

    简单Web服务器 基本的HTTP协议 请求服务器数据 GET /文件或目录 HTTP/1.1 协议头部分(可选) /r/n(协议头结束) 服务器应答浏览器 HTTP/1.1 200 OK conten ...

  4. JavaScript常见的创建对象的几种方式

    1.通过Object构造函数或对象字面量创建单个对象 这些方式有明显的缺点:使用同一个接口创建很多对象,会产生大量的重复代码.为了解决这个问题,出现了工厂模式. 2.工厂模式 考虑在ES中无法创建类( ...

  5. update 中实现子查询

    mysql 在update中实现子查询的方式   当使用mysql条件更新时--最先让人想到的写法 UPDATE buyer SET is_seller=1 WHERE uid IN (SELECT  ...

  6. 【Selenium-WebDriver自学】Selenium测试设计技术(十三)

    Selenium页面对象模型 1.Selenium页面对象模型 优点 页面的对象模型是其中测试对象和功能被彼此分开,从而保持代码干净的实现. 对象保持独立的测试脚本.一个目的可以通过一个或多个测试脚本 ...

  7. 《C++数据结构-快速拾遗》 基础常识

    1.命名空间函数 namespace wjy { void print() { cout<<"; } int load(int num) { return num; } } us ...

  8. springBoot_freemark配置

    Spring Boot –test 1.添加依赖 <!-- 引入 spring-boot-starter-test 集成单元测试--> <dependency> <gro ...

  9. 代码: html 页面小效果 (集合,待补充)

    标签切换(下部内容区跟着切换): 2016-6-2 <script type="text/javascript" src="http://cdn.bootcss.c ...

  10. java 权重随机算法实现

    import java.util.*; /** * 权重随机算法实现 * a b c d 对应权重范围 --- [0,1).[1,3).[3,6).[6,10) */ public class Ran ...