root / plugins / processes / proc_mem_by_user @ 4b400a73
Historique | Voir | Annoter | Télécharger (1,55 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
# |
| 3 |
# (c) 2015, Raphaël Droz <raphael.droz@gmail.com> |
| 4 |
# (c) 2014, Gilles Fauvie <gfauvie@opendbteam.com> |
| 5 |
# Based on the 'du_multidirs' plugin, written by Christian Kujau <lists@nerdbynature.de> |
| 6 |
# |
| 7 |
# Configure it by using the processes env var, i.e.: |
| 8 |
# |
| 9 |
# WARNING: SELINUX can block this plugin |
| 10 |
# |
| 11 |
# [proc_mem_by_user] |
| 12 |
# env.users munin-node jprod |
| 13 |
# |
| 14 |
# see bug: |
| 15 |
# http://munin-monitoring.org/ticket/921 |
| 16 |
# /usr/share/munin/plugins/plugin.sh (clean_fieldname()) |
| 17 |
|
| 18 |
. "$MUNIN_LIBDIR/plugins/plugin.sh" |
| 19 |
users=${users:-munin-node}
|
| 20 |
|
| 21 |
|
| 22 |
if [ "$1" = autoconf ]; then |
| 23 |
ok=1 |
| 24 |
[ -z "$users" ] && ok=0 |
| 25 |
|
| 26 |
for user in $users; do |
| 27 |
ps u -U "$user" 1> /dev/null 2>&1 || ok=0 |
| 28 |
done |
| 29 |
|
| 30 |
if [ $ok = 1 ]; then echo yes |
| 31 |
else echo no; fi |
| 32 |
exit 0 |
| 33 |
fi |
| 34 |
|
| 35 |
if [ "$1" = config ]; then |
| 36 |
cat <<EOF |
| 37 |
graph_title Memory usage by process by user |
| 38 |
graph_args --base 1024 -l 0 |
| 39 |
graph_vlabel Bytes |
| 40 |
graph_category memory |
| 41 |
graph_info This graph shows the memory usage of several processes of one user |
| 42 |
graph_order $(echo "$users"|sed 's/\broot\b/__root/g') |
| 43 |
EOF |
| 44 |
|
| 45 |
for user in $users; do |
| 46 |
munin_safe_name=$(clean_fieldname "$user") |
| 47 |
cat<<EOF |
| 48 |
$munin_safe_name.label $user |
| 49 |
$munin_safe_name.info $user |
| 50 |
$munin_safe_name.min 0 |
| 51 |
$munin_safe_name.draw LINESTACK2 |
| 52 |
$munin_safe_name.type GAUGE |
| 53 |
EOF |
| 54 |
done |
| 55 |
|
| 56 |
# echo "$u".warning 0 |
| 57 |
# echo "$u".critical 0 |
| 58 |
|
| 59 |
exit 0 |
| 60 |
fi |
| 61 |
|
| 62 |
for user in $users; do |
| 63 |
munin_safe_name=$(clean_fieldname "$user") |
| 64 |
sum=$(ps u -U "$user" | awk 'BEGIN { sum = 0 } NR > 1 { sum += $6 }; END { print sum * 1024 }')
|
| 65 |
echo "$munin_safe_name.value ${sum:-U}"
|
| 66 |
done |
