一天一个 Linux 命令(39):dstat 命令

一、简介

Linux下的dstat是一个全能系统信息统计工具的命令,用来替换vmstat、iostat、netstat、nfsstat和ifstat这些命令。dstat克服了这些命令的局限并增加了一些另外的功能,增加了监控项,也变得更灵活了。dstat可以很方便监控系统运行状况并用于基准测试和排除故障。

dstat将以列表的形式提供选项信息并清晰地告诉你是在何种幅度和单位显示输出。这样更好地避免了信息混乱和误报。更重要的是,它可以更容易编写插件来收集你想要的数据信息,以从未有过的方式进行扩展。

dstat支持即时刷新,譬如输入dstat 3即每三秒收集一次,但最新的数据都会每秒刷新显示。和sysstat相同的是,dstat也可以收集指定的性能资源,譬如dstat -c即显示CPU的使用情况。

如果系统没有安装,可以通过sudo yum install dstat来安装。

二、格式说明

dstat [-afv] [options..] [delay [count]]
dstat [参数]

Usage: dstat [-afv] [options..] [delay [count]]
Versatile tool for generating system resource statistics

Dstat options:
  -c, --cpu              enable cpu stats
     -C 0,3,total           include cpu0, cpu3 and total
  -d, --disk             enable disk stats
     -D total,hda           include hda and total
  -g, --page             enable page stats
  -i, --int              enable interrupt stats
     -I 5,eth2              include int5 and interrupt used by eth2
  -l, --load             enable load stats
  -m, --mem              enable memory stats
  -n, --net              enable network stats
     -N eth1,total          include eth1 and total
  -p, --proc             enable process stats
  -r, --io               enable io stats (I/O requests completed)
  -s, --swap             enable swap stats
     -S swap1,total         include swap1 and total
  -t, --time             enable time/date output
  -T, --epoch            enable time counter (seconds since epoch)
  -y, --sys              enable system stats

  --aio                  enable aio stats
  --fs, --filesystem     enable fs stats
  --ipc                  enable ipc stats
  --lock                 enable lock stats
  --raw                  enable raw stats
  --socket               enable socket stats
  --tcp                  enable tcp stats
  --udp                  enable udp stats
  --unix                 enable unix stats
  --vm                   enable vm stats

  --plugin-name          enable plugins by plugin name (see manual)
  --list                 list all available plugins

  -a, --all              equals -cdngy (default)
  -f, --full             automatically expand -C, -D, -I, -N and -S lists
  -v, --vmstat           equals -pmgdsc -D total

  --bits                 force bits for values expressed in bytes
  --float                force float values on screen
  --integer              force integer values on screen

  --bw, --blackonwhite   change colors for white background terminal
  --nocolor              disable colors (implies --noupdate)
  --noheaders            disable repetitive headers
  --noupdate             disable intermediate updates
  --output file          write CSV output to file
  --profile              show profiling statistics when exiting dstat

三、选项说明

-a  此为默认选项,等同于-cdngy。
-c	显示CPU系统占用,用户占用,空闲,等待,中断,软件中断等信息
-d	显示磁盘读写数据大小
-n	显示网络状态
-l	显示系统负载情况
-m	显示内存使用情况,包括used,buffer,cache,free值
-g	显示页面使用情况
-p	显示进程状态
-s	显示交换分区使用情况
-t  将当前时间显示在第一行
-r	I/O请求情况
-y	系统状态
–fs 显示文件系统统计数据(包括文件总数量和inodes值)
--ipc 显示ipc消息队列,信号等信息
--socket 显示网络统计数据,用来显示tcp udp端口状态
–tcp 显示常用的TCP统计
–udp 显示监听的UDP接口及其当前用量的一些动态数据

--disk-util 显示某一时间磁盘的忙碌状况

--freespace 显示当前磁盘空间使用率

--proc-count 显示正在运行的程序数量

--top-bio 指出块I/O最大的进程

--top-cpu 图形化显示CPU占用最大的进程

--top-io 显示正常I/O最大的进程

--top-mem 显示占用最多内存的进程

四、命令功能

一个全能系统信息统计工具

五、常见用法

5.1 显示cpu、disk、net、page、system信息

# dstat

----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  99   0   0   0| 244B   38k|   0     0 |   0     0 | 758  1156 
  0   0 100   0   0   0|   0     0 | 150B  228B|   0     0 | 787  1285 
  0   0 100   0   0   0|   0     0 |  96B  372B|   0     0 | 690  1143 
  0   0 100   0   0   0|   0     0 |  54B  212B|   0     0 | 673  1104 
  0   0 100   0   0   0|   0     0 | 138B  270B|   0     0 | 757  1235 
  0   1  99   0   0   0|   0    40k| 702B 1151B|   0     0 | 942  1421 
  0   0  99   0   0   0|   0     0 |2170B 3495B|   0     0 | 908  1417 

CPU状态:CPU的使用率。这项报告更有趣的部分是显示了用户,系统和空闲部分,这更好地分析了CPU当前的使用状况。如果你看到"wait"一栏中,CPU的状态是一个高使用率值,那说明系统存在一些其它问题。当CPU的状态处在"waits"时,那是因为它正在等待I/O设备(例如内存,磁盘或者网络)的响应而且还没有收到。

磁盘统计(dsk):磁盘的读写操作,这一栏显示磁盘的读、写总数。

网络统计(net):网络设备发送和接受的数据,这一栏显示的网络收、发数据总数。

分页统计(paging):系统的分页活动。分页指的是一种内存管理技术用于查找系统场景,一个较大的分页表明系统正在使用大量的交换空间,或者说内存非常分散,大多数情况下你都希望看到page in(换入)和page out(换出)的值是0 0。

系统统计(system):这一项显示的是中断(int)和上下文切换(csw)。这项统计仅在有比较基线时才有意义。这一栏中较高的统计值通常表示大量的进程造成拥塞,需要对CPU进行关注。你的服务器一般情况下都会运行运行一些程序,所以这项总是显示一些数值。

默认情况下,dstat每秒都会刷新数据。如果想退出dstat,你可以按"CTRL+C"键。

需要注意的是报告的第一行,通常这里所有的统计都不显示数值的。

5.2 每3秒收集一次 cpu、disk、net、page、system 信息

# dstat 3

5.3 显示CPU系统占用,用户占用,空闲,等待,中断,软件中断等信息

# dstat -c

5.4 显示磁盘读写数据大小

# dstat -d

5.5 显示网络状态

# dstat -n

5.6 查看全部内存都有谁在占用

# dstat -g -l -m -s --top-mem

5.7 显示CPU资源损耗的数据

# dstat -c -y -l --proc-count --top-cpu

5.8 输出一个csv文件

dstat –output /tmp/dstat.csv -tpcdrmgln

5.9 找出占用资源最高的进程和用户

dstat --top-mem --top-io --top-cpu

joshua317博客
请先登录后发表评论
  • latest comments
  • 总共0条评论