Linux系统之dstat命令的基本使用

在这里插入图片描述

一、dstat命令介绍

1. dstat简介

dstat是一个通用的系统资源统计工具,stat命令是一个用来替换vmstat、iostat、netstat、nfsstat和ifstat这些命令,是一个全能系统信息统计工具。

2. dstat特点

  • 实时的监控cpu、磁盘、网络、IO、内存等使用情况
  • 全能系统信息统计
  • 安装方便快速,上手简单
  • 功能强大,是运维的好帮手

二、本次实践介绍

1. 本地环境规划

本地环境规划:

hostnameIP地址dstat版本操作系统版本
jeven192.168.3.1663.28.2-10centos 7.6

2. 本次实践介绍

1.本次实践环境为个人测试环境;
2.本次实践为在centos7.6系统上安装dstat工具;
3.学会dstat工具的基本使用。

三、本地环境检查

1. 检查操作系统版本

检查本地操作系统版本

[root@jeven test]#  cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core) 

2. 查看系统内核版本

查看系统内核版本

[root@jeven test]# uname -r 
3.10.0-957.el7.x86_64

3. 检查本地yum仓库源状态

检查本地yum仓库的状态

[root@server001 ~]# yum repolist all |grep enable 
!base/7/x86_64                               CentOS-7 - Base - m enabled: 10,072
!docker-ce-stable/7/x86_64                   Docker CE Stable -  enabled:    234
!epel/x86_64                                 Extra Packages for  enabled: 13,785
!extras/7/x86_64                             CentOS-7 - Extras - enabled:    515
!mysql-connectors-community/x86_64           MySQL Connectors Co enabled:    220
!mysql-tools-community/x86_64                MySQL Tools Communi enabled:     98
!mysql80-community/x86_64                    MySQL 8.0 Community enabled:    405
!remi-safe                                   Safe Remi's RPM rep enabled:  5,159
!updates/7/x86_64                            CentOS-7 - Updates  enabled:  4,926
!webmin                                      Webmin Distribution enabled:    243
!zabbix/x86_64                               Zabbix Official Rep enabled:    114
!zabbix-agent2-plugins/x86_64                Zabbix Official Rep enabled:      4
!zabbix-non-supported/x86_64                 Zabbix Official Rep enabled:      5

四、安装dstat工具

1. 搜索dstat软件

使用yum查找dstat软件

[root@server001 ~]# yum search dstat
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * remi-safe: mirrors.tuna.tsinghua.edu.cn
=================================================================================== N/S matched: dstat ===================================================================================
dstat.noarch : Versatile resource statistics tool

  Name and summary matches only, use "search all" for everything.

查看dstat的软件版本

[root@server001 ~]# yum list all|grep dstat
dstat.noarch                             0.7.2-12.el7                  base  

2. 安装dstat工具

使用yum直接安装dstat工具

[root@jeven ~]# yum -y install dstat
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * epel: mirrors.cqu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package dstat.noarch 0:0.7.2-12.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================================================================================
 Package                                    Arch                                        Version                                           Repository                                 Size
==========================================================================================================================================================================================
Installing:
 dstat                                      noarch                                      0.7.2-12.el7                                      base                                      163 k

Transaction Summary
==========================================================================================================================================================================================
Install  1 Package

Total download size: 163 k
Installed size: 752 k
Downloading packages:
dstat-0.7.2-12.el7.noarch.rpm                                                                                                                                      | 163 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : dstat-0.7.2-12.el7.noarch                                                                                                                                              1/1 
  Verifying  : dstat-0.7.2-12.el7.noarch                                                                                                                                              1/1 

Installed:
  dstat.noarch 0:0.7.2-12.el7                                                                                                                                                             

Complete!

3. 查看dstat版本

查看dstat版本

[root@jeven ~]# dstat --version
Dstat 0.7.2
Written by Dag Wieers <dag@wieers.com>
Homepage at http://dag.wieers.com/home-made/dstat/

Platform posix/linux2
Kernel 3.10.0-957.el7.x86_64
Python 2.7.5 (default, Oct 30 2018, 23:45:53) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

Terminal type: xterm (color support)
Terminal size: 39 lines, 186 columns

Processors: 4
Pagesize: 4096
Clock ticks per secs: 100

internal:
	aio, cpu, cpu24, disk, disk24, disk24old, epoch, fs, int, int24, io, ipc, load, lock, mem, net, page, page24, proc, raw, socket, swap, swapold, sys, tcp, time, udp, unix, vm
/usr/share/dstat:
	battery, battery-remain, cpufreq, dbus, disk-tps, disk-util, dstat, dstat-cpu, dstat-ctxt, dstat-mem, fan, freespace, gpfs, gpfs-ops, helloworld, innodb-buffer, innodb-io, 
	innodb-ops, lustre, memcache-hits, mysql-io, mysql-keys, mysql5-cmds, mysql5-conn, mysql5-io, mysql5-keys, net-packets, nfs3, nfs3-ops, nfsd3, nfsd3-ops, ntp, postfix, power, 
	proc-count, qmail, rpc, rpcd, sendmail, snooze, squid, test, thermal, top-bio, top-bio-adv, top-childwait, top-cpu, top-cpu-adv, top-cputime, top-cputime-avg, top-int, top-io, 
	top-io-adv, top-latency, top-latency-avg, top-mem, top-oom, utmp, vm-memctl, vmk-hba, vmk-int, vmk-nic, vz-cpu, vz-io, vz-ubc, wifi

五、dstat命令的帮助信息

1. 在命令行的帮助信息

在centos命令行终端的dstat的帮助信息

[root@jeven ~]# dstat --help
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

delay is the delay in seconds between each update (default: 1)
count is the number of updates to display before exiting (default: unlimited)

2. dstat命令常用选项

dstat命令常用选项

-c:显示CPU系统占用,用户占用,空闲,等待,中断,软件中断等信息。
-C:当有多个CPU时候,此参数可按需分别显示cpu状态,例:-C 0,1 是显示cpu0和cpu1的信息。
-d:显示磁盘读写数据大小。
-D hda,total:include hda and total。
-n:显示网络状态。
-N eth1,total:有多块网卡时,指定要显示的网卡。
-l:显示系统负载情况。
-m:显示内存使用情况。
-g:显示页面使用情况。
-p:显示进程状态。
-s:显示交换分区使用情况。
-S:类似D/N。
-r:I/O请求情况。
-y:系统状态。
--ipc:显示ipc消息队列,信号等信息。
--socket:用来显示tcp udp端口状态。
-a:此为默认选项,等同于-cdngy。
-v:等同于 -pmgdsc -D total。
--output 文件:此选项也比较有用,可以把状态信息以csv的格式重定向到指定的文件中,以便日后查看。例:dstat --output /root/dstat.csv & 此时让程序默默的在后台运行并把结果输出到/root/dstat.csv文件中。

六、dstat命令的基本使用

1. 直接使用dstat命令

直接使用dstat命令,默认使用的是-cdngy参数,分别显示cpu、disk、net、page、system信息,默认是1s显示一条信息。
在命令后面加上–output ,可以把状态信息以csv的格式重定向到指定的文件中,以便日后查看。

[root@jeven ~]# 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  99   0   0   0| 221k   35k|   0     0 |   0     0 | 141   195 
  0   0 100   0   0   0|   0     0 | 328B  938B|   0     0 |  76   111 
  0   0 100   0   0   0|   0     0 | 254B  398B|   0     0 |  57    78 
  0   0 100   0   0   0|   0     0 | 314B  458B|   0     0 |  46    60 
  0   0 100   0   0   0|   0     0 | 254B  458B|   0     0 |  58    73 
  0   0 100   0   0   0|   0     0 | 254B  398B|   0     0 |  49    67 

在这里插入图片描述

- CPU部分解释
usr:用户空间的程序所占百分比;
sys:系统空间程序所占百分比;
idel:空闲百分比;
wai:等待磁盘I/O所消耗的百分比;
hiq:硬中断次数;
siq:软中断次数;


- disk部分解释
read:磁盘读带宽; 
writ:磁盘写带宽

- system部分解释
int、csw分别为系统的中断次数(interrupt)和上下文切换(context switch)。


- net部分解释
recv:网络收包带宽
send:网络发包带宽


- paging内存分页统计
in: page in(换入)
out:page out(换出)

2. 指定时间间隔显示

可以在最后指定显示一条信息的时间间隔,如dstat3是每3s显示一条,dstat 3 6表示每3s显示一条,一共显示6条。

[root@jeven ~]# dstat 3
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  99   0   0   0| 212k   33k|   0     0 |   0     0 | 137   190 
  0   0 100   0   0   0|   0     0 | 254B  573B|   0     0 |  55    71 
  0   0 100   0   0   0|   0     0 | 334B  387B|   0     0 |  59    82 
  0   0 100   0   0   0|   0     0 | 254B  387B|   0     0 |  70    78 
  0   0 100   0   0   0|   0     0 | 234B  407B|   0     0 |  53    74 
  0   0 100   0   0   0|   0     0 | 254B  387B|   0     0 |  51    68 
  0   0 100   0   0   0|   0     0 | 454B  407B|   0     0 |  55    74 
  0   0 100   0   0   0|   0     0 | 254B  407B|   0     0 |  56    78 

[root@jeven ~]# dstat 3 6
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  99   0   0   0| 210k   33k|   0     0 |   0     0 | 137   190 
  0   0 100   0   0   0|   0     0 | 254B  573B|   0     0 |  57    77 
  0   0 100   0   0   0|   0     0 | 428B  387B|   0     0 |  77   110 
  0   0 100   0   0   0|   0     0 | 294B  407B|   0     0 |  76   102 
  0   0 100   0   0   0|   0     0 | 254B  407B|   0     0 |  84    90 
  0   0 100   0   0   0|   0     0 | 228B  387B|   0     0 |  55    79 
  0   0 100   0   0   0|   0     0 | 214B  407B|   0     0 |  51    73 

3. 查看dstat能使用的所有参数

查看dstat能使用的所有参数使用dstat --list

[root@jeven ~]# dstat --list
internal:
	aio, cpu, cpu24, disk, disk24, disk24old, epoch, fs, int, int24, io, ipc, load, lock, mem, net, page, page24, proc, raw, socket, swap, swapold, sys, tcp, time, udp, unix, vm
/usr/share/dstat:
	battery, battery-remain, cpufreq, dbus, disk-tps, disk-util, dstat, dstat-cpu, dstat-ctxt, dstat-mem, fan, freespace, gpfs, gpfs-ops, helloworld, innodb-buffer, innodb-io, 
	innodb-ops, lustre, memcache-hits, mysql-io, mysql-keys, mysql5-cmds, mysql5-conn, mysql5-io, mysql5-keys, net-packets, nfs3, nfs3-ops, nfsd3, nfsd3-ops, ntp, postfix, power, 
	proc-count, qmail, rpc, rpcd, sendmail, snooze, squid, test, thermal, top-bio, top-bio-adv, top-childwait, top-cpu, top-cpu-adv, top-cputime, top-cputime-avg, top-int, top-io, 
	top-io-adv, top-latency, top-latency-avg, top-mem, top-oom, utmp, vm-memctl, vmk-hba, vmk-int, vmk-nic, vz-cpu, vz-io, vz-ubc, wifi

4. 监控系统的进程

检查查看系统的进程

[root@jeven ~]# dstat -p 5 10
---procs---
run blk new
  0   0 3.8
  0   0   0
  0   0   0
  0   0   0
  0   0   0
  0   0   0
  0   0   0
0.4   0   0
  0   0 1.6
  0   0   0
  0   0   0

七、dstat命令的日常用法

1. 显示最耗CPU的进程

查看当前最耗CPU的进程名、PID和CPU占比以及读写信息。

[root@jeven ~]# dstat -t --top-cpu-adv 2 6
----system---- -------most-expensive-cpu-process-------
     time     |process              pid  cpu read write
14-05 05:16:31|vmtoolsd             9177 0.0%2094B   1B
14-05 05:16:33|python2              9868 0.1%   0    0 
14-05 05:16:35|kworker/1:1          224830.1%   0    0 
14-05 05:16:37|                                        
14-05 05:16:39|                                        
14-05 05:16:41|kworker/0:1          40   0.1%   0    0 
14-05 05:16:43|rngd                 9141 0.1%   0    0 

2. 显示最高磁盘IO的进程

查看当前最耗block I/O的进程名、PID和读写容量以及CPU占比。

[root@jeven ~]# dstat -t  --top-bio-adv 2 6
----system---- ----most-expensive-block-i/o-process----
     time     |process              pid  read write cpu
14-05 05:18:38|systemd              1      68k  20k0.0%
14-05 05:18:40|                                        
14-05 05:18:42|                                        
14-05 05:18:44|                                        
14-05 05:18:46|                                        
14-05 05:18:48|                                        
14-05 05:18:50|                                        

3. 显示最耗内存的进程

查看当前最耗内存的进程

[root@jeven ~]#  dstat -t --top-mem 2 6
----system---- --most-expensive-
     time     |  memory process 
14-05 05:52:02|gnome-shell  133M
14-05 05:52:05|gnome-shell  133M
14-05 05:52:07|gnome-shell  133M
14-05 05:52:09|gnome-shell  133M
14-05 05:52:10|gnome-shell  133M
14-05 05:52:13|gnome-shell  133M
14-05 05:52:15|gnome-shell  133M

4. 监控磁盘读写

监控磁盘sda的读写状态

[root@jeven ~]# dstat -t  -dD sda,total  2 6
----system---- --dsk/sda----dsk/total-
     time     | read  writ: read  writ
14-05 05:23:05| 164k   26k: 164k   26k
14-05 05:23:07|   0     0 :   0     0 
14-05 05:23:09|   0     0 :   0     0 
14-05 05:23:11|   0     0 :   0     0 
14-05 05:23:13|   0    15k:   0    15k
14-05 05:23:15|   0     0 :   0     0 
14-05 05:23:17|   0     0 :   0     0 

5. 监控网卡的流量

监控系统的某个网卡,例如ens33网卡的流量情况。

[root@jeven ~]# dstat -t  -n -N ens33,total 2 6
----system---- -net/ens33---net/total-
     time     | recv  send: recv  send
14-05 05:24:59|   0     0 :   0     0 
14-05 05:25:01| 224B  378B: 224B  378B
14-05 05:25:03| 284B  312B: 284B  312B
14-05 05:25:05| 224B  282B: 224B  282B
14-05 05:25:07| 224B  312B: 224B  312B
14-05 05:25:09| 194B  282B: 194B  282B
14-05 05:25:11| 224B  312B: 224B  312B
[root@jeven ~]# 

6. 监控内存状态

监控系统内存的状态,显示内存的各项信息。

[root@jeven ~]# dstat -t  -m  2 6
----system---- ------memory-usage-----
     time     | used  buff  cach  free
14-05 05:26:43|1209M 6168k  822M 9798M
14-05 05:26:45|1209M 6168k  822M 9798M
14-05 05:26:47|1209M 6168k  822M 9798M
14-05 05:26:49|1209M 6168k  822M 9798M
14-05 05:26:51|1209M 6168k  822M 9798M
14-05 05:26:53|1209M 6168k  822M 9798M
14-05 05:26:55|1209M 6168k  822M 9798M

  • 6
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江湖有缘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值