mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-18 18:31:00 +03:00
d6418de057
This patch updates the "zpool status/iostat -c" commands to only run "pre-baked" scripts from the /etc/zfs/zpool.d directory (or wherever you install to). The scripts can only be run from -c as an unprivileged user (unless the ZPOOL_SCRIPTS_AS_ROOT environment var is set by root). This was done to encourage scripts to be written is such a way that normal users can use them, and to be cautious. If your script needs to run a privileged command, consider adding the appropriate line in /etc/sudoers. See zpool(8) for an example of how to do this. The patch also allows the scripts to output custom column names. If the script outputs a line like: name=value then "name" is used for the column name, and "value" is its value. Multiple columns can be specified by outputting multiple lines. Column names and values can have spaces. If the value is empty, a dash (-) is printed instead. After all the "name=value" lines are read (if any), zpool will take the next the next line of output (if any) and print it without a column header. After that, no more lines will be processed. This can be useful for printing errors. Lastly, this patch also disables the -c option with the latency and request size histograms, since it produced awkward output and made the code harder to maintain. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov> Signed-off-by: Tony Hutter <hutter2@llnl.gov> Closes #5852
66 lines
1.8 KiB
Bash
Executable File
66 lines
1.8 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Display most relevant iostat bandwidth/latency numbers. The output is
|
|
# dependent on the name of the script/symlink used to call it.
|
|
#
|
|
|
|
helpstr="
|
|
iostat: Show iostat values since boot (summary page).
|
|
iostat-1s: Do a single 1-second iostat sample and show values.
|
|
iostat-10s: Do a single 10-second iostat sample and show values."
|
|
|
|
script=$(basename "$0")
|
|
if [ "$1" = "-h" ] ; then
|
|
echo "$helpstr" | grep "$script:" | tr -s '\t' | cut -f 2-
|
|
exit
|
|
fi
|
|
|
|
if [ "$script" = "iostat-1s" ] ; then
|
|
# Do a single one-second sample
|
|
extra="1 1"
|
|
# Don't show summary stats
|
|
y="-y"
|
|
elif [ "$script" = "iostat-10s" ] ; then
|
|
# Do a single ten-second sample
|
|
extra="10 1"
|
|
# Don't show summary stats
|
|
y="-y"
|
|
fi
|
|
|
|
if [ -f "$VDEV_UPATH" ] ; then
|
|
# We're a file-based vdev, iostat doesn't work on us. Do nothing.
|
|
exit
|
|
fi
|
|
|
|
out=$(eval "iostat $y -k -x $VDEV_UPATH $extra")
|
|
|
|
# Sample output (we want the last two lines):
|
|
#
|
|
# Linux 2.6.32-642.13.1.el6.x86_64 (centos68) 03/09/2017 _x86_64_ (6 CPU)
|
|
#
|
|
# avg-cpu: %user %nice %system %iowait %steal %idle
|
|
# 0.00 0.00 0.00 0.00 0.00 100.00
|
|
#
|
|
# Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
|
|
# 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
|
|
#
|
|
|
|
# Get the column names
|
|
cols=$(echo "$out" | grep Device)
|
|
|
|
# Get the values and tab separate them to make them cut-able.
|
|
vals="$(echo "$out" | grep -A1 Device | tail -n 1 | sed -r 's/[[:blank:]]+/\t/g')"
|
|
|
|
i=0
|
|
for col in $cols ; do
|
|
i=$((i+1))
|
|
# Skip the first column since it's just the device name
|
|
if [ "$col" = "Device:" ] ; then
|
|
continue
|
|
fi
|
|
|
|
# Get i'th value
|
|
val=$(echo "$vals" | cut -f "$i")
|
|
echo "$col=$val"
|
|
done
|