2014-03-05 12:33:10 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2015-11-10 01:32:46 +01:00
|
|
|
# (c) 2015, Raphaël Droz <raphael.droz@gmail.com>
|
2014-03-05 12:33:10 +01:00
|
|
|
# (c) 2014, Gilles Fauvie <gfauvie@opendbteam.com>
|
|
|
|
# Based on the 'du_multidirs' plugin, written by Christian Kujau <lists@nerdbynature.de>
|
|
|
|
#
|
|
|
|
# Configure it by using the processes env var, i.e.:
|
|
|
|
#
|
2014-03-05 16:37:06 +01:00
|
|
|
# WARNING: SELINUX can block this plugin
|
|
|
|
#
|
2014-03-05 12:33:10 +01:00
|
|
|
# [proc_mem_by_user]
|
2014-03-05 16:37:06 +01:00
|
|
|
# env.users munin-node jprod
|
2014-03-05 12:33:10 +01:00
|
|
|
#
|
2015-11-10 01:32:46 +01:00
|
|
|
# see bug:
|
|
|
|
# http://munin-monitoring.org/ticket/921
|
|
|
|
# /usr/share/munin/plugins/plugin.sh (clean_fieldname())
|
2014-03-05 12:33:10 +01:00
|
|
|
|
2015-11-10 01:32:46 +01:00
|
|
|
. "$MUNIN_LIBDIR/plugins/plugin.sh"
|
|
|
|
users=${users:-munin-node}
|
2014-03-05 12:33:10 +01:00
|
|
|
|
|
|
|
|
2015-11-10 01:32:46 +01:00
|
|
|
if [ "$1" = autoconf ]; then
|
|
|
|
ok=1
|
|
|
|
[ -z "$users" ] && ok=0
|
|
|
|
|
|
|
|
for user in $users; do
|
|
|
|
ps u -U "$user" 1> /dev/null 2>&1 || ok=0
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $ok = 1 ]; then echo yes
|
|
|
|
else echo no; fi
|
|
|
|
exit 0
|
|
|
|
fi
|
2014-03-05 12:33:10 +01:00
|
|
|
|
2015-11-10 01:32:46 +01:00
|
|
|
if [ "$1" = config ]; then
|
|
|
|
cat <<EOF
|
|
|
|
graph_title Memory usage by process by user
|
|
|
|
graph_args --base 1024 -l 0
|
|
|
|
graph_vlabel Bytes
|
|
|
|
graph_category processes
|
|
|
|
graph_info This graph shows the memory usage of several processes of one user
|
|
|
|
graph_order $(echo "$users"|sed 's/\broot\b/__root/g')
|
|
|
|
EOF
|
2014-03-05 12:33:10 +01:00
|
|
|
|
2015-11-10 01:32:46 +01:00
|
|
|
for user in $users; do
|
|
|
|
munin_safe_name=$(clean_fieldname "$user")
|
|
|
|
cat<<EOF
|
|
|
|
$munin_safe_name.label $user
|
|
|
|
$munin_safe_name.info $user
|
|
|
|
$munin_safe_name.min 0
|
|
|
|
$munin_safe_name.draw LINESTACK2
|
|
|
|
$munin_safe_name.type GAUGE
|
|
|
|
EOF
|
|
|
|
done
|
2014-03-05 12:33:10 +01:00
|
|
|
|
2015-11-10 01:32:46 +01:00
|
|
|
# echo "$u".warning 0
|
|
|
|
# echo "$u".critical 0
|
2014-03-05 12:33:10 +01:00
|
|
|
|
2015-11-10 01:32:46 +01:00
|
|
|
exit 0
|
2014-03-05 12:33:10 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
for user in $users; do
|
2015-11-10 01:32:46 +01:00
|
|
|
munin_safe_name=$(clean_fieldname "$user")
|
|
|
|
sum=$(ps u -U "$user" | awk 'BEGIN { sum = 0 } NR > 1 { sum += $6 }; END { print sum * 1024 }')
|
|
|
|
echo "$munin_safe_name.value ${sum:-U}"
|
|
|
|
done
|