Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / zfs / zfs_arcstats @ 17f78427

Historique | Voir | Annoter | Télécharger (9,76 ko)

1
#!/bin/bash
2

    
3
: << =cut
4

    
5
=head1 NAME
6

    
7
  zfs_arcstats - Munin multi-graph plugin to monitor ZFS ARC statistics
8

    
9
  These functions are implemented:
10
    size     : to monitor ARC size
11
    activity : to monitor ARC activities
12
    actlist  : to monitor ARC activities by cache list (MFU/MRU)
13
    actdata  : to monitor ARC activities by data type (Demand/Prefetch)
14
    hitratio : to monitor ARC hit ratio
15

    
16
  Tested with Solaris 10 and 11, OpenIndiana Hipster, FreeBSD 11, CentOS 7
17
  This plugin is inspired by arcstat.pl [https://github.com/mharsch/arcstat]
18

    
19
=head1 CONFIGURATION
20

    
21
  Make symlink:
22
    cd /path/to/munin/etc/plugins
23
    ln -s /path/to/munin/lib/plugins/zfs_arcstats .
24

    
25
  For FreeBSD, it should be necessary to change shebang /bin/bash -> /usr/local/bin/bash
26

    
27
=head1 ENVIRONMENT VARIABLES
28

    
29
  None
30

    
31
=head1 AUTHOR
32

    
33
  K.Cima https://github.com/shakemid
34

    
35
=head1 LICENSE
36

    
37
  GPLv2
38

    
39
=head1 Magic markers
40

    
41
  #%# family=contrib
42
  #%# capabilities=autoconf
43

    
44
=cut
45

    
46
# Include plugin.sh
47
. "${MUNIN_LIBDIR:-}/plugins/plugin.sh"
48
is_multigraph "$@"
49

    
50
# Shell options
51
set -o nounset
52

    
53
# Set global variables
54
plugin_name=zfs_arcstats
55
functions='size activity actlist actdata hitratio'
56

    
57
# Functions
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

    
78
preconfig() {
79
    local func=$1
80

    
81
    # data_attr format: field type draw label
82
    #   label can contain white-spaces.
83

    
84
    case $func in
85
    size)
86
        global_attr="
87
            graph_title ZFS ARC - Size
88
            graph_category fs
89
            graph_args --base 1024 --lower-limit 0
90
            graph_vlabel Bytes
91
            graph_info ZFS ARC - Size
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
115
        data_attr="
116
            $data_attr
117
            size GAUGE LINE ARC size
118
            c    GAUGE LINE Target size
119
            p    GAUGE LINE Target MRU size
120
        "
121
        ;;
122
    activity)
123
        global_attr="
124
            graph_title ZFS ARC - Activities
125
            graph_category fs
126
            graph_args --base 1000 --lower-limit 0
127
            graph_vlabel misses (-) / hits (+) per second
128
            graph_info ZFS ARC - Activities
129

    
130
            hits.negative misses
131
            l2_hits.negative l2_misses
132
        "
133
        data_attr="
134
            misses    DERIVE LINE dummy
135
            hits      DERIVE LINE ARC
136
            l2_misses DERIVE LINE dummy
137
            l2_hits   DERIVE LINE L2ARC
138
        "
139
        ;;
140
    actlist)
141
        global_attr="
142
            graph_title ZFS ARC - Activities by cache list
143
            graph_category fs
144
            graph_args --base 1000 --lower-limit 0
145
            graph_vlabel ghost hits (-) / hits (+) per second
146
            graph_info ZFS ARC - Activities by cache list
147

    
148
            mfu_hits.negative mfu_ghost_hits
149
            mru_hits.negative mru_ghost_hits
150
        "
151
        data_attr="
152
            mfu_ghost_hits DERIVE LINE dummy
153
            mfu_hits       DERIVE LINE MFU
154
            mru_ghost_hits DERIVE LINE dummy
155
            mru_hits       DERIVE LINE MRU
156
        "
157
        ;;
158
    actdata)
159
        global_attr="
160
            graph_title ZFS ARC - Activities by data type
161
            graph_category fs
162
            graph_args --base 1000 --lower-limit 0
163
            graph_vlabel misses (-) / hits (+) per second
164
            graph_info ZFS ARC - Activities by data type
165

    
166
            demand_data_hits.negative demand_data_misses
167
            demand_metadata_hits.negative demand_metadata_misses
168
            prefetch_data_hits.negative prefetch_data_misses
169
            prefetch_metadata_hits.negative prefetch_metadata_misses
170
        "
171
        data_attr="
172
            demand_data_misses       DERIVE LINE dummy
173
            demand_data_hits         DERIVE LINE D data
174
            demand_metadata_misses   DERIVE LINE dummy
175
            demand_metadata_hits     DERIVE LINE D meta
176
            prefetch_data_misses     DERIVE LINE dummy
177
            prefetch_data_hits       DERIVE LINE P data
178
            prefetch_metadata_misses DERIVE LINE dummy
179
            prefetch_metadata_hits   DERIVE LINE P meta
180
        "
181
        ;;
182
    hitratio)
183
        global_attr="
184
            graph_title ZFS ARC - Hit ratio
185
            graph_category fs
186
            graph_args --base 1000 --lower-limit 0 --upper-limit 100 --rigid
187
            graph_vlabel % hits
188
            graph_info ZFS ARC - Hit ratio - The graph shows cache hit ratio between munin-update intervals (usually 5 minutes).
189

    
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,*
196
        "
197
        data_attr="
198
            hits                       DERIVE LINE  dummy
199
            misses                     DERIVE LINE  dummy
200
            l2_hits                    DERIVE LINE  dummy
201
            l2_misses                  DERIVE LINE  dummy
202
            demand_data_hits           DERIVE LINE  dummy
203
            demand_data_misses         DERIVE LINE  dummy
204
            demand_metadata_hits       DERIVE LINE  dummy
205
            demand_metadata_misses     DERIVE LINE  dummy
206
            prefetch_data_hits         DERIVE LINE  dummy
207
            prefetch_data_misses       DERIVE LINE  dummy
208
            prefetch_metadata_hits     DERIVE LINE  dummy
209
            prefetch_metadata_misses   DERIVE LINE  dummy
210
            hitratio                   GAUGE  LINE2 ARC hits
211
            l2_hitratio                GAUGE  LINE  L2ARC hits
212
            demand_data_hitratio       GAUGE  LINE  Demand data hits
213
            demand_metadata_hitratio   GAUGE  LINE  Demand metadata hits
214
            prefetch_data_hitratio     GAUGE  LINE  Prefetch data hits
215
            prefetch_metadata_hitratio GAUGE  LINE  Prefetch metadata hits
216
        "
217
        ;;
218
    *)
219
        echo "Unknown function: $func"
220
        exit 1
221
        ;;
222
    esac
223
}
224

    
225
do_config() {
226
    local func=$1
227
    local label_max_length=45
228
    local field type draw label
229

    
230
    preconfig "$func"
231
    echo "multigraph ${plugin_name}_${func}"
232

    
233
    # print global attributes
234
    echo "$global_attr" | sed -e 's/^  *//' -e '/^$/d'
235

    
236
    # print data source attributes
237
    echo "$data_attr" | while read -r field type draw label
238
    do
239
        [ -z "$field" ] && continue
240

    
241
        echo "${field}.type ${type}"
242
        echo "${field}.draw ${draw}"
243
        echo "${field}.label ${label:0:${label_max_length}}"
244
        if [ "$type" = 'DERIVE' ]; then
245
            echo "${field}.min 0"
246
        fi
247
        if [ "$label" = 'dummy' ]; then
248
            echo "${field}.graph no"
249
        fi
250
    done
251

    
252
    echo
253
}
254

    
255
get_stats() {
256
    local arcstats stat value
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

    
288
    while read -r stat value
289
    do
290
        printf -v "arcstats_${stat}" "%s" "$value"
291
        # printf -v means indirect variable assignment (similar to eval)
292
    done <<< "$arcstats"
293
}
294

    
295
do_fetch() {
296
    local func=$1
297
    local field type draw label value ref
298

    
299
    preconfig "$func"
300
    echo "multigraph ${plugin_name}_${func}"
301

    
302
    echo "$data_attr" | while read -r field type draw label
303
    do
304
        [ -z "$field" ] && continue
305

    
306
        ref="arcstats_${field}"
307
        value=${!ref:-0}
308
        # ${!varname} means indirect evaluation (similar to eval)
309

    
310
        echo "${field}.value ${value}"
311
    done
312

    
313
    echo
314
}
315

    
316
autoconf() {
317
    if [ -x /sbin/zfs ]; then
318
        echo yes
319
    else
320
        echo "no (ZFS looks unavailable)"
321
    fi
322
}
323

    
324
config() {
325
    local func
326

    
327
    for func in $functions
328
    do
329
        do_config "$func"
330
    done
331
}
332

    
333
fetch() {
334
    local func
335

    
336
    get_stats
337

    
338
    for func in $functions
339
    do
340
        do_fetch "$func"
341
    done
342
}
343

    
344
# Main
345

    
346
osname=$( get_osname )
347

    
348
case ${1:-} in
349
autoconf)
350
    autoconf
351
    ;;
352
config)
353
    config
354
    if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi
355
    ;;
356
*)
357
    fetch
358
    ;;
359
esac
360

    
361
exit 0