2017-04-16 14:58:21 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
: << =cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
forks - Munin plugin to monitor Solaris fork and exec rate
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
Make symlink:
|
|
|
|
cd /path/to/munin/etc/plugins
|
|
|
|
ln -s /path/to/munin/lib/plugins/forks .
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
K.Cima https://github.com/shakemid
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
GPLv2
|
|
|
|
|
|
|
|
=head1 Magic markers
|
|
|
|
|
|
|
|
#%# family=contrib
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
# Include plugin.sh
|
|
|
|
. "${MUNIN_LIBDIR:-}/plugins/plugin.sh"
|
|
|
|
|
|
|
|
# Shell options
|
|
|
|
set -o nounset # Like perl use strict;
|
|
|
|
|
|
|
|
# Graph settings
|
|
|
|
global_attr="
|
|
|
|
graph_title Fork and exec rate
|
|
|
|
graph_category processes
|
|
|
|
graph_args --base 1000 --lower-limit 0 --rigid
|
|
|
|
graph_vlabel count per second
|
|
|
|
graph_info Fork and exec rate
|
|
|
|
"
|
|
|
|
# data_attr format: field type draw label
|
|
|
|
# label can contain white-spaces.
|
|
|
|
data_attr="
|
|
|
|
sysfork DERIVE LINE fork
|
|
|
|
sysvfork DERIVE LINE vfork
|
|
|
|
sysexec DERIVE LINE exec
|
|
|
|
"
|
|
|
|
|
|
|
|
# Functions
|
|
|
|
|
|
|
|
autoconf() {
|
2017-04-18 02:11:17 +02:00
|
|
|
if which kstat >/dev/null ; then
|
2017-04-16 14:58:21 +02:00
|
|
|
echo yes
|
|
|
|
else
|
|
|
|
echo "no (failed to find executable 'kstat')"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
config() {
|
|
|
|
local label_max_length=45
|
|
|
|
|
|
|
|
# print global attributes
|
2017-04-18 02:11:17 +02:00
|
|
|
echo "$global_attr" | sed -e 's/^ *//' -e '/^$/d'
|
2017-04-16 14:58:21 +02:00
|
|
|
|
|
|
|
# print data source attributes
|
|
|
|
# split line into field,type,draw,label
|
2017-04-18 02:11:17 +02:00
|
|
|
local field type draw label
|
|
|
|
echo "$data_attr" | while read -r field type draw label
|
2017-04-16 14:58:21 +02:00
|
|
|
do
|
|
|
|
[ -z "$field" ] && continue
|
|
|
|
|
|
|
|
echo "${field}.type ${type}"
|
|
|
|
echo "${field}.draw ${draw}"
|
|
|
|
echo "${field}.label ${label:0:${label_max_length}}"
|
|
|
|
if [ "${type}" = DERIVE ]; then
|
|
|
|
echo "${field}.min 0"
|
|
|
|
fi
|
2017-04-18 02:11:17 +02:00
|
|
|
done
|
2017-04-16 14:58:21 +02:00
|
|
|
}
|
|
|
|
|
2017-04-18 02:11:17 +02:00
|
|
|
fetch() {
|
2017-04-16 14:58:21 +02:00
|
|
|
local field type draw label
|
2017-04-18 02:11:17 +02:00
|
|
|
echo "$data_attr" | while read -r field type draw label
|
2017-04-16 14:58:21 +02:00
|
|
|
do
|
|
|
|
[ -z "$field" ] && continue
|
|
|
|
value=$( kstat -p "cpu::sys:${field}" | awk '{ sum += $2 } END { print sum }' )
|
|
|
|
echo "${field}.value ${value}"
|
2017-04-18 02:11:17 +02:00
|
|
|
done
|
2017-04-16 14:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Main
|
|
|
|
case ${1:-} in
|
|
|
|
autoconf)
|
|
|
|
autoconf
|
|
|
|
;;
|
|
|
|
config)
|
|
|
|
config
|
2017-04-18 02:11:17 +02:00
|
|
|
[ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
|
2017-04-16 14:58:21 +02:00
|
|
|
;;
|
|
|
|
*)
|
2017-04-18 02:11:17 +02:00
|
|
|
fetch
|
2017-04-16 14:58:21 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|