2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

Fix for pull req #833

This commit is contained in:
K.Cima 2017-04-18 09:11:17 +09:00
parent 726abac461
commit 0670445765
4 changed files with 53 additions and 65 deletions

View File

@ -52,7 +52,7 @@ data_attr="
# Functions # Functions
autoconf() { autoconf() {
if [ -x "$( which kstat )" ]; then if which kstat >/dev/null ; then
echo yes echo yes
else else
echo "no (failed to find executable 'kstat')" echo "no (failed to find executable 'kstat')"
@ -63,16 +63,14 @@ config() {
local label_max_length=45 local label_max_length=45
# print global attributes # print global attributes
sed -e 's/^ *//' -e '/^$/d' <<< "${global_attr}" echo "$global_attr" | sed -e 's/^ *//' -e '/^$/d'
# print data source attributes # print data source attributes
# split line into field,type,draw,label # split line into field,type,draw,label
local fields field type draw label local field type draw label
fields= echo "$data_attr" | while read -r field type draw label
while read -r field type draw label
do do
[ -z "$field" ] && continue [ -z "$field" ] && continue
fields="${fields} ${field}"
echo "${field}.type ${type}" echo "${field}.type ${type}"
echo "${field}.draw ${draw}" echo "${field}.draw ${draw}"
@ -80,19 +78,17 @@ config() {
if [ "${type}" = DERIVE ]; then if [ "${type}" = DERIVE ]; then
echo "${field}.min 0" echo "${field}.min 0"
fi fi
done <<< "${data_attr}" done
echo graph_order "$fields"
} }
getvalue() { fetch() {
local field type draw label local field type draw label
while read -r field type draw label echo "$data_attr" | while read -r field type draw label
do do
[ -z "$field" ] && continue [ -z "$field" ] && continue
value=$( kstat -p "cpu::sys:${field}" | awk '{ sum += $2 } END { print sum }' ) value=$( kstat -p "cpu::sys:${field}" | awk '{ sum += $2 } END { print sum }' )
echo "${field}.value ${value}" echo "${field}.value ${value}"
done <<< "${data_attr}" done
} }
# Main # Main
@ -102,10 +98,10 @@ autoconf)
;; ;;
config) config)
config config
[ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && getvalue [ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
;; ;;
*) *)
getvalue fetch
;; ;;
esac esac

View File

@ -29,7 +29,7 @@
ln -s /path/to/munin/lib/plugins/fsstat_act_ fsstat_act_nfs4 ln -s /path/to/munin/lib/plugins/fsstat_act_ fsstat_act_nfs4
... ...
=head1 ENVIRONMET VARIABLES =head1 ENVIRONMENT VARIABLES
None None
@ -62,11 +62,11 @@ stat_regexp='/^(?!(class|crtime|snaptime|.*_bytes))/'
# Graph settings # Graph settings
global_attr=" global_attr="
graph_title File system statictics - Activities of ${fs_type^^} graph_title File system statictics - Activities of $( echo "$fs_type" | tr '[:lower:]' '[:upper:]' )
graph_category disk graph_category disk
graph_args --base 1000 graph_args --base 1000
graph_vlabel Counts per second graph_vlabel Counts per second
graph_info File system statictics - Activities of ${fs_type^^} graph_info File system statictics - Activities of $( echo "$fs_type" | tr '[:lower:]' '[:upper:]' )
" "
# Functions # Functions
@ -74,6 +74,8 @@ global_attr="
get_zone_id() { get_zone_id() {
local osver zonename zoneid local osver zonename zoneid
# Note: Solaris 11 fsstat supports statistics per zone. Solaris 10 does not.
zoneid=0 zoneid=0
osver=$( uname -r | cut -d. -f2 ) osver=$( uname -r | cut -d. -f2 )
@ -86,7 +88,7 @@ get_zone_id() {
} }
autoconf() { autoconf() {
if [ -x "$( which kstat )" ]; then if which kstat >/dev/null ; then
echo yes echo yes
else else
echo "no (failed to find executable 'kstat')" echo "no (failed to find executable 'kstat')"
@ -96,9 +98,9 @@ autoconf() {
suggest() { suggest() {
# Print file systems which look active # Print file systems which look active
kstat -p "unix:${zone_id}:${name_regexp}:/^(read_bytes|write_bytes)\$/" | \ kstat -p "unix:${zone_id}:${name_regexp}:/^(read_bytes|write_bytes)\$/" \
sed -e 's/vopstats_//' -e 's/:/ /g' | \ | sed -e 's/vopstats_//' -e 's/:/ /g' \
awk '{ | awk '{
sum[ $3 ] += $5 sum[ $3 ] += $5
} }
END { END {
@ -114,12 +116,12 @@ config() {
local stat local stat
# Print global attributes # Print global attributes
echo "${global_attr}" | sed -e 's/^ *//' -e '/^$/d' echo "$global_attr" | sed -e 's/^ *//' -e '/^$/d'
# Get stat names by kstat # Get stat names by kstat
kstat -p "unix:${zone_id}:vopstats_${fs_type}:${stat_regexp}" | \ kstat -p "unix:${zone_id}:vopstats_${fs_type}:${stat_regexp}" \
sed -e 's/vopstats_//' -e 's/:/ /g' | awk '{ print $4 }' | sort -u | \ | sed -e 's/vopstats_//' -e 's/:/ /g' | awk '{ print $4 }' | sort \
while read -r stat | while read -r stat
do do
# Print data attributes # Print data attributes
echo "${stat}.label ${stat#n}" echo "${stat}.label ${stat#n}"
@ -127,11 +129,9 @@ config() {
echo "${stat}.type DERIVE" echo "${stat}.type DERIVE"
echo "${stat}.min 0" echo "${stat}.min 0"
done done
echo
} }
getvalue() { fetch() {
local stat value local stat value
# Get fs names, stat names and values by kstat # Get fs names, stat names and values by kstat
@ -142,14 +142,12 @@ getvalue() {
# unix:0:vopstats_hsfs:nread 407790 # unix:0:vopstats_hsfs:nread 407790
# ... # ...
kstat -p "unix:${zone_id}:vopstats_${fs_type}:${stat_regexp}" | \ kstat -p "unix:${zone_id}:vopstats_${fs_type}:${stat_regexp}" \
sed -e 's/vopstats_//' -e 's/:/ /g' | awk '{ print $4,$5 }' | \ | sed -e 's/vopstats_//' -e 's/:/ /g' | awk '{ print $4,$5 }' \
while read -r stat value | while read -r stat value
do do
echo "${stat}.value ${value}" echo "${stat}.value ${value}"
done done
echo
} }
# Main # Main
@ -165,10 +163,10 @@ suggest)
;; ;;
config) config)
config config
[ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && getvalue [ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
;; ;;
*) *)
getvalue fetch
;; ;;
esac esac

View File

@ -20,7 +20,7 @@
cd /path/to/munin/etc/plugins cd /path/to/munin/etc/plugins
ln -s /path/to/munin/lib/plugins/fsstat_bytes . ln -s /path/to/munin/lib/plugins/fsstat_bytes .
=head1 ENVIRONMET VARIABLES =head1 ENVIRONMENT VARIABLES
env.exclude - file system(s) to exclude seperated by white-space. env.exclude - file system(s) to exclude seperated by white-space.
example: env.exclude autofs example: env.exclude autofs
@ -82,6 +82,8 @@ is_excluded() {
get_zone_id() { get_zone_id() {
local osver zonename zoneid local osver zonename zoneid
# Note: Solaris 11 fsstat supports statistics per zone. Solaris 10 does not.
zoneid=0 zoneid=0
osver=$( uname -r | cut -d. -f2 ) osver=$( uname -r | cut -d. -f2 )
@ -94,7 +96,7 @@ get_zone_id() {
} }
autoconf() { autoconf() {
if [ -x "$( which kstat )" ]; then if which kstat >/dev/null ; then
echo yes echo yes
else else
echo "no (failed to find executable 'kstat')" echo "no (failed to find executable 'kstat')"
@ -105,12 +107,12 @@ config() {
local fs local fs
# Print global attributes # Print global attributes
echo "${global_attr}" | sed -e 's/^ *//' -e '/^$/d' echo "$global_attr" | sed -e 's/^ *//' -e '/^$/d'
# Get fs names by kstat # Get fs names by kstat
kstat -p "unix:${zone_id}:${name_regexp}:${data_in}" | \ kstat -p "unix:${zone_id}:${name_regexp}:${data_in}" \
sed -e 's/vopstats_//' -e 's/:/ /g' | awk '{ print $3 }' | sort -u | \ | sed -e 's/vopstats_//' -e 's/:/ /g' | awk '{ print $3 }' | sort \
while read -r fs | while read -r fs
do do
is_excluded "$fs" && continue is_excluded "$fs" && continue
@ -125,11 +127,9 @@ config() {
echo "${fs}_${data_in}.type DERIVE" echo "${fs}_${data_in}.type DERIVE"
echo "${fs}_${data_in}.min 0" echo "${fs}_${data_in}.min 0"
done done
echo
} }
getvalue() { fetch() {
local fs stat value local fs stat value
# Get fs names, stat names and values by kstat # Get fs names, stat names and values by kstat
@ -140,16 +140,14 @@ getvalue() {
# unix:0:vopstats_hsfs:nread 407790 # unix:0:vopstats_hsfs:nread 407790
# ... # ...
kstat -p "unix:${zone_id}:${name_regexp}:/^(${data_in}|${data_out})\$/" | \ kstat -p "unix:${zone_id}:${name_regexp}:/^(${data_in}|${data_out})\$/" \
sed -e 's/vopstats_//' -e 's/:/ /g' | awk '{ print $3,$4,$5 }' | \ | sed -e 's/vopstats_//' -e 's/:/ /g' | awk '{ print $3,$4,$5 }' \
while read -r fs stat value | while read -r fs stat value
do do
is_excluded "$fs" && continue is_excluded "$fs" && continue
echo "${fs}_${stat}.value ${value}" echo "${fs}_${stat}.value ${value}"
done done
echo
} }
# Main # Main
@ -162,10 +160,10 @@ autoconf)
;; ;;
config) config)
config config
[ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && getvalue [ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
;; ;;
*) *)
getvalue fetch
;; ;;
esac esac

View File

@ -64,7 +64,7 @@ data_attr="
# Functions # Functions
autoconf() { autoconf() {
if [ -x "$( which kstat )" ]; then if which kstat >/dev/null ; then
echo yes echo yes
else else
echo "no (failed to find executable 'kstat')" echo "no (failed to find executable 'kstat')"
@ -75,16 +75,14 @@ config() {
local label_max_length=45 local label_max_length=45
# print global attributes # print global attributes
sed -e 's/^ *//' -e '/^$/d' <<< "${global_attr}" echo "$global_attr" | sed -e 's/^ *//' -e '/^$/d'
# print data source attributes # print data source attributes
# split line into field,type,draw,label # split line into field,type,draw,label
local fields field type draw label local field type draw label
fields= echo "$data_attr" | while read -r field type draw label
while read -r field type draw label
do do
[ -z "$field" ] && continue [ -z "$field" ] && continue
fields="${fields} ${field}"
echo "${field}.type ${type}" echo "${field}.type ${type}"
echo "${field}.draw ${draw}" echo "${field}.draw ${draw}"
@ -92,14 +90,12 @@ config() {
if [ "${type}" = DERIVE ]; then if [ "${type}" = DERIVE ]; then
echo "${field}.min 0" echo "${field}.min 0"
fi fi
done <<< "${data_attr}" done
echo graph_order "$fields"
} }
getvalue() { fetch() {
local field type draw label local field type draw label
while read -r field type draw label echo "$data_attr" | while read -r field type draw label
do do
[ -z "$field" ] && continue [ -z "$field" ] && continue
@ -112,7 +108,7 @@ getvalue() {
value=$( kstat -p "cpu::sys:${field}" | awk '{ sum += $2 } END { print sum }' ) value=$( kstat -p "cpu::sys:${field}" | awk '{ sum += $2 } END { print sum }' )
echo "${field}.value ${value}" echo "${field}.value ${value}"
done <<< "${data_attr}" done
} }
# Main # Main
@ -122,10 +118,10 @@ autoconf)
;; ;;
config) config)
config config
[ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && getvalue [ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
;; ;;
*) *)
getvalue fetch
;; ;;
esac esac