2
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/solaris/forks
Lars Kruse c81c20ab3b unify DIRTYCONFIG handling in shell and python plugins
The following issues were fixed:
* comparison too broad (e.g. "0" misinterpreted as "true")
* python: comparing string with number (is never equal in python)
* unwanted non-zero exitcode (compound command "&&" as last command in
  shell code block (e.g. "case" or "if" branch))
* access to unset variable (shell style issue)
2018-04-07 02:17:06 +02:00

108 lines
2 KiB
Bash
Executable file

#!/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() {
if which kstat >/dev/null ; then
echo yes
else
echo "no (failed to find executable 'kstat')"
fi
}
config() {
local label_max_length=45
# print global attributes
echo "$global_attr" | sed -e 's/^ *//' -e '/^$/d'
# print data source attributes
# split line into field,type,draw,label
local field type draw label
echo "$data_attr" | while read -r field type draw label
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
done
}
fetch() {
local field type draw label
echo "$data_attr" | while read -r field type draw label
do
[ -z "$field" ] && continue
value=$( kstat -p "cpu::sys:${field}" | awk '{ sum += $2 } END { print sum }' )
echo "${field}.value ${value}"
done
}
# Main
case ${1:-} in
autoconf)
autoconf
;;
config)
config
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi
;;
*)
fetch
;;
esac
exit 0