Révision a6b50554
Add illumos, FreeBSD, Linux support for zfs_arcstats plugin, cleanup code
| plugins/zfs/zfs_arcstats | ||
|---|---|---|
| 4 | 4 |
|
| 5 | 5 |
=head1 NAME |
| 6 | 6 |
|
| 7 |
zfs_arcstats - Munin multi-graph plugin to monitor Solaris ZFS ARC statistics
|
|
| 7 |
zfs_arcstats - Munin multi-graph plugin to monitor ZFS ARC statistics |
|
| 8 | 8 |
|
| 9 | 9 |
These functions are implemented: |
| 10 | 10 |
size : to monitor ARC size |
| ... | ... | |
| 13 | 13 |
actdata : to monitor ARC activities by data type (Demand/Prefetch) |
| 14 | 14 |
hitratio : to monitor ARC hit ratio |
| 15 | 15 |
|
| 16 |
Tested with Solaris 10 and 11.
|
|
| 16 |
Tested with Solaris 10 and 11, OpenIndiana Hipster, FreeBSD 11, CentOS 7
|
|
| 17 | 17 |
This plugin is inspired by arcstat.pl [https://github.com/mharsch/arcstat] |
| 18 | 18 |
|
| 19 | 19 |
=head1 CONFIGURATION |
| ... | ... | |
| 22 | 22 |
cd /path/to/munin/etc/plugins |
| 23 | 23 |
ln -s /path/to/munin/lib/plugins/zfs_arcstats . |
| 24 | 24 |
|
| 25 |
For FreeBSD, it should be necessary to change shebang /bin/bash -> /usr/local/bin/bash |
|
| 26 |
|
|
| 25 | 27 |
=head1 ENVIRONMENT VARIABLES |
| 26 | 28 |
|
| 27 | 29 |
None |
| ... | ... | |
| 54 | 56 |
|
| 55 | 57 |
# Functions |
| 56 | 58 |
|
| 59 |
get_osname() {
|
|
| 60 |
local osname osver |
|
| 61 |
|
|
| 62 |
osname=$( uname -s ) |
|
| 63 |
osver=$( uname -v ) |
|
| 64 |
|
|
| 65 |
case $osname in |
|
| 66 |
SunOS) |
|
| 67 |
case $osver in |
|
| 68 |
illumos*) |
|
| 69 |
osname=illumos |
|
| 70 |
;; |
|
| 71 |
esac |
|
| 72 |
;; |
|
| 73 |
esac |
|
| 74 |
|
|
| 75 |
echo "$osname" |
|
| 76 |
} |
|
| 77 |
|
|
| 57 | 78 |
preconfig() {
|
| 58 | 79 |
local func=$1 |
| 59 | 80 |
|
| ... | ... | |
| 69 | 90 |
graph_vlabel Bytes |
| 70 | 91 |
graph_info ZFS ARC - Size |
| 71 | 92 |
" |
| 93 |
case $osname in |
|
| 94 |
SunOS) |
|
| 95 |
# For Solaris 10,11 |
|
| 96 |
data_attr=" |
|
| 97 |
data_size GAUGE AREASTACK Data size |
|
| 98 |
prefetch_meta_size GAUGE AREASTACK Prefetch meta size |
|
| 99 |
buf_size GAUGE AREASTACK Buf size |
|
| 100 |
other_size GAUGE AREASTACK Other size |
|
| 101 |
" |
|
| 102 |
;; |
|
| 103 |
*) |
|
| 104 |
# For illumos, FreeBSD, Linux (OpenZFS) |
|
| 105 |
data_attr=" |
|
| 106 |
data_size GAUGE AREASTACK Data size |
|
| 107 |
metadata_size GAUGE AREASTACK Metadata size |
|
| 108 |
hdr_size GAUGE AREASTACK Hdr size |
|
| 109 |
other_size GAUGE AREASTACK Other size |
|
| 110 |
mru_size GAUGE LINE MRU size |
|
| 111 |
mfu_size GAUGE LINE MFU size |
|
| 112 |
" |
|
| 113 |
;; |
|
| 114 |
esac |
|
| 72 | 115 |
data_attr=" |
| 73 |
data_size GAUGE AREASTACK Data size |
|
| 74 |
prefetch_meta_size GAUGE AREASTACK Prefetch meta size |
|
| 75 |
buf_size GAUGE AREASTACK Buf size |
|
| 76 |
other_size GAUGE AREASTACK Other size |
|
| 77 |
c GAUGE LINE Target size |
|
| 78 |
p GAUGE LINE Target MRU size |
|
| 116 |
$data_attr |
|
| 117 |
size GAUGE LINE ARC size |
|
| 118 |
c GAUGE LINE Target size |
|
| 119 |
p GAUGE LINE Target MRU size |
|
| 79 | 120 |
" |
| 80 | 121 |
;; |
| 81 | 122 |
activity) |
| ... | ... | |
| 146 | 187 |
graph_vlabel % hits |
| 147 | 188 |
graph_info ZFS ARC - Hit ratio - The graph shows cache hit ratio between munin-update intervals (usually 5 minutes). |
| 148 | 189 |
|
| 149 |
hitratio.cdef hits,DUP,DUP,misses,+,/,100,*,hitratio,IF
|
|
| 150 |
l2_hitratio.cdef l2_hits,DUP,DUP,l2_misses,+,/,100,*,l2_hitratio,IF
|
|
| 151 |
demand_data_hitratio.cdef demand_data_hits,DUP,DUP,demand_data_misses,+,/,100,*,demand_data_hitratio,IF
|
|
| 152 |
demand_metadata_hitratio.cdef demand_metadata_hits,DUP,DUP,demand_metadata_misses,+,/,100,*,demand_metadata_hitratio,IF
|
|
| 153 |
prefetch_data_hitratio.cdef prefetch_data_hits,DUP,DUP,prefetch_data_misses,+,/,100,*,prefetch_data_hitratio,IF
|
|
| 154 |
prefetch_metadata_hitratio.cdef prefetch_metadata_hits,DUP,DUP,prefetch_metadata_misses,+,/,100,*,prefetch_metadata_hitratio,IF
|
|
| 190 |
hitratio.cdef hits,DUP,misses,+,/,100,*
|
|
| 191 |
l2_hitratio.cdef l2_hits,DUP,l2_misses,+,/,100,*
|
|
| 192 |
demand_data_hitratio.cdef demand_data_hits,DUP,demand_data_misses,+,/,100,*
|
|
| 193 |
demand_metadata_hitratio.cdef demand_metadata_hits,DUP,demand_metadata_misses,+,/,100,*
|
|
| 194 |
prefetch_data_hitratio.cdef prefetch_data_hits,DUP,prefetch_data_misses,+,/,100,*
|
|
| 195 |
prefetch_metadata_hitratio.cdef prefetch_metadata_hits,DUP,prefetch_metadata_misses,+,/,100,*
|
|
| 155 | 196 |
" |
| 156 |
# Note: hitratio = hits > 0 ? hits / ( hits + misses ) * 100 : 0 |
|
| 157 |
|
|
| 158 |
# Bug?: If '0' is set at IF ELSE of CDEF, RRD cur value always become 0. |
|
| 159 |
# NG: hits,DUP,DUP,misses,+,/,100,*,0,IF |
|
| 160 |
# OK: hits,DUP,DUP,misses,+,/,100,*,hitratio,IF |
|
| 161 |
|
|
| 162 | 197 |
data_attr=" |
| 163 | 198 |
hits DERIVE LINE dummy |
| 164 | 199 |
misses DERIVE LINE dummy |
| ... | ... | |
| 218 | 253 |
} |
| 219 | 254 |
|
| 220 | 255 |
get_stats() {
|
| 221 |
local stat value |
|
| 256 |
local arcstats stat value
|
|
| 222 | 257 |
|
| 258 |
case $osname in |
|
| 259 |
SunOS|illumos) |
|
| 260 |
arcstats=$( kstat -p 'zfs:0:arcstats' | sed -e 's/:/ /g' | awk '{ print $4,$5 }' )
|
|
| 261 |
# kstat output example: |
|
| 262 |
# $ kstat -p zfs:0:arcstats |
|
| 263 |
# zfs:0:arcstats:c 4135233544 |
|
| 264 |
# ... |
|
| 265 |
;; |
|
| 266 |
*BSD) |
|
| 267 |
arcstats=$( /sbin/sysctl -a | sed -n -e 's/^kstat\.zfs\.misc\.arcstats\.//p' | awk -F: '{ print $1,$2 }' )
|
|
| 268 |
# sysctl output example: |
|
| 269 |
# $ sysctl -a |
|
| 270 |
# ... |
|
| 271 |
# kstat.zfs.misc.arcstats.c: 632540160 |
|
| 272 |
# ... |
|
| 273 |
;; |
|
| 274 |
Linux) |
|
| 275 |
arcstats=$( sed '1,2d' /proc/spl/kstat/zfs/arcstats | awk '{ print $1,$3 }' )
|
|
| 276 |
# proc file output example: |
|
| 277 |
# $ cat /proc/spl/kstat/zfs/arcstats |
|
| 278 |
# ... |
|
| 279 |
# name type data |
|
| 280 |
# hits 4 62 |
|
| 281 |
# ... |
|
| 282 |
;; |
|
| 283 |
*) |
|
| 284 |
echo "Unsupported OS: $osname" |
|
| 285 |
exit 1 |
|
| 286 |
esac |
|
| 287 |
|
|
| 223 | 288 |
while read -r stat value |
| 224 | 289 |
do |
| 225 | 290 |
printf -v "arcstats_${stat}" "%s" "$value"
|
| 226 | 291 |
# printf -v means indirect variable assignment (similar to eval) |
| 227 |
done < <( kstat -p 'zfs:0:arcstats' | sed -e 's/:/ /g' | awk '{ print $4,$5 }' )
|
|
| 228 |
|
|
| 229 |
# kstat output example: |
|
| 230 |
# $ kstat -p zfs:0:arcstats:c |
|
| 231 |
# zfs:0:arcstats:c 4135233544 |
|
| 232 |
# ... |
|
| 233 |
|
|
| 234 |
# Note: It should be possible to monitor ZFS on FreeBSD/Linux by |
|
| 235 |
# imprementing get_stats function as well. |
|
| 236 |
|
|
| 237 |
# FreeBSD: sysctl kstat.zfs.misc.arcstats ... |
|
| 238 |
# Linux: cat /proc/spl/kstat/zfs/arcstats ... |
|
| 292 |
done <<< "$arcstats" |
|
| 239 | 293 |
} |
| 240 | 294 |
|
| 241 | 295 |
do_fetch() {
|
| ... | ... | |
| 260 | 314 |
} |
| 261 | 315 |
|
| 262 | 316 |
autoconf() {
|
| 263 |
if which kstat >/dev/null ; then
|
|
| 317 |
if [ -x /sbin/zfs ]; then
|
|
| 264 | 318 |
echo yes |
| 265 | 319 |
else |
| 266 |
echo "no (failed to find executable 'kstat')"
|
|
| 320 |
echo "no (ZFS looks unavailable)"
|
|
| 267 | 321 |
fi |
| 268 | 322 |
} |
| 269 | 323 |
|
| ... | ... | |
| 288 | 342 |
} |
| 289 | 343 |
|
| 290 | 344 |
# Main |
| 345 |
|
|
| 346 |
osname=$( get_osname ) |
|
| 347 |
|
|
| 291 | 348 |
case ${1:-} in
|
| 292 | 349 |
autoconf) |
| 293 | 350 |
autoconf |
Formats disponibles : Unified diff