-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prebaked scripts for zpool status/iostat -c
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 <[email protected]> Reviewed-by: Giuseppe Di Natale <[email protected]> Signed-off-by: Tony Hutter <[email protected]> Closes #5852
- Loading branch information
1 parent
038091f
commit d6418de
Showing
36 changed files
with
1,218 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
This directory contains scripts that can be run the zpool status/iostat | ||
-c option: | ||
|
||
zpool status -c script1,script2, ... | ||
|
||
zpool iostat -vc script1,script2, ... | ||
|
||
Some scripts output different values depending on the symlink name that is | ||
used to run them. See the zpool(8) man page for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
iostat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
iostat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lsblk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/sh | ||
# | ||
# Print some common lsblk values | ||
# | ||
# Any (lowercased) name symlinked to the lsblk script will be passed to lsblk | ||
# as one of its --output names. Here's a partial list of --output names | ||
# from the lsblk binary: | ||
# | ||
# Available columns (for --output): | ||
# NAME device name | ||
# KNAME internal kernel device name | ||
# MAJ:MIN major:minor device number | ||
# FSTYPE filesystem type | ||
# MOUNTPOINT where the device is mounted | ||
# LABEL filesystem LABEL | ||
# UUID filesystem UUID | ||
# RA read-ahead of the device | ||
# RO read-only device | ||
# RM removable device | ||
# MODEL device identifier | ||
# SIZE size of the device | ||
# STATE state of the device | ||
# OWNER user name | ||
# GROUP group name | ||
# MODE device node permissions | ||
# ALIGNMENT alignment offset | ||
# MIN-IO minimum I/O size | ||
# OPT-IO optimal I/O size | ||
# PHY-SEC physical sector size | ||
# LOG-SEC logical sector size | ||
# ROTA rotational device | ||
# SCHED I/O scheduler name | ||
# RQ-SIZE request queue size | ||
# TYPE device type | ||
# DISC-ALN discard alignment offset | ||
# DISC-GRAN discard granularity | ||
# DISC-MAX discard max bytes | ||
# DISC-ZERO discard zeroes data | ||
# | ||
# If the script is run as just 'lsblk' then print out disk size, vendor, | ||
# model number and serial number. | ||
|
||
|
||
helpstr=" | ||
label: Show filesystem label. | ||
model: Show disk model number. | ||
serial: Show disk serial number. | ||
size: Show the disk capacity. | ||
vendor: Show the disk vendor. | ||
lsblk: Show the disk size, vendor, model number, and serial number." | ||
|
||
script=$(basename "$0") | ||
|
||
if [ "$1" = "-h" ] ; then | ||
echo "$helpstr" | grep "$script:" | tr -s '\t' | cut -f 2- | ||
exit | ||
fi | ||
|
||
if [ "$script" = "lsblk" ] ; then | ||
list="size vendor model serial" | ||
else | ||
list=$(echo "$script" | tr '[:upper:]' '[:lower:]') | ||
fi | ||
|
||
# Older versions of lsblk don't support all these values (like SERIAL). | ||
for i in $list ; do | ||
|
||
# Special case: Looking up the size of a file-based vdev can't | ||
# be done with lsblk. | ||
if [ "$i" = "size" ] && [ -f "$VDEV_UPATH" ] ; then | ||
size="$(du -h --apparent-size $VDEV_UPATH | cut -f 1)" | ||
echo "size=$size" | ||
continue | ||
fi | ||
|
||
|
||
val="" | ||
if val=$(eval "lsblk -dl -n -o $i $VDEV_UPATH 2>/dev/null") ; then | ||
# Remove leading/trailing whitespace from value | ||
val=$(echo "$val" | sed -e 's/^[[:space:]]*//' \ | ||
-e 's/[[:space:]]*$//') | ||
fi | ||
echo "$i=$val" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lsblk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lsblk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/sh | ||
# | ||
# Print SCSI Enclosure Services (SES) info. The output is dependent on the name | ||
# of the script/symlink used to call it. | ||
# | ||
helpstr=" | ||
enc: Show disk enclosure w:x:y:z value. | ||
slot: Show disk slot number as reported by the enclosure. | ||
encdev: Show the /dev/sg* device for the enclosure associated with the disk slot. | ||
fault_led: Show the value of the disk enclosure slot fault LED. | ||
locate_led: Show the value of the disk enclosure slot locate LED. | ||
ses: Show disk's enclosure, enclosure dev, slot number, and fault/locate LED values." | ||
|
||
script=$(basename "$0") | ||
if [ "$1" = "-h" ] ; then | ||
echo "$helpstr" | grep "$script:" | tr -s '\t' | cut -f 2- | ||
exit | ||
fi | ||
|
||
if [ "$script" = "ses" ] ; then | ||
scripts='enc encdev slot fault_led locate_led' | ||
else | ||
scripts="$script" | ||
fi | ||
|
||
for i in $scripts ; do | ||
if [ -z "$VDEV_ENC_SYSFS_PATH" ] ; then | ||
echo "$i=" | ||
continue | ||
fi | ||
|
||
val="" | ||
case $i in | ||
enc) | ||
val=$(ls "$VDEV_ENC_SYSFS_PATH/../../" 2>/dev/null) | ||
;; | ||
slot) | ||
val=$(cat "$VDEV_ENC_SYSFS_PATH/slot" 2>/dev/null) | ||
;; | ||
encdev) | ||
val=$(ls "$VDEV_ENC_SYSFS_PATH/../device/scsi_generic" 2>/dev/null) | ||
;; | ||
fault_led) | ||
val=$(cat "$VDEV_ENC_SYSFS_PATH/fault" 2>/dev/null) | ||
;; | ||
locate_led) | ||
val=$(cat "$VDEV_ENC_SYSFS_PATH/locate" 2>/dev/null) | ||
;; | ||
esac | ||
echo "$i=$val" | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lsblk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/sh | ||
# | ||
# Show device mapper slave devices. This is useful for looking up the | ||
# /dev/sd* devices associated with a dm or multipath device. For example: | ||
# | ||
# $ ls /sys/block/dm-113/slaves/ | ||
# sddt sdjw | ||
# | ||
|
||
if [ "$1" = "-h" ] ; then | ||
echo "Show device mapper slave devices." | ||
exit | ||
fi | ||
|
||
dev="$VDEV_PATH" | ||
|
||
# If the VDEV path is a symlink, resolve it to a real device | ||
if [ -L "$dev" ] ; then | ||
dev=$(readlink "$dev") | ||
fi | ||
|
||
dev=$(basename "$dev") | ||
val="" | ||
if [ -d "/sys/class/block/$dev/slaves" ] ; then | ||
# ls -C: output in columns, no newlines | ||
val=$(ls -C "/sys/class/block/$dev/slaves") | ||
|
||
# ls -C will print two spaces between files; change to one space. | ||
val=$(echo "$val" | sed -r 's/[[:blank:]]+/ /g') | ||
fi | ||
|
||
echo "slaves=$val" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
if [ "$1" = "-h" ] ; then | ||
echo "Show the underlying path for a device." | ||
exit | ||
fi | ||
|
||
echo upath="$VDEV_UPATH" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lsblk |
Oops, something went wrong.