How to Monitor system statistics using dstat

dstat Tool - To Monitor Processor, Memory, Network Performance on Linux

Dstats is an versatile resource statistic tool. This tool combines the ability of iostat, vmstat, netstat, and ifstat. Dstat allow us to monitor the server resources in real-time. Monitoring system statistics using dstat is explained.

Features

  • Combines all the stats
  • Modular approach
  • Shows stats in the exact time frame
  • Enable or order counters during analysis/troubleshooting

To install dstat in CentOS, use yum install command

[root@linuxhelp ~]# yum install dstat -y
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
* base: centos.webwerks.com
* extras: centos.webwerks.com
* updates: centos.webwerks.com
Resolving Dependencies
-->  Running transaction check
--->  Package dstat.noarch 0:0.7.2-12.el7 will be installed
.
.
.
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!

Now we have successfully installed dstat.

To display the cpu, disk stats, network stats, page stats, system stats etc., run the following command.

[root@linuxhelp ~]# 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
  8   6  80   5   0   1| 564k  238k|   0     0 | 455B 2926B| 394   548
 22   2  75   0   0   1|   0     0 |   0     0 |   0     0 | 290   372
 26   3  71   0   0   0|   0     0 |   0     0 |   0     0 | 322   445
 25   2  73   0   0   0|   0     0 | 120B    0 |   0     0 | 314   392
 16   2  82   0   0   0|   0     0 |  60B    0 |   0     0 | 230   292
 30   3  66   0   0   1|   0     0 | 120B    0 |   0     0 | 658   699
 32   4  64   0   0   0|   0     0 |   0     0 |   0     0 | 739   713
 25   2  73   0   0   0|   0     0 |   0     0 |   0     0 | 658   701
 30   2  68   0   0   0|   0     0 |   0     0 |   0     0 | 586   617
 34   2  64   0   0   0|   0     0 |   0     0 |   0     0 | 723   666
 19   1  80   0   0   0|   0     0 |   0     0 |   0     0 | 401   535
 26   3  71   0   0   0|   0     0 |  60B    0 |   0     0 | 414   493
 21   1  78   0   0   0|   0     0 |  60B    0 |   0     0 | 426   472
 27   2  71   0   0   0|   0     0 | 240B    0 |   0     0 | 394   445
 15   2  83   0   0   0|   0     0 | 120B    0 |   0     0 | 216   286

The following options can be used along with dstat.

    c : cpu stats (total cpu usage)
    d : disk stats (disk/total)
    n : network stats (net/total)
    g : page stats (paging)
    y : system stats (system)

To view the information about cpu, memory, eth0 activity and system resources related to time.

[root@linuxhelp ~]# dstat -tcmsn -N eth0

Module dstat_net failed to load. (No suitable network interfaces found to monitor)
----system---- ----total-cpu-usage---- ------memory-usage----- ----swap---
     time     |usr sys idl wai hiq siq| used  buff  cach  free| used  free
08-07 04:18:14|  9   6  80   5   0   1| 560M    0   317M  110M|7572k 1993M
08-07 04:18:15| 19   1  80   0   0   0| 560M    0   317M  110M|7572k 1993M
08-07 04:18:16| 25   3  72   0   0   0| 560M    0   317M  110M|7572k 1993M
08-07 04:18:17| 34   2  64   0   0   0| 560M    0   317M  110M|7572k 1993M
08-07 04:18:18| 16   2  82   0   0   0| 560M    0   317M  110M|7572k 1993M
08-07 04:18:19| 26   2  72   0   0   0| 560M    0   317M  110M|7572k 1993M
08-07 04:18:20| 26   2  72   0   0   0| 560M    0   317M  110M|7572k 1993M
08-07 04:18:21| 16   1  83   0   0   0| 560M    0   317M  110M|7572k 1993M
08-07 04:18:22| 26   3  71   0   0   0| 560M    0   317M  110M|7572k 1993M
08-07 04:18:23| 25   1  73   0   0   1| 560M    0   317M  110M|7572k 1993M
08-07 04:18:24| 18   2  80   0   0   0| 560M    0   317M  110M|7572k 1993M
08-07 04:18:25| 23   2  75   0   0   0| 560M    0   317M  110M|7572k 1993M
08-07 04:18:26| 17   1  82   0   0   0| 560M    0   317M  110M|7572k 1993M

To view the information about cpu, disk (sda1) utilization and system load, run the following command.

[root@linuxhelp ~]# dstat -cdl -D sda1

----total-cpu-usage---- --dsk/sda1- ---load-avg---
usr sys idl wai hiq siq| read  writ| 1m   5m  15m
  9   5  80   5   0   1|  11k  741B|0.54 0.41 0.61
 18   2  80   0   0   0|   0     0 |0.54 0.41 0.61
 24   3  73   0   0   0|   0     0 |0.50 0.40 0.61
 24   2  74   0   0   0|   0     0 |0.50 0.40 0.61
 15   2  83   0   0   0|   0     0 |0.50 0.40 0.61
 24   2  73   0   0   1|   0     0 |0.50 0.40 0.61
 25   2  73   0   0   0|   0     0 |0.50 0.40 0.61
 16   2  82   0   0   0|   0     0 |0.54 0.41 0.61
 23   3  74   0   0   0|   0     0 |0.54 0.41 0.61
 24   1  75   0   0   0|   0     0 |0.54 0.41 0.61
 15   2  83   0   0   0|   0     0 |0.54 0.41 0.61
 23   2  75   0   0   0|   0     0 |0.54 0.41 0.61
 41   3  56   0   0   0|   0     0 |0.49 0.41 0.61

To display the information about top cpu, top latency and top memory

[root@linuxhelp ~]# dstat --top-cpu-adv --top-latency --top-mem

Module dstat_top_latency failed to load. (Kernel has no scheduler statistics, use at least 2.6.12)
-------most-expensive-cpu-process------- --most-expensive-
process              pid  cpu read write|  memory process
gnome-shell           5435 4.2%3689B1847k|gnome-shell  239M
gnome-shell           5435  14%  16B7681k|gnome-shell  239M
gnome-shell           5435  16%  16B7681k|gnome-shell  239M
gnome-shell           5435  22%  24B  11M|gnome-shell  239M
gnome-shell           5435  15%  16B7681k|gnome-shell  239M
gnome-shell           5435  14%  16B7681k|gnome-shell  239M
gnome-shell           5435  23%  24B  11M|gnome-shell  239M
gnome-shell           5435  14%  16B7681k|gnome-shell  239M
gnome-shell           5435  14%  16B7681k|gnome-shell  239M
gnome-shell           5435  25%  24B  11M|gnome-shell  239M
gnome-shell           5435  14%  16B7681k|gnome-shell  239M
gnome-shell           5435  17%  16B7681k|gnome-shell  239M

To extend the delay, mention the delay time at the end of dstat command. Here, we are displaying the output for a delay of every 10 seconds.

[root@linuxhelp ~]# dstat -tn -N eth0 --tcp 10

Module dstat_net failed to load. (No suitable network interfaces found to monitor)
----system---- ----tcp-sockets----
     time     |lis act syn tim clo
08-07 04:21:43| 13   0   0   0   0
08-07 04:21:53| 13   0   0   0   0
08-07 04:22:03| 13   0   0   0   0

To show the count delay for limiting the number of stats updates to 20 with delay for every 4 second.

[root@linuxhelp ~]# dstat -tn 4 20

----system---- -net/total-
     time     | recv  send
08-07 04:23:45|   0     0
08-07 04:23:49|  60B    0
08-07 04:23:53|  97B    0
08-07 04:23:57|  60B    0
08-07 04:24:01|  45B    0
08-07 04:24:05|  23B   23B

FAQ
Q
How to install dstat in CentOS?
A
use yum install command
# yum install dstat
Now we have successfully installed dstat.
Q
How can we cdisplay the cpu, disk stats, network stats, page stats, system stats?
A
*run the following command to display the CPU, disk stats, network stats, page stats
# dstat
Q
How to view the information about CPU, disk (sda1) utilization and system load?
A
Use the following command to view the information about CPU, disk (sda1) utilization and system load
# dstat -cdl -D sda1
Q
Can display the information about top CPU, top latency and top memory?
A
*Yes it is possible
*Run the following command
# dstat --top-cpu-adv --top-latency --top-mem
Q
How can we extend the delay on dstat?
A
Here, we are displaying the output for a delay of every 10 seconds.
# dstat -tn -N eth0 --tcp 10