查看CPU状况 查看内存消耗 查看磁盘IO 查看网络状况 系统缓存清除

2015-07-20 21:03:00
admin
原创 2923
摘要:查看CPU状况 查看内存消耗 查看磁盘IO 查看网络状况 系统缓存清除

一、查看CPU状况

top -c -d delay -n iterations -p pid[,...]

1、-d delay,多久刷新一次性能数据,默认2秒;

2、-n iterations,刷新多少次性能数据,默认一直刷新;

3、-c,显示命令路径和调用参数;

4、-p pid,显示指定进程的性能;

5、常用命令:h-显示命令帮助,1-Toggle SMP view;


显示列说明:

PR,进程优先级,值越小优先级越高;

NI,进程nice值,-20到19,值越小优先级越高;

VIRT,虚拟内存使用量,包括RES和SWAP

RES,物理内存使用量,包括进程的SHR

SHR,共享内存使用量;


进程的5种状态码: 
D 不可中断 uninterruptible sleep (usually IO) 
R 运行 runnable (on run queue) 
S 中断 sleeping 
T 停止 traced or stopped 
Z 僵死 a defunct ("zombie") process


如何使用load average:

load average: 0.05, 0.01, 0.00,1、5、15分钟任务队列的平均长度;
先看15分钟负载,如果负载很高,再看1分钟和5分钟负载,查看是否有下降趋势;
1分钟负载很大,我们不用担心,如果15分钟负载都很高,要赶紧看看发生了什么事情;


单核情况的load average解释:
0.7 < load < 1,此时状态不错,如果进来更多的汽车,马路仍可以应付;
load = 1,马路即将拥堵,没有更多的资源执行额外的任务;
load > 5,非常拥堵,马路非常繁忙,每辆车都无法很快运行;

二、查看内存消耗

free [-b | -k | -m | -g] [-s delay ]

-b,以字节显示内存;

-k,以k显示内存,默认以k显示;

-m,以兆显示内存;

-g,以GB显示内存;

-s,每隔多少秒显示一次;


三、查看磁盘IO

pidstat options [ interval [ count ] ]

-d,查看磁盘IO;

-p { pid[,...] | SELF | ALL },查看指定进程;


四、查看网络状况

sar options [interval [count ]],收集展示系统运行信息。

1、-n { keyword[,...] | ALL },查看网络性能;

2、interval=0,显示系统启动以来的平均值;

3、不设置count,统计一直会周期性运行;


sar -n DEV 1 2
21时18分25秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
21时18分26秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
21时18分26秒      eth0      8.00      0.00      0.56      0.00      0.00      0.00      0.00
21时18分26秒      eth1      0.00      0.00      0.00      0.00      0.00      0.00      0.00


21时18分26秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
21时18分27秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
21时18分27秒      eth0      2.97      0.99      0.21      0.18      0.00      0.00      0.00
21时18分27秒      eth1      0.00      0.00      0.00      0.00      0.00      0.00      0.00


平均时间:     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
平均时间:        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均时间:      eth0      5.47      0.50      0.38      0.09      0.00      0.00      0.00
平均时间:      eth1      0.00      0.00      0.00      0.00      0.00      0.00      0.00


五、系统缓存清除

操作系统可用内存:free memory;

应用进程可用内存:free memory+buffers+cached,buffers和cached可以很快回收;

buffers:磁盘缓存;

cached:频繁访问的文件缓存,如果很大说明缓存的文件很多


To free pagecache, use echo 1 >/proc/sys/vm/drop_caches;
To free dentries and inodes, use echo 2 >/proc/sys/vm/drop_caches;
To free pagecache, dentries and inodes, use echo 3 >/proc/sys/vm/drop_caches;
Because this is a non-destructive operation and dirty objects are not freeable, the user should run sync first.


清除缓存:

sync,同步到磁盘
echo 3 >/proc/sys/vm/drop_caches,清除缓存

发表评论
评论通过审核之后才会显示。