查看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. Change default network name (ens33) to old “eth0” on Ubuntu 18.04 / Ubuntu 16.04

    Change default network name (ens33) to old “eth0” on Ubuntu 18.04 / Ubuntu 16.04 By Raj Last updated ...

  2. spark streaming的有状态例子

    import org.apache.spark._ import org.apache.spark.streaming._ /** * Created by code-pc on 16/3/14. * ...

  3. 《Linux 性能及调优指南》1.1 Linux进程管理

    https://blog.csdn.net/ljianhui/article/details/46718835 本文为IBM RedBook的Linux Performanceand Tuning G ...

  4. 7 家 IT 厂商 6394.5 万元中标天津公安云项目(虚拟化、数据库、软件开发)

    http://mp.weixin.qq.com/s/kjum54HJorGTPtZiM-HE1g 天津市公安局云计算平台项目分为:大数据部分.虚拟化部分.数据库部分,软件开发部分,预算分别为:2350 ...

  5. Apache服务器下phalcon项目报Mod-Rewrite is not enabled问题

    问题如图: 项目已经按照官网的教程修改了.htaccess文件,仍旧报此错误,判断可能是apache未添加mod_rewrite,通过查询资料,经以下两步解决此问题: 1.执行sudo a2enmod ...

  6. JDK 8 中Lambda表达式的使用

    认识Lambda表达式 首先来引入一个示例 new Thread(new Runnable() {     @Override     public void run() {         Syst ...

  7. android 相对布局例子代码

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  8. 8.2.优化SQL语句

    8.2.优化SQL语句 数据库应用程序核心操作逻辑都是通过执行SQL语句来执行,不管是直接通过解释器还是通过后台API提交. 调优手册里面的这一节内容帮助各种各样MySQL程序加快速度.手册包括SQL ...

  9. 47.纯 CSS 创作一个蝴蝶标本展示框

    html,body{ margin:; padding:; } body{ height: 100vh; display: flex; justify-content: center; align-i ...

  10. python中strip、startswith、endswith

    strip(rm)用来删除元素内的空白符: rm对应要删除空白符的元素,当rm为空(strip())时删除所有元素的空白符 startswith.endswith用来查找开头或结尾条件的元素 例子: ...