Score:0

How to get average disk queue length of a physical hard drive based on folder path

cn flag

I want to check what is the disk queue length of a physical hard drive, on which a specified folder is stored e.g. /home/andy250/myfiles I want to check this automatically via script.

I am running Azure Linux VM (Ubuntu 20.04). Running df /home/andy250/myfiles gives me this:

Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/root       30309264 16460592  13832288  55% /

And then when I run iostat -x I get this

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.82    0.01    0.39    0.07    0.00   98.70

Device            r/s     rkB/s   rrqm/s  %rrqm r_await rareq-sz     w/s     wkB/s   wrqm/s  %wrqm w_await wareq-sz     d/s     dkB/s   drqm/s  %drqm d_await dareq-sz  aqu-sz  %util
loop0            0.01      0.37     0.00   0.00    0.18    41.25    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.00
loop1            0.02      0.83     0.00   0.00    0.42    51.09    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.00
loop10           0.05      1.48     0.00   0.00    0.06    29.10    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.00
loop11           0.00      0.03     0.00   0.00    0.27    21.31    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.00
loop12           0.01      0.36     0.00   0.00    0.07    62.18    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.00
loop13           0.05      2.16     0.00   0.00    0.24    45.46    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.00
loop14           0.02      0.72     0.00   0.00    0.05    38.69    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.01
loop15           0.00      0.02     0.00   0.00    0.10    18.17    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.00
loop16           0.02      0.74     0.00   0.00    0.03    38.20    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.01
loop17           0.05      1.44     0.00   0.00    0.04    27.94    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.00
loop2            0.03      0.39     0.00   0.00    0.10    12.35    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.00
loop3            0.00      0.00     0.00   0.00    0.20     1.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.00
loop4            0.04      0.50     0.00   0.00    0.07    13.31    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.00
loop5            0.04      0.47     0.00   0.00    0.07    12.60    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.00
loop6            0.07      1.05     0.00   0.00    0.08    14.19    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.01
loop7            0.06      1.50     0.00   0.00    0.11    25.58    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.01
loop8            0.09      0.28     0.00   0.00    0.04     2.97    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.00
loop9            0.01      0.33     0.00   0.00    0.11    37.36    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00   0.00
sda              1.02     26.82     0.08   7.04    0.85    26.31    1.31     45.36     0.98  42.76   14.55    34.66    0.11     59.70     0.00   0.49   10.11   561.47    0.02   0.32
sdb              0.00      0.02     0.00   0.00    0.29    29.83    0.00      0.54     0.00  60.32    3.06   479.99    0.00     54.03     0.00  50.00    0.07 242163.65    0.00   0.00

So the problem is that df shows a "Filesystem" that does not exist on the list of "Devices" in output of iostat. I am probably missing some fundamentals on how linux filesystem works, but I want to somehow figure out on which device the folder /home/andy250/myfiles (Filesystem /dev/root) physically exists - so I can parse the correct line of iostat output or just run iostat -dx [device id].

EDIT Output from lsblk

NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop1     7:1    0 135.1M  1 loop /snap/chromium/1912
loop2     7:2    0  55.5M  1 loop /snap/core18/2284
loop3     7:3    0     4K  1 loop /snap/bare/5
loop4     7:4    0  61.9M  1 loop /snap/core20/1328
loop5     7:5    0  61.9M  1 loop /snap/core20/1361
loop6     7:6    0 164.8M  1 loop /snap/gnome-3-28-1804/161
loop7     7:7    0 248.8M  1 loop /snap/gnome-3-38-2004/99
loop8     7:8    0  65.2M  1 loop /snap/gtk-common-themes/1519
loop9     7:9    0  43.6M  1 loop /snap/snapd/14978
loop10    7:10   0 346.8M  1 loop /snap/wine-platform-runtime/286
loop11    7:11   0   5.9M  1 loop /snap/notepad-plus-plus/346
loop12    7:12   0 134.8M  1 loop /snap/chromium/1926
loop13    7:13   0 322.9M  1 loop /snap/wine-platform-6-stable/14
loop14    7:14   0  67.2M  1 loop /snap/lxd/21835
loop15    7:15   0     6M  1 loop /snap/notepad-plus-plus/349
loop16    7:16   0  67.9M  1 loop /snap/lxd/22526
loop17    7:17   0 346.9M  1 loop /snap/wine-platform-runtime/287
sda       8:0    0    30G  0 disk 
├─sda1    8:1    0  29.9G  0 part /
├─sda14   8:14   0     4M  0 part 
└─sda15   8:15   0   106M  0 part /boot/efi
sdb       8:16   0    16G  0 disk 
└─sdb1    8:17   0    16G  0 part /mnt

EDIT 2 Output from ls -al /dev/root:

brw------- 1 root root 8, 1 Feb 28 08:17 /dev/root

Output from stat "$(realpath /dev/root)"

File: /dev/root
  Size: 0           Blocks: 0          IO Block: 4096   block special file
Device: 5h/5d   Inode: 160         Links: 1     Device type: 8,1
Access: (0600/brw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-02-28 08:18:15.753244000 +0000
Modify: 2022-02-28 08:17:56.732000000 +0000
Change: 2022-02-28 08:17:56.732000000 +0000
 Birth: -
Tom Yan avatar
in flag
Just curious, what does `ls -l /dev/root` give you? (And perhaps even, `stat "$(realpath /dev/root)"`)
andy250 avatar
cn flag
@TomYan updated my question with the outputs
Tom Yan avatar
in flag
Seems like it's an additional dev node that refers to the same block device as `/dev/sda1` does. See https://man7.org/linux/man-pages/man1/mknod.1.html for your reference and research about major minor.
Score:0
ca flag

Filesystem and physical block devices are different things, so you can not expect to find an sd* for each filesystem reported by df.

I suspect your /dev/root block device to be a symlink pointing to a device mapper (or LVM) disk. Please show the output of lsblk and pvs; vgs; lvs to confirm.

That said, your iostat output only shows sda and sdb (the various loop devices are for snaps) and so your root devices can only be backed by these two disks.

EDIT: your lsblk output clearly shows that /dev/sda1 is mounted as the root filesystem. The /dev/root entry is probably symlinked to /dev/sda1 (a thing you can check with ls -al /dev/root).

andy250 avatar
cn flag
edited my question with output from lsblk. The other 3 commands give me empty output.
shodanshok avatar
ca flag
@andy250 I've edited my answer
andy250 avatar
cn flag
Thanks, updated question with output from `ls -al /dev/root` and also `stat`
shodanshok avatar
ca flag
@andy250 The output of `lsblk` already shows your root device - which is `sda1`. No need to update the question with additional details from my part.
andy250 avatar
cn flag
I still have no idea how I could get from `/home/andy250/myfiles` to `sda` using a script. There seems to be too much guesswork or hidden knowledge to be able to resolve my path to `sda` in this case.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.