Projet

Général

Profil

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

root / plugins / solaris / fsstat_bytes @ 17f78427

Historique | Voir | Annoter | Télécharger (3,47 ko)

1
#!/bin/bash
2

    
3
: << =cut
4

    
5
=head1 NAME
6

    
7
  fsstat_bytes - Munin plugin to monitor Solaris file system statistics
8

    
9
  Tested with Solaris 10 and 11.
10

    
11
  Note:
12
    In Solaris 11, fsstat command can get stats for each non-global zones in
13
    global zone. (see man fsstat)
14
    In global zone, this plugin gets stats of only global zone.
15
    In non-global zones, this plugin reports stats of the non-global zones.
16

    
17
=head1 CONFIGURATION
18

    
19
  Make symlink:
20
    cd /path/to/munin/etc/plugins
21
    ln -s /path/to/munin/lib/plugins/fsstat_bytes .
22

    
23
=head1 ENVIRONMENT VARIABLES
24

    
25
  env.exclude - file system(s) to exclude seperated by white-space.
26
    example:  env.exclude  autofs
27
    default:  none
28

    
29
=head1 AUTHOR
30

    
31
  K.Cima https://github.com/shakemid
32

    
33
=head1 LICENSE
34

    
35
  GPLv2
36

    
37
=head1 Magic markers
38

    
39
  #%# family=contrib
40
  #%# capabilities=autoconf
41

    
42
=cut
43

    
44
# Include plugin.sh
45
. "${MUNIN_LIBDIR:-}/plugins/plugin.sh"
46

    
47
# Shell options
48
set -o nounset  # Like perl use strict;
49

    
50
# Set environment variables
51
name_regexp='/^vopstats_(?![0-9a-f]{7})[a-z]/'  # data source of fsstat
52
: "${exclude:=}"
53

    
54
# Set graph settings
55
global_attr="
56
    graph_title File system statictics - I/O throughput
57
    graph_category disk
58
    graph_args --base 1024
59
    graph_vlabel Bytes per second write (-) / read (+)
60
    graph_info File system statictics - I/O throughput
61
"
62
data_in=read_bytes
63
data_out=write_bytes
64

    
65

    
66
# Functions
67

    
68
is_excluded() {
69
    local arg i
70
    arg=$1
71

    
72
    for i in ${exclude}
73
    do
74
        if [ "$arg" = "$i" ]; then
75
            return 0
76
        fi
77
    done
78

    
79
    return 1
80
}
81

    
82
get_zone_id() {
83
    local osver zonename zoneid
84

    
85
    # Note: Solaris 11 fsstat supports statistics per zone. Solaris 10 does not.
86

    
87
    zoneid=0
88
    osver=$( uname -r | cut -d. -f2 )
89

    
90
    if [ "$osver" -ge 11 ]; then
91
        zonename=$( zonename )
92
        zoneid=$( /usr/sbin/zoneadm list -p | awk -F: '$2 == "'"$zonename"'" { print $1 }' )
93
    fi
94

    
95
    echo "$zoneid"
96
}
97

    
98
autoconf() {
99
    if which kstat >/dev/null ; then
100
        echo yes
101
    else
102
        echo "no (failed to find executable 'kstat')"
103
    fi
104
}
105

    
106
config() {
107
    local fs
108

    
109
    # Print global attributes
110
    echo "$global_attr" | sed -e 's/^  *//' -e '/^$/d'
111

    
112
    # Get fs names by kstat
113
    kstat -p "unix:${zone_id}:${name_regexp}:${data_in}" \
114
    | sed -e 's/vopstats_//' -e 's/:/ /g' | awk '{ print $3 }' | sort \
115
    | while read -r fs
116
    do
117
        is_excluded "$fs" && continue
118

    
119
        # Print data attributes
120
        echo "${fs}_${data_out}.label dummy"
121
        echo "${fs}_${data_out}.graph no"
122
        echo "${fs}_${data_out}.type DERIVE"
123
        echo "${fs}_${data_out}.min 0"
124

    
125
        echo "${fs}_${data_in}.label ${fs}"
126
        echo "${fs}_${data_in}.negative ${fs}_${data_out}"
127
        echo "${fs}_${data_in}.type DERIVE"
128
        echo "${fs}_${data_in}.min 0"
129
    done
130
}
131

    
132
fetch() {
133
    local fs stat value
134

    
135
    # Get fs names, stat names and values by kstat
136

    
137
    # kstat output example:
138
    #  $ kstat -p 'unix::/^vopstats_[a-z]/:nread'
139
    #  unix:0:vopstats_autofs:nread    2
140
    #  unix:0:vopstats_hsfs:nread      407790
141
    #  ...
142

    
143
    kstat -p "unix:${zone_id}:${name_regexp}:/^(${data_in}|${data_out})\$/" \
144
    | sed -e 's/vopstats_//' -e 's/:/ /g' | awk '{ print $3,$4,$5 }' \
145
    | while read -r fs stat value
146
    do
147
        is_excluded "$fs" && continue
148

    
149
        echo "${fs}_${stat}.value ${value}"
150
    done
151
}
152

    
153
# Main
154

    
155
zone_id=$( get_zone_id )
156

    
157
case ${1:-} in
158
autoconf)
159
    autoconf
160
    ;;
161
config)
162
    config
163
    if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi
164
    ;;
165
*)
166
    fetch
167
    ;;
168
esac
169

    
170
exit 0