A background pattern of shaded interlocking triangles

Time CIFS File Performance Using Stderr and Grouping

Here is a simple snippet for timing file system performance. 

I wrote this as part of a script to detect an infrequent but recurrent error mode on a NAS that causes performance degradation. I run the script hourly from a Linux host with a CIFS share mounted from the NAS in question and collect the performance metrics in InfluxDB (using this technique) for graphing and alerting using Grafana.

Should the error occur, detection is triggered when the time taken to perform the test exceeds a threshold; a reboot of the NAS subsequently recovers service. 

I'm sharing this snippet as it demonstrates both redirection of stderr to stdout and command grouping to successfully capture of output of the time command in greppable form. 

This took some time and effort to research, which I hope might be time saved for you. This technique might also be used to capture and process other output dependent upon stderr and piping. 

ttt="$( { time -p dd if=/dev/zero of=/mnt/nas-share/testfile bs=16k count=8k; } 2>&1 | grep real )"
ttt="$( echo $ttt | awk '{print $2}' )"
rm /mnt/nas-share/testfile

Consequently, variable ttt holds the time in seconds taken to perform the write.  

Of course, other potentially more robust techniques exist for timing I/O performance, and this method is not intended be particularly scientific. However, it is a quick and simple way of detecting significant change in file system performance without installing additional (and often more complex) tools.