Linux系统上的进程查看及管理工具:
pstree , ps , pgrep , pkill , pidof ;
uptime , top ;
htop , vmstat , pmap , glances ;
dstat ;
kill , killall ;
job , bg , fg , nohup , nice , renice , …;
关键词:dstat;
1、dstat 命令
命令说明:用于生成系统资源统计信息的通用工具;
dstat – versatile tool for generating system resource statistics
命令格式:
dstat [-afv] [options..] [delay [count]]
‘dstat’不带任何选项参数,默认显示如下:
[root@kouyuushinn ~]# dstat You did not select any stats, using -cdngy by default. ----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system-- usr sys idl wai hiq siq| read writ| recv send| in out | int csw 0 0 100 0 0 0|6993B 8631B| 0 0 | 0 8B| 37 33 0 1 99 0 0 0| 0 0 | 120B 842B| 0 0 | 71 65 5 5 90 0 0 0| 0 0 |3170B 135k| 0 0 | 199 95 0 0 100 0 0 0| 0 0 | 180B 362B| 0 0 | 70 66 0 0 100 0 0 0| 0 0 | 120B 362B| 0 0 | 64 56 6 6 88 0 0 0| 0 0 |3170B 135k| 0 0 | 205 96 0 0 100 0 0 0| 0 0 | 60B 362B| 0 0 | 61 56 0 0 100 0 0 0| 0 0 | 60B 362B| 0 0 | 71 67 4 6 90 0 0 0| 0 0 |3170B 135k| 0 0 | 196 95 0 0 100 0 0 0| 0 0 | 180B 362B| 0 0 | 64 57 0 0 100 0 0 0| 0 0 | 120B 362B| 0 0 | 67 58 5 5 88 1 0 1| 0 0 |3170B 135k| 0 0 | 207 100 0 1 99 0 0 0| 0 106k| 180B 362B| 0 0 | 71 67 0 0 100 0 0 0| 0 0 | 120B 362B| 0 0 | 73 70
~]# dstat 2 表示每隔2秒刷新一次;
~]# dstat 2 5 表示每隔2秒刷新,总共刷5次;
常用选项:
CPU: -c,--cpu : 显示CPU相关信息(system, user, idle, wait, hardware interrupt, software interrupt); -C 0,3,total : CPU是多核心的系统环境下,可以指定显示第几颗CPU的信息;每颗CPU的信息单独显示;'0,3'是举例数字; -c -C 0,3,total : 组合使用; 硬盘: -d, --disk : 显示硬盘设备的相关信息(读写); -D total,sda : 指定显示哪块硬盘设备的信息;如果指定多块磁盘,显示的信息也是综合的,并未对磁盘做独立的分析显示; -D sda,total -d -D sda,sdc,total : 组合使用,可分开显示各个磁盘的相关信息; 内存与swap: -g, --page : 显示内存的'page'相关的速率(page in, page out); -m, --mem : 显示内存的相关统计数据(used, buffers, cache, free); -s, --swap : 显示swap统计信息; -S swap1,total : 显示指定的swap统计信息; 网络接口: -n, --net : 显示网络状态信息(receive, send); -N eth1,total : 显示指定网络接口的状态信息; -n -N eth1,lo,ech2,total : 组合使用; 进程: -p, --proc : 显示进程统计信息(runnable, uninterruptible, new); I/O: -r, --io : 显示I/O统计信息(读写请求); 协议/套接字: --tcp : 显示TCP状态信息(listen, established, syn, time_wait, close); --udp : 显示UDP状态信息(listen, active); --raw : 显示raw原始套接字状态信息(raw sockets); --socket : 显示socket状态信息(total, tcp, udp, raw, ip-fragments); 进程间通信: --ipc : 显示icp状态信息(消息队列、信号、共享内存); TOP-XX: --top-cpu : 显示最占用CPU资源的进程; --top-io : 显示最消耗I/O资源的进程; --top-mem : 显示最占用内存资源的进程; --top-latency : 显示延迟最大的进程; 备注:'-d' 与 '-r' 区别,man手册中对于两者的定义有如下描述; -d, --disk enable disk stats (read, write) -r, --io enable I/O request stats (read, write requests)
dstat命令中选项的组合使用举例:
----------------------------------- [root@kouyuushinn ~]# [root@kouyuushinn ~]# dstat -cmr --top-cpu --top-mem --top-io ----total-cpu-usage---- ------memory-usage----- --io/total- -most-expensive- --most-expensive- ----most-expensive---- usr sys idl wai hiq siq| used buff cach free| read writ| cpu process | memory process | i/o process 0 0 100 0 0 0| 301M 484k 494M 179M|0.07 0.33 |glances 0.1|tuned 18.0M|systemd 40k 5346B 1 0 99 0 0 0| 302M 484k 494M 178M| 0 0 | |tuned 18.0M|sshd: root@ 974B 1028B 7 6 87 0 0 0| 302M 484k 494M 178M| 0 0 |glances 11|tuned 18.0M|glances 1071k 199B 2 1 97 0 0 0| 302M 484k 494M 178M| 0 0 | |tuned 18.0M|sshd: root@ 355B 420B 1 0 99 0 0 0| 302M 484k 494M 178M| 0 0 | |tuned 18.0M|sshd: root@ 348B 404B 7 7 86 0 0 0| 302M 484k 494M 178M| 0 0 |glances 11|tuned 18.0M|glances 1067k 199B 2 0 98 0 0 0| 302M 484k 494M 178M| 0 0 | |tuned 18.0M|sshd: root@ 355B 420B 1 1 98 0 0 0| 302M 484k 494M 178M| 0 0 | |tuned 18.0M|sshd: root@ 348B 404B 7 5 88 0 0 0| 302M 484k 494M 178M| 0 0 |glances 10|tuned 18.0M|glances 1067k 199B 2 1 97 0 0 0| 302M 484k 494M 178M| 0 0 | |tuned 18.0M|sshd: root@ 355B 420B 2 1 97 0 0 0| 302M 484k 494M 178M| 0 0 | |tuned 18.0M|sshd: root@ 348B 404B^C [root@kouyuushinn ~]# [root@kouyuushinn ~]# [root@kouyuushinn ~]# dstat -cmr --top-cpu --top-mem --top-io -dgnp 1 8 ----total-cpu-usage---- ------memory-usage----- --io/total- -most-expensive- --most-expensive- ----most-expensive---- -dsk/total- ---paging-- -net/total- ---procs--- usr sys idl wai hiq siq| used buff cach free| read writ| cpu process | memory process | i/o process | read writ| in out | recv send|run blk new 0 0 100 0 0 0| 301M 484k 494M 179M|0.07 0.33 |glances 0.1|tuned 18.0M|systemd 40k 5342B|6894B 8532B| 0 7B| 0 0 |0.0 0 0.2 2 0 98 0 0 0| 302M 484k 494M 179M| 0 0 | |tuned 18.0M|sshd: root@1479B 1540B| 0 0 | 0 0 | 120B 3104B|3.0 0 0 3 1 96 0 0 0| 303M 484k 494M 177M| 0 0 | |tuned 18.0M|pickup 70k 24B| 0 0 | 0 0 | 60B 618B|3.0 0 1.0 7 6 86 0 0 1| 304M 484k 494M 177M| 0 0 |glances 11|tuned 18.0M|glances 1090k 199B| 0 0 | 0 0 |3230B 133k|1.0 0 1.0 2 1 97 0 0 0| 304M 484k 494M 177M| 0 0 |kworker/0:1 1.0|tuned 18.0M|sshd: root@ 508B 564B| 0 0 | 0 0 | 120B 618B|2.0 0 0 2 0 98 0 0 0| 304M 484k 494M 177M| 0 0 | |tuned 18.0M|sshd: root@ 508B 564B| 0 0 | 0 0 | 60B 618B|2.0 0 0 6 6 88 0 0 0| 304M 484k 494M 177M| 0 0 |glances 10|tuned 18.0M|glances 1082k 199B| 0 0 | 0 0 |3170B 136k|1.0 0 1.0 2 1 97 0 0 0| 304M 484k 494M 177M| 0 0 | |tuned 18.0M|sshd: root@ 508B 564B| 0 0 | 0 0 | 60B 618B|2.0 0 0 2 0 98 0 0 0| 304M 484k 494M 177M| 0 0 | |tuned 18.0M|sshd: root@ 501B 564B| 0 0 | 0 0 | 60B 618B| 0 0 0 [root@kouyuushinn ~]#