Linux查看CPU、内存、IO占用高的进程
查看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占用高的进程的更多相关文章
- linux 查看CPU内存 网络 流量 磁盘 IO
使用vmstat命令来察看系统资源情况 在命令行方式下,如何查看CPU.内存的使用情况,网络流量和磁盘I/O? Q: 在命令行方式下,如何查看CPU.内存的使用情况,网络流量和磁盘I/O? A: 在命 ...
- linux 查看cpu 内存 硬盘 文件夹大小
文件夹大小 显示cpu使用率 top 1 查看CPU 1.1 查看CPU个数 # cat /proc/cpuinfo | grep "physical id" | uniq | w ...
- linux查看cpu内存信息
# 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数 cat /proc/cpuinfo| ...
- python glances来监控linux服务器CPU 内存 IO使用
什么是 Glances? Glances 是一个由 Python 编写,使用 psutil 库来从系统抓取信息的基于 curses 开发的跨平台命令行系统监视工具. 通过 Glances,我们可以监视 ...
- 找出linux服务器IO占用高的程序
一台服务器比较性能无外乎内存.cpu使用率.IO使用率,把这3样优化好了,你服务器的负载就要小很多,当然网络情况不在我的考虑范围,毕竟网络这个情况是很不稳定,就算你服务器上把网络优化得再好,idc不 ...
- Linux查看CPU和内存使用情况 【转】
Linux查看CPU和内存使用情况 在系统维护的过程中,随时可能有需要查看 CPU 使用率,并根据相应信息分析系统状况的需要.在 CentOS 中,可以通过 top 命令来查看 CPU 使用状况.运行 ...
- Linux查看CPU和内存情况
本文简单介绍在Linux上查看CPU和内存情况和一款系统资源查看工具htop. 查看CPU情况 以下是个人工作会经常使用到的服务器的信息. 查看所有CPU信息 可以通过如下命令查看所有CPU信息: # ...
- Linux查看CPU和内存使用情况总结
Linux查看CPU和内存使用情况:http://www.cnblogs.com/xd502djj/archive/2011/03/01/1968041.html 在做Linux系统优化的时候,物理内 ...
- 如何在 Linux 中找出 CPU 占用高的进程
1) 怎样使用 top 命令找出 Linux 中 CPU 占用高的进程 在所有监控 Linux 系统性能的工具中,Linux 的 top 命令是最好的也是最知名的一个.top 命令提供了 Linux ...
随机推荐
- log4net 配置允许同时写日志到同一个文件
RollingFileAppender appender = new RollingFileAppender();... appender.LockingModel = new FileAppende ...
- 在线学习和在线凸优化(online learning and online convex optimization)—FTL算法5
最自然的学习规则是使用任何在过去回合中损失最小的向量. 这与Consistent算法的精神相同,它在在线凸优化中通常被称为Follow-The-Leader,最小化累积损失. 对于任何t: 我们谈到了 ...
- plugin 看不到update按钮
然后再按一下tab键,焦点就会在 update上了.然后再回车.
- GIT命令行笔记
一次常规的初始化+推送: git initgit config user.email "you@example.com"git config user.name "asm ...
- tp5生成小程序推广二维码
//获取用户经销商信息 及生成推广二维码 public function qrcode() { //拿到openid 查找用户表内是否有该用户 没有则拒绝生成二维码 有则查看是否已生成二维码 有生成则 ...
- Java 7-Java 循环结构 - for, while 及 do…while
Java 循环结构 - for, while 及 do...while 顺序结构的程序语句只能被执行一次.如果您想要同样的操作执行多次,,就需要使用循环结构. Java中有三种主要的循环结构: whi ...
- JS静态变量和函数、实例变量和函数以及prototype 说明
静态变量.函数 当定义一个函数后通过 “.”为其添加的属性和函数,通过对象本身仍然可以访问得到,但是其实例却访问不到,这样的变量和函数分别被称为静态变量和静态函数,用过Java.C#的同学很好理解静态 ...
- 浅谈jmeter请求参数获取的方式
一.传统的web端请求参数我们在浏览器url栏看到传递的参数是什么,比如百度: 1.我们假如百度有一个这样的地址: https://www.baidu.com/s?wd=jmeter&name ...
- 介绍Collection框架的结构;Collection 和 Collections的区别
介绍Collection框架的结构:Collection 和 Collections的区别 集合框架: Collection:List列表,Set集 Map:Hashtable,HashMap,Tre ...
- Eureka 客户端启动报错误 Cannot determine embedded database driver class for database type NONE
用这种数据库配置就是死活连不上数据库 提示:Cannot determine embedded database driver class for database type NONE 解决方式: 启 ...