48

I'd like to watch disk activity on my USB external hard drive. I know that I can use iotop to monitor disk I/O for each running process, but is there a way to get a measure per filesystem?

5 Answers 5

31

dstat is better than iostat for strictly monitoring disk activity.

I am running the following command while moving files from one harddrive to another

dstat -D sda,sdc

for more info, have a look at this page

https://help.ubuntu.com/community/DiskPerformance

5
  • 3
    Very nice. However this way I can't see which process is causing the IO. So I'm stuck with either seeing which process (with iotop) or which device (with dstat), but not both.
    – jlh
    Dec 24, 2018 at 11:55
  • 1
    I wish we could also limit its monitoring to a specific process
    – matanox
    Aug 25, 2019 at 7:47
  • 1
    And in contrast to iotop it doesn't even need root.
    – Nobody
    Mar 9, 2020 at 10:44
  • Good call @jlh I understand your pain point and I can't think of an easy solution other than understanding your running process. You should know for example that postgresql is installed on a specific drive and has storage on the other one. so, with that knowledge, looking at both iotop and dstat should give you the information you need. hope this helps.
    – Mathieu J.
    Mar 10, 2020 at 0:55
  • @Nobody iotop needs root to look into process you do not own. dstat don't need root as devices info is available to normal users under /proc and /sys stats files
    – Mathieu J.
    Mar 10, 2020 at 0:57
24

I'm not skilled in this area, but iostat comes to mind. You can install it with the sysstat package. Good luck!

4
  • 6
    example usage: iostat -d 10 /dev/sda will give you the io utilization in 10 second intervals of /dev/sda. I'd almost use watch iostat -d /dev/sda over its interval option. Edit: beat me to it while I was typing :)
    – aperson
    Sep 3, 2010 at 21:24
  • 1
    I just read that the first set of values reported are statistics from what has occurred since system startup, so it turns out not to make much sense to use watch. Continuous reporting with something like iostat -dk 10 returns more meaningful numbers.
    – ændrük
    Sep 3, 2010 at 21:41
  • Hmm... I just don't like that it fills my entire scrollback.
    – aperson
    Sep 3, 2010 at 22:08
  • Crank open a new terminal and do it then
    – codaamok
    Mar 2, 2016 at 14:05
16

Using iostat from the sysstat package provides a single snapshot of results since startup. Use of the interval parameter will append the results for only the last interval to the output. Example, iostat 10 will first show the "since boot" values then continue to add the last 10 seconds of statistics to the output, every 10 seconds. Include the -y option to omit the first display of statistics since boot but understand that the command will appear idle for the specified interval while the system collects the first snapshot.

I've found this most effective when combined with the watch command and indicating to only collect for a single interval of statistics. For example:

watch -t -n 0.1 iostat -p sda,sdc -d -t -y 5 1

This gives a refresh every 5.1 seconds of activity statistics for the last 5 seconds. To break down the options and parameters...

  • The first -t tells watch to omit the header. This is to avoid confusion that otherwise the header will include "Every 0.1s" which does not represent the snapshot of data.
  • The -n 0.1 tells watch to run the following command every 0.1 seconds. This is the smallest interval for watch (procps-ng 3.3.9) but don't worry, it isn't actually running the command every 0.1 seconds. It will run the command 0.1 seconds after the prior instance completes.
  • The -p sda,sdc tells iostat to only display stats for these devices.
  • The -d tells iostat to only display device utilization, relevant since the question was concerning disk activity.
  • The second -t switch tells iostat to include the time of the refresh in the statistics. This is useful since the earlier omission of the watch header removed the time display that would have been there.
  • The -y switch omits the first screen of "since boot" statistics from the interval display. Without this the result would be a display of the statistics since boot updating at the interval of the watch command.
  • The 5 1 are the iostat interval parameters. In this case capture 5 seconds of statistics once (the 1). Because the -y switch was used this will only present a single screen of data.

It will take 5 seconds for iostat to collect the data, it will then be displayed in watch, and 0.1 seconds later watch will trigger the iostat command again. 5 seconds later the new data will replace the old, watch will wait 0.1 seconds, wash, rinse, repeat...

14

Try with nmon

sudo apt-get install nmon

Try:

nmon

Output Like below:

enter image description here

Press d = Disk Press c = CPU Press r = RAM, Press v = Virtual Memory, Kernal Status press K, Press N = network and Press q or x to exit

1

In order to monitor disk IO per device and process in one glance, consider using glances.

https://nicolargo.github.io/glances

You can install it with apt:

sudo apt install glances

or pip:

pip install glances
1
  • Best answer. Glances replaces iotop+dstat
    – ChennyStar
    Apr 10, 2023 at 13:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .