Projet

Général

Profil

Révision aa9a39f0

IDaa9a39f043d7b0ba8c6c919ec35a2241370288c6
Parent 2ad0dfec
Enfant 14fae657

Ajouté par Lars Kruse il y a plus de 8 ans

[zpool_iostat] improve formatting and variable names

Voir les différences:

plugins/zfs/zpool_iostat
58 58
fi
59 59

  
60 60
zlines=$("$ZPOOL_BIN" iostat -v | wc -l | sed 's/ //g')
61
pool_iostat=$("$ZPOOL_BIN" iostat -v 1 1 | tail "-$zlines")
62
zlist=$(echo "$pool_iostat" | gawk '/alloc/ {next}; /avail/ {next}; /raid/ {next}; /mirror/ {next}; { if ( $4 >=0 ) print $1}' | tr ' ' '\n')
63

  
64
# parse the n'th column of the iostat output for a given pool as a number (interpreting K and M suffixes)
65
get_pool_iostat() {
66
	local pool_label="$1"
61
iostats=$("$ZPOOL_BIN" iostat -v 1 1 | tail "-$zlines")
62
zlist=$(echo "$iostats" \
63
	| gawk '/alloc/ {next}; /avail/ {next}; /raid/ {next}; /mirror/ {next};
64
		{ if ( $4 >=0 ) print $1}' \
65
	| tr ' ' '\n')
66

  
67
# Parse the n'th column of the iostat output for a given pool or disk as a
68
# number (interpreting K and M suffixes).
69
get_device_iostat_column() {
70
	local device_label="$1"
67 71
	local stat_column="$2"
68
	echo "$pool_iostat" \
69
		| gawk '{ if ($1 == "'"$pool_label"'") print $'"$stat_column"'; }' \
70
		| gawk '/M/ {print strtonum($1)*1000}; /K/ {print strtonum($1)}; /[0-9]$/ {print int($1)/1000}'
72
	# convert all numeric values into kB
73
	echo "$iostats" \
74
		| gawk '{ if ($1 == "'"$device_label"'")
75
				print $'"$stat_column"'; }' \
76
		| gawk '/M/ {print strtonum($1)*1000};
77
			/K/ {print strtonum($1)};
78
			/[0-9]$/ {print int($1)/1000}'
71 79
}
72 80

  
73
get_pool_fieldname() {
74
	local pool_id="$1"
75
	# backwards compatibility (until 2016):
76
	# keep the unprefixed pool name for the fieldname, except for pool names starting with digits
77
	if echo "$pool_id" | grep -q "^[0-9]"; then
78
		clean_fieldname "_$pool_id"
81

  
82
get_device_fieldname() {
83
	local device_id="$1"
84
	# Backwards compatibility (until 2016): keep the unprefixed pool name
85
	# for the fieldname, except for pool names starting with digits.
86
	if echo "$device_id" | grep -q "^[0-9]"; then
87
		clean_fieldname "_$device_id"
79 88
	else
80
		clean_fieldname "$pool_id"
89
		clean_fieldname "$device_id"
81 90
	fi
82 91
}
83 92

  
93

  
84 94
if [ "$ACTION" = "config" ]; then
85 95
	echo 'graph_title zpool iostat'
86 96
	echo 'graph_args --base 1000 -l 0'
87
	echo 'graph_vlabel write - read KBytes/s'
97
	echo 'graph_vlabel write (-) / read (+) KBytes/s'
88 98
	echo 'graph_category disk'
89 99
	echo 'graph_scale no'
90 100
	echo 'graph_info This graph shows zpool iostat'
91
	# assemble the "graph_order" as a sorted list of read/write pairs for each poll
101
	# Assemble the "graph_order" as a sorted list of read/write pairs for
102
	# each device.
92 103
	printf "graph_order"
93
	echo "$zlist" | while read -r pool_id; do
94
		fieldname="$(get_pool_fieldname "pool_$pool_id")"
104
	echo "$zlist" | while read -r device_id; do
105
		fieldname="$(get_device_fieldname "pool_$device_id")"
95 106
		printf " %s_read %s_write" "$fieldname" "$fieldname"
96 107
	done
97
	# finalize the 'graph_order'
108
	# finalize the 'graph_order' with a newline
98 109
	echo
99 110
	# output all fields: write as negative numbers and read as positive
100
	echo "$zlist" | while read -r pool_id; do
101
		fieldname="$(get_pool_fieldname "pool_$pool_id")"
102
		echo "${fieldname}_read.label $pool_id"
111
	echo "$zlist" | while read -r device_id; do
112
		fieldname="$(get_device_fieldname "pool_$device_id")"
113
		echo "${fieldname}_read.label $device_id"
103 114
		echo "${fieldname}_read.type GAUGE"
104 115
		echo "${fieldname}_read.graph no"
105
		echo "${fieldname}_write.label $pool_id"
116
		echo "${fieldname}_write.label $device_id"
106 117
		echo "${fieldname}_write.type GAUGE"
107 118
		echo "${fieldname}_write.negative ${fieldname}_read"
108 119
	done
109 120
	exit 0
110 121
fi
111
echo "$zlist" | while read -r pool_id; do
112
	fieldname="$(get_pool_fieldname "pool_$pool_id")"
113
	echo "${fieldname}_read.value $(get_pool_iostat "$pool_id" 6)"
114
	echo "${fieldname}_write.value $(get_pool_iostat "$pool_id" 7)"
122

  
123

  
124
echo "$zlist" | while read -r device_id; do
125
	fieldname="$(get_device_fieldname "pool_$device_id")"
126
	echo "${fieldname}_read.value $(get_device_iostat_column "$device_id" 6)"
127
	echo "${fieldname}_write.value $(get_device_iostat_column "$device_id" 7)"
115 128
done

Formats disponibles : Unified diff