• Get In Touch
October 24, 2016

How to Install and Use Dstat on Ubuntu-16.04

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Dstat is a replacement for the vmstat, iostat, netstat and ifstat utility that overcomes some limitations by adding extra features. Dstat is one of the most powerful and flexible utilities for generating and monitoring Linux resource statistics. You can easily view your system resources instantly using dstat. You can also export dstat’s data to aCSV file to be imported and used by OpenOffice.

In this tutorial, we will learn how to install and use dstat on Ubuntu-16.04.

Requirements

  • A server runing Ubuntu-16.04.

Installing Dstat

Dstat comes in the Ubuntu-16.04 repository by default, you can easily install it by running the following command:

sudo apt-get install dstat

Output:

    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following NEW packages will be installed:
      dstat
    0 upgraded, 1 newly installed, 0 to remove and 782 not upgraded.
    Need to get 68.2 kB of archives.
    After this operation, 351 kB of additional disk space will be used.
    Get:1 http://in.archive.ubuntu.com/ubuntu/ trusty/universe dstat all 0.7.2-3build1 [68.2 kB]
    Fetched 68.2 kB in 3s (18.4 kB/s)
    Selecting previously unselected package dstat.
    (Reading database ... 271096 files and directories currently installed.)
    Preparing to unpack .../dstat_0.7.2-3build1_all.deb ...
    Unpacking dstat (0.7.2-3build1) ...
    Processing triggers for man-db (2.6.7.1-1) ...
    Setting up dstat (0.7.2-3build1) ...

Getting Started with Dstat

Once dstat is installed, it’s time to monitor your systems performance stats.
Let’s start with the following command:

dstat

Output:

    ----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
    usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw 
      8   9  83   0   0   0|   0   104k| 156B  262B|   0     0 |1915  4165 
      5   7  88   1   0   0|   0     0 |  28B   42B|   0     0 |1356  3835 
      5   8  87   0   0   0|   0     0 | 234B  368B|   0     0 |1436  4279 
     16   8  75   1   0   0|   0   724k| 156B  226B|   0     0 |1886  5693 
      8   7  85   0   0   0|   0     0 |   0     0 |   0     0 |1689  4546 
      9   8  81   2   0   0|   0    56k| 437B 2547B|   0     0 |2199  4906 
      9   9  83   0   0   0|   0    68k| 336B 1556B|   0     0 |2257  4376 
     18   8  72   2   0   0|   0    28k|1405B 1701B|   0     0 |2363  7171 
     13   9  78   0   0   0|   0     0 | 196B  152B|   0     0 |1815  5568 
      6  10  83   1   0   0|  25k    0 |   0     0 |   0     0 |1630  3962 
     10   8  80   2   0   0|   0    32k|  86B   98B|   0     0 |2227  5095 
      9   8  80   2   0   0|   0    20k|1540B 9899B|   0     0 |2283  5019 
      6   8  87   0   0   0|   0     0 |  72B   78B|   0     0 |2119  4382 
     13   6  80   1   0   0|   0     0 |   0     0 |   0     0 |1495  3731 
     11   7  81   1   0   0|4096B  220k|   0     0 |   0     0 |1682  4300 
     13   7  79   1   0   0|   0     0 |   0     0 |   0     0 |1691  4730 
      8  10  82   0   0   0|   0     0 |   0     0 |   0     0 |2299  6325 
      8   8  83   1   0   0|   0     0 |   0     0 |   0     0 |2272  5065 
      6   8  86   0   0   0|   0   724k|   0     0 |   0     0 |3131  3920 
      7   8  84   1   0   0|   0     0 |   0     0 |   0     0 |2104  4630 
     12   6  81   1   0   0|   0    52k|   0     0 |   0     0 |2102  4232 
     11   8  80   1   0   0|   0    40k|   0     0 |   0     0 |2249  4587 
      9   9  83   0   0   0|   0     0 |   0     0 |   0     0 |2362  6276 

When you run dstat command without any arguements, it will use the -cdngy options.

The -cdngy options are as follows:

c : cpu stats
d : disk stats
n : network stats
g : page stats
y : system stats

You can also use other options to customise the dstat output.

If you want to display the information about your cpu, disk (sda2) utilisation and system load, run the following command:

dstat -cdl -D sda2

Output:

    ----total-cpu-usage---- --dsk/sda2- ---load-avg---
    usr sys idl wai hiq siq| read  writ| 1m   5m  15m 
      9  10  78   2   0   0|  84B    0 |1.29 0.93 0.80
      6   8  86   0   0   0|   0     0 |1.29 0.93 0.80
     13   7  80   1   0   0|   0     0 |1.29 0.93 0.80
     10   7  82   0   0   0|   0     0 |1.29 0.93 0.80
     10   8  82   0   0   0|   0     0 |1.29 0.93 0.80
     12  10  78   1   0   0|   0     0 |1.35 0.95 0.81
      7   8  84   1   0   0|   0     0 |1.35 0.95 0.81
      5   7  87   1   0   0|   0     0 |1.35 0.95 0.81
      6   7  87   0   0   0|   0     0 |1.35 0.95 0.81
      5   7  87   1   0   0|   0     0 |1.35 0.95 0.81
      6   7  86   0   1   0|   0     0 |1.24 0.93 0.80
      5   8  86   1   1   0|   0     0 |1.24 0.93 0.80
      6   7  86   0   1   0|   0     0 |1.24 0.93 0.80
      5   7  87   1   0   0|   0     0 |1.24 0.93 0.80
     13   9  78   0   0   0|   0     0 |1.24 0.93 0.80
      5  10  84   1   0   0|   0     0 |1.22 0.94 0.80
      6   8  85   1   0   0|   0     0 |1.22 0.94 0.80
     13   9  77   1   0   0|   0     0 |1.22 0.94 0.80
      7   9  84   0   0   0|   0     0 |1.22 0.94 0.80
      5   8  86   1   0   0|   0     0 |1.22 0.94 0.80
      7   8  86   0   0   0|   0     0 |1.12 0.92 0.80
      6   8  85   1   0   0|   0     0 |1.12 0.92 0.80
      7   8  84   1   0   0|   0     0 |1.12 0.92 0.80
      5   7  86   1   0   0|   0     0 |1.12 0.92 0.80

If you want to display the information about top cpu, top latency and top memory, run the following command:

dstat --top-cpu-adv --top-latency --top-mem

Output:

    -------most-expensive-cpu-process------- --highest-total-- --most-expensive-
    process              pid  cpu read write| latency process |  memory process 
    VirtualBox            3666 6.1%1730B 540B|firefox        13|VirtualBox  1758M
    VirtualBox            3666 4.5%  78B 194B|indicator3-ap  11|VirtualBox  1758M
    X                     1408 3.2%4824B  22k|indicator3-ap  13|VirtualBox  1758M
    VirtualBox            3666 7.2%  21B  21B|firefox        19|VirtualBox  1758M
    VirtualBox            3666 3.8%  21B 253B|indicator3-ap  10|VirtualBox  1758M
    VirtualBox            3666 3.2%  21B  65B|indicator3-ap  16|VirtualBox  1758M
    VirtualBox            3666 4.0%  78B 194B|indicator3-ap  16|VirtualBox  1758M
    collectl              1596 8.5% 298k  52k|indicator3-ap  16|VirtualBox  1758M
    VirtualBox            3666 3.0%  21B  21B|firefox      8357|VirtualBox  1758M
    VirtualBox            3666 3.8%  53B 253B|indicator3-ap  10|VirtualBox  1758M
    VirtualBox            3666 3.2%  24B  24B|indicator3-ap8701|VirtualBox  1758M
    VirtualBox            3666 4.0%  78B 238B|indicator3-ap  15|VirtualBox  1758M
    X                     1408 3.5%9168B  26k|indicator3-ap8591|VirtualBox  1758M
    X                     1408 3.5%8648B  24k|indicator3-ap  11|VirtualBox  1758M
    X                     1408 3.8%  11k  29k|firefox      9189|VirtualBox  1758M
    VirtualBox            3666 3.2%  21B  21B|indicator3-ap  11|VirtualBox  1758M
    VirtualBox            3666 4.5%  78B 882B|indicator3-ap  11|VirtualBox  1758M
    X                     1408 3.8%6752B  25k|indicator3-ap7982|VirtualBox  1758M
    VirtualBox            3666 6.0%  20B 368B|indicator3-ap7474|VirtualBox  1758M^C

Dstat provides some advanced commands that can be used in production environment. For example, if you want to monitor a single application that is using the most CPU and consuming the most amount of memory, run the following command:

dstat -c --top-cpu -dn --top-mem

Output:

    ----total-cpu-usage---- -most-expensive- -dsk/total- -net/total- --most-expensive-
    usr sys idl wai hiq siq|  cpu process   | read  writ| recv  send|  memory process 
      9  10  79   2   0   0|VirtualBox   5.8| 566k  281k|   0     0 |VirtualBox  1759M
      6   8  86   0   0   0|VirtualBox   3.5|   0     0 |   0     0 |VirtualBox  1759M
      6   9  84   1   0   0|VirtualBox   5.5|   0     0 |   0     0 |VirtualBox  1759M
     12   7  80   0   0   0|collectl     8.2|   0     0 |   0     0 |VirtualBox  1759M
     12  10  77   0   0   0|compiz       4.2|   0    52k|  86B   98B|VirtualBox  1758M
     10   9  81   0   0   0|X            3.8|   0     0 |   0     0 |VirtualBox  1758M
      7   8  84   1   0   0|VirtualBox   3.0|   0     0 |   0     0 |VirtualBox  1758M
      6   8  85   2   0   0|VirtualBox   4.5|   0    32k|   0     0 |VirtualBox  1758M
      6   7  86   1   0   0|VirtualBox   3.0|   0     0 |   0     0 |VirtualBox  1758M
      5   8  87   0   0   0|VirtualBox   4.0|   0     0 |   0     0 |VirtualBox  1758M
      6   7  86   1   0   0|VirtualBox   3.2|   0     0 |   0     0 |VirtualBox  1758M
      5   7  88   0   0   0|VirtualBox   3.5|   0    36k|   0   110B|VirtualBox  1759M
      6   8  85   1   0   0|VirtualBox   4.2|   0    16k|  90B   74B|VirtualBox  1759M
      5   7  87   0   0   0|VirtualBox   3.5|   0     0 |   0    74B|VirtualBox  1759M
      7  11  81   1   0   0|VirtualBox   7.0|   0     0 |   0     0 |VirtualBox  1759M
      7   9  85   0   0   0|X            3.8|   0     0 |   0    74B|VirtualBox  1759M
      6   8  85   1   0   0|VirtualBox   3.8|   0     0 |  42B   80B|VirtualBox  1759M
      6   8  86   0   0   0|VirtualBox   4.8|   0   144k|   0     0 |VirtualBox  1759M
      6   7  86   1   0   0|VirtualBox   3.2|   0     0 |   0     0 |VirtualBox  1759M
      6   7  87   0   0   0|VirtualBox   3.8|1024B  124k| 586B   74B|VirtualBox  1759M
      6   8  85   1   0   0|VirtualBox   4.0|   0     0 |   0     0 |VirtualBox  1759M
      5   8  85   1   0   0|VirtualBox   3.5|   0    32k|   0     0 |VirtualBox  1758M^C

Where, -c used to display cpu usage, --top-cpu used to display most cpu consuming process, -dn used to display disk and network stats and --top-mem
used to display top memory consuming process.

You can also store the output of dstat command in a .csv file using --output option:

For example, if you want to display the time, cpu, mem, system load stats with a two second delay between 10 updates and store the output in report.csv file, run the following command:

dstat --time --cpu --mem --load --output report.csv 2 10

Output:

    ----system---- ----total-cpu-usage---- ------memory-usage----- ---load-avg---
         time     |usr sys idl wai hiq siq| used  buff  cach  free| 1m   5m  15m 
    20-10 23:40:05|  9  10  80   2   0   0|2782M 43.7M  841M  170M|0.94 0.79 0.79
    20-10 23:40:07|  6   8  85   1   0   0|2782M 43.7M  841M  169M|0.94 0.79 0.79
    20-10 23:40:09|  6   8  86   1   0   0|2785M 43.7M  841M  166M|0.86 0.78 0.79
    20-10 23:40:11|  4  20  76   1   0   0|2785M 43.7M  841M  166M|0.86 0.78 0.79
    20-10 23:40:13|  4  14  81   0   0   0|2785M 43.7M  841M  166M|0.87 0.78 0.79
    20-10 23:40:15|  5   8  86   1   0   0|2785M 43.7M  841M  166M|0.87 0.78 0.79
    20-10 23:40:17|  5   7  87   1   0   0|2786M 43.8M  841M  165M|0.87 0.78 0.79
    20-10 23:40:19|  5   7  87   1   0   0|2787M 43.8M  841M  164M|0.80 0.77 0.78
    20-10 23:40:21|  6   8  86   0   0   0|2788M 43.8M  841M  163M|0.80 0.77 0.78
    20-10 23:40:23|  5   7  86   1   1   0|2789M 43.8M  841M  162M|0.74 0.75 0.78
    20-10 23:40:25| 11   9  79   0   1   0|2791M 43.8M  846M  156M|0.74 0.75 0.78

You can also use several internal and external plugins with dstat.

To list out all available plugins, run the following command:

dstat --list

Output:

    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-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

There are lots of useful options available with dstat, you can list out all available options with the following command:

dstat -h

Output:

    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

      --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

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

That’s it. Enjoy….

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]