Linux I/O Monitoring and Analyze: Difference between revisions

From WikiMLT
Line 97: Line 97:
| t = 16
| t = 16
| side = 16
| side = 16
}}
}}Here is an advanced version :) which outputs also an additional data generated by <code>iostat</code>:<syntaxhighlight lang="shell" line="1" class="multi-line-cmd">
sudo watch -d \
"find /var/lib /var/log -type f -size +800k -mmin -10 -printf '%s    \t %t %p\n' | grep -Pv '\.(gz|[0-9])$';
echo;
iostat /dev/sda2"
 
</syntaxhighlight><syntaxhighlight lang="shell-session">
ss
</syntaxhighlight>


== References ==
== References ==

Revision as of 22:43, 28 August 2022

There is a cou­ple of tools avail­able that al­lows you to mon­i­tor and an­a­lyze the disk I/O per­for­mance of your Lin­ux dri­ven sys­tem. Here are list­ed few of them and al­so how to in­stall and ex­am­ples of their ba­sic us­age.

The htop com­mand

If a new­er ver­sion of htop is avail­able at your dis­tri­b­u­tion, there is avail­able an ad­di­tion­al tab that shows the I/O met­rics of the in­stance – Screen 1. Here is how to check the avail­able ver­sion and in­stall htop.

sudo apt show htop 2>/dev/null | grep '^Version'
sudo apt install htop

In­stall the lat­est ver­sion of htop 3.2.1–1 on Ubun­tu Serv­er 22.04.1 from a .deb pack­age.

cd /tmp
wget --no-check-certificate https://http.us.debian.org/debian/pool/main/h/htop/htop_3.2.1-1_amd64.deb
sudo apt install ./htop_3.2.1-1_amd64.deb

To be able to see all da­ta in most cas­es you need to run the tool as root:

sudo htop
Screen 1. The new I/O Met­rics tab of htop (v 3.2+). Use Tab to switch to the I/O tab, then use F6 to open the Sort by menu, and sort by IO_WRITE_RATE. The screen­shot is tak­en on Kali Lin­ux 2022. Screen 1. The new I/O Metrics tab of htop (v 3.2+). Use Tab to switch to the I/O tab, then use F6 to open the Sort by menu, and sort by IO_WRITE_RATE. The screenshot is taken on Kali Linux 2022.

The io­stat com­mand

The iotop com­mand

The dstat com­mand

sudo apt install dstat
sudo dstat -D sdc -ta --top-bio
----system---------total-cpu-usage-------dsk/sdc------net/total------paging-------system--------most-expensive--------
     time      | usr sys idl wai stl | read   writ | recv   send |  in   out  | int   csw  |  block     i/o   process
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
02-04 09:25:42 |  2   0  97   0   0  | 160k   208k |   0      0  | 170B  835B | 1951  7955 | systemd    1285k 1569k
02-04 09:25:43 |  2   1  97   0   0  |   0      0  |  66k    57k |   0     0  | 2614  5033 | pvestatd   1280k    0
02-04 09:25:44 |  2   1  98   0   0  |   0      0  |  16k    21k |   0     0  | 2830  7131 | kvm           0    32k
02-04 09:25:45 |  2   1  98   0   0  |   0      0  |  45k    54k |   0     0  | 2347  5187 | kvm           0   320k
02-04 09:25:46 |  3   1  96   0   0  |   0      0  |  24k    29k |   0     0  | 2686  8578 | ceph-mon      0    64k

The sar com­mand

The sar com­mand is par of the pack­age sys­stat. It out­puts the con­tents of se­lect­ed cu­mu­la­tive ac­tiv­i­ty coun­ters in the  op­er­at­ing  sys­tem. The ac­tiv­i­ties are col­lect­ed by the sysstat.service. Af­ter in­stalling the pack­age we need to en­able the col­lec­tor ser­vice and wait un­til some sta­tis­tics are col­lect­ed.

sudo apt install sysstat
sudo sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat
sudo systemctl enable --now sysstat.service
systemctl cat sysstat-collect.timer
# /lib/systemd/system/sysstat-collect.timer
# /lib/systemd/system/sysstat-collect.timer
# (C) 2014 Tomasz Torcz <tomek@pipebreaker.pl>
#
# sysstat-12.5.2 systemd unit file:
#        Activates activity collector every 10 minutes

[Unit]
Description=Run system activity accounting tool every 10 minutes

[Timer]
OnCalendar=*:00/10

[Install]
WantedBy=sysstat.service
sar
Linux 5.15.39-4-pve (ubuntu-lxc-pve) 	08/28/22 	_x86_64_	(24 CPU)

20:41:48     LINUX RESTART	(24 CPU)

20:50:05        CPU     %user     %nice   %system   %iowait    %steal     %idle
21:00:00        all      1.66      0.00      0.26      0.02      0.00     98.06
21:10:10        all      2.66      0.00      0.27      0.03      0.00     97.03
21:20:13        all      1.92      0.00      0.29      0.02      0.00     97.76
Average:        all      2.09      0.00      0.27      0.03      0.00     97.62

Mon­i­tor the Files Size Changes Re­cur­sive­ly

By the fol­low­ing com­mand we can mon­i­tor which are the most writ­ten files for the past 10 min­utes, larg­er than 800 Kb. This is done re­cur­sive­ly for the di­rec­to­ries /​​​var/​​​lib and /​​​var/​​​log. The out­put of the com­mand is shown at Screen 2.

sudo watch -n 3 -d \
"find /var/lib /var/log -type f -size +800k -mmin -10 -printf '%s    \t %t %p\n' | grep -Pv '\.(gz|[0-9])$'"
Screen 2. Use watch and find to monitor file change in real time.
Screen 2. Use watch and find to mon­i­tor file change in re­al time. Screen 2. Use watch and find to monitor file change in real time.

Here is an ad­vanced ver­sion :) which out­puts al­so an ad­di­tion­al da­ta gen­er­at­ed by io­stat:

sudo watch -d \
"find /var/lib /var/log -type f -size +800k -mmin -10 -printf '%s    \t %t %p\n' | grep -Pv '\.(gz|[0-9])$';
 echo;
 iostat /dev/sda2"
ss

Ref­er­ences