Projet

Général

Profil

Révision b077ad21

IDb077ad21e4585475e698b2b1cff10542044374eb
Parent d2847dc5
Enfant b194c867

Ajouté par Petteri Valkonen il y a plus de 11 ans

Add plugin for monitoring HDD power state on FreeBSD

Voir les différences:

plugins/disk/freebsd_hdd_power_state
1
#!/bin/sh
2
#
3
# Plugin to monitor the power state of hard disk drives on FreeBSD.
4
#
5
# Configure the plugin to run as root by adding the following to
6
# /usr/local/etc/munin/plugin-conf.d/plugins.conf:
7
#
8
# [freebsd_hdd_power_state]
9
# user root
10
#
11
# You can also specify the monitored devices using the 'env.devices'
12
# environment variable, if autoconfiguration doesn't work for you:
13
#
14
# env.devices ada0 ada1 ada2 ada3 ada4 ada5 ada6 ada7
15
#
16
# Copyright (c) 2014, Petteri Valkonen <petteri.valkonen@iki.fi>
17
#
18
# Redistribution and use in source and binary forms, with or without
19
# modification, are permitted provided that the following conditions are met:
20
#     * Redistributions of source code must retain the above copyright
21
#       notice, this list of conditions and the following disclaimer.
22
#     * Redistributions in binary form must reproduce the above copyright
23
#       notice, this list of conditions and the following disclaimer in the
24
#       documentation and/or other materials provided with the distribution.
25
#     * Neither the name of the copyright holder nor the
26
#       names of its contributors may be used to endorse or promote products
27
#       derived from this software without specific prior written permission.
28
#
29
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
30
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
33
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
#
40
#%# family=auto contrib
41
#%# capabilities=autoconf
42

  
43
DEVICES=${devices:-$(iostat -x | tail -n +3 | egrep -o '^a?da[0-9]+')}
44

  
45
case $1 in
46
    config)
47
        cat <<EOM
48
multigraph $(basename $0)
49
graph_title HDD power state
50
graph_vlabel Power state
51
graph_args --upper-limit 1 -l 0
52
graph_scale no
53
graph_category disk
54
graph_info The power state of the hard disk drives on the system (1 is spun up, 0 is idle/standby).
55
EOM
56
        echo $DEVICES | awk 'BEGIN{OFS=""} { for (i = 0; i++ < NF;) print "power", i, ".label ", $i }'
57
        exit 0;;
58
    autoconf)
59
	if [ -z "$DEVICES" ] ; then
60
            echo "no (no devices found)"
61
	else
62
            echo yes
63
        fi
64
        exit 0;;
65
esac
66

  
67
INDEX=1
68
set -- $DEVICES
69
for DEVICE in $@ ; do
70
    STATE=$(camcontrol cmd $DEVICE -a "E5 00 00 00 00 00 00 00 00 00 00 00" -r - 2>/dev/null | awk '{print $10}')
71
    if [ -z "$STATE" ] ; then
72
        VALUE="-1"
73
    else
74
        VALUE=$(echo "$(echo "ibase=16; $STATE" | bc) / 255" | bc)
75
    fi
76
    printf "power%d.value %d\n" $INDEX $VALUE
77
    INDEX=$(expr $INDEX + 1)
78
done

Formats disponibles : Unified diff