Optimize RAIDZ expansion
[zfs.git] / cmd / zpool / zpool.d / iostat
blob2f8d79af89262dda373978275214f4097e1e777d
1 #!/bin/sh
3 # Display most relevant iostat bandwidth/latency numbers. The output is
4 # dependent on the name of the script/symlink used to call it.
7 helpstr="
8 iostat: Show iostat values since boot (summary page).
9 iostat-1s: Do a single 1-second iostat sample and show values.
10 iostat-10s: Do a single 10-second iostat sample and show values."
12 script="${0##*/}"
13 if [ "$1" = "-h" ] ; then
14 echo "$helpstr" | grep "$script:" | tr -s '\t' | cut -f 2-
15 exit
18 # Sometimes, UPATH ends up /dev/(null).
19 # That should be corrected, but for now...
20 # shellcheck disable=SC2154
21 if [ ! -b "$VDEV_UPATH" ]; then
22 somepath="${VDEV_PATH}"
23 else
24 somepath="${VDEV_UPATH}"
27 if [ "$script" = "iostat-1s" ] ; then
28 # Do a single one-second sample
29 interval=1
30 # Don't show summary stats
31 brief="yes"
32 elif [ "$script" = "iostat-10s" ] ; then
33 # Do a single ten-second sample
34 interval=10
35 # Don't show summary stats
36 brief="yes"
39 if [ -f "$somepath" ] ; then
40 # We're a file-based vdev, iostat doesn't work on us. Do nothing.
41 exit
44 if [ "$(uname)" = "FreeBSD" ]; then
45 out=$(iostat -dKx \
46 ${interval:+"-w $interval"} \
47 ${interval:+"-c 1"} \
48 "$somepath" | tail -n 2)
49 else
50 out=$(iostat -kx \
51 ${brief:+"-y"} \
52 ${interval:+"$interval"} \
53 ${interval:+"1"} \
54 "$somepath" | grep -v '^$' | tail -n 2)
58 # Sample output (we want the last two lines):
60 # Linux 2.6.32-642.13.1.el6.x86_64 (centos68) 03/09/2017 _x86_64_ (6 CPU)
62 # avg-cpu: %user %nice %system %iowait %steal %idle
63 # 0.00 0.00 0.00 0.00 0.00 100.00
65 # Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
66 # sdb 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
69 # Get the column names
70 cols=$(echo "$out" | head -n 1)
72 # Get the values and tab separate them to make them cut-able.
73 vals=$(echo "$out" | tail -n 1 | tr -s '[:space:]' '\t')
75 i=0
76 for col in $cols ; do
77 i=$((i+1))
78 # Skip the first column since it's just the device name
79 if [ "$i" -eq 1 ]; then
80 continue
83 # Get i'th value
84 val=$(echo "$vals" | cut -f "$i")
85 echo "$col=$val"
86 done