Révision a1c4bcb2
[plugins/user/membyuser] Minor enhancements
Don't use a fixed scale
Use resident set size as measure for a process' memory usage instead
of vsz
More robust username enumeration
| plugins/user/membyuser | ||
|---|---|---|
| 2 | 2 |
# |
| 3 | 3 |
# Plugin to monitor Memory usage inspired by cpubyuser |
| 4 | 4 |
# |
| 5 |
# 2012-05-23 Sebastien Campion |
|
| 5 |
# Usage: Place in /etc/munin/plugins/ (or link it there using ln -s) |
|
| 6 |
# Add this to your /etc/munin/plugin-conf.d/munin-node: |
|
| 7 |
# [membyuser] |
|
| 8 |
# user root # required if /proc can't be read from by any user! |
|
| 6 | 9 |
|
| 7 |
LU=`ps auh | cut -d' ' -f 1 | sort -u` |
|
| 8 |
USERS=`echo $LU` |
|
| 10 |
## 2012-05-23 Sebastien Campion |
|
| 11 |
# changed on 2019-08-30 by pcy <pcy@ulyssis.org>: |
|
| 12 |
# - change category from 'memory' to 'system' (so it appears next to cpubyuser) |
|
| 13 |
# - use rss instead of vsz |
|
| 14 |
# - more robust username enumeration |
|
| 15 |
|
|
| 16 |
USERS="$(ps ax --format uname | tail +2 | sort -u | grep -v -e '^root$')" |
|
| 9 | 17 |
|
| 10 | 18 |
if [ "$1" = "autoconf" ]; then |
| 11 | 19 |
if [ -n "$USERS" ]; then |
| ... | ... | |
| 17 | 25 |
fi |
| 18 | 26 |
|
| 19 | 27 |
if [ "$1" = "config" ]; then |
| 20 |
echo "graph_args --base 1000 -r --lower-limit 0"
|
|
| 28 |
echo "graph_args --base 1024"
|
|
| 21 | 29 |
echo "graph_title Memory usage, by user" |
| 22 | 30 |
echo "graph_category memory" |
| 23 | 31 |
echo "graph_info This graph shows memory usage, for monitored users." |
| 24 |
echo "graph_vlabel KB" |
|
| 25 |
echo "graph_scale no" |
|
| 32 |
echo "graph_vlabel Bytes" |
|
| 26 | 33 |
echo "graph_period second" |
| 27 | 34 |
_USERS=${USERS//[-.]/_}
|
| 28 | 35 |
echo "graph_order $_USERS others" |
| ... | ... | |
| 32 | 39 |
echo "${_USER}.label $USER"
|
| 33 | 40 |
echo "${_USER}.info Memory used by user $USER"
|
| 34 | 41 |
echo "${_USER}.type GAUGE"
|
| 35 |
if [ $FIRSTUSER -eq 1 ]; then |
|
| 36 |
echo "${_USER}.draw AREA"
|
|
| 37 |
FIRSTUSER=0 |
|
| 38 |
else |
|
| 39 |
echo "${_USER}.draw STACK"
|
|
| 40 |
fi |
|
| 42 |
echo "${_USER}.draw AREASTACK"
|
|
| 41 | 43 |
done |
| 42 | 44 |
exit |
| 43 | 45 |
fi |
| 44 | 46 |
|
| 45 |
ps -e -o "%z%U" | \
|
|
| 47 |
ps -e -o rss,user | \
|
|
| 46 | 48 |
awk -v USERS="$USERS" ' |
| 47 | 49 |
{ if ($2 != "USER") MEM_USER[$2]+=$1 }
|
| 48 | 50 |
END {
|
| ... | ... | |
| 52 | 54 |
if (m != 0) {
|
| 53 | 55 |
_user=user |
| 54 | 56 |
gsub(/[-.]/,"_", _user); |
| 55 |
print _user".value", MEM_USER[user]
|
|
| 57 |
print _user".value", (MEM_USER[user] * 1024)
|
|
| 56 | 58 |
} else |
| 57 |
others_sum += MEM_USER[user]
|
|
| 59 |
others_sum += (MEM_USER[user] * 1024)
|
|
| 58 | 60 |
} |
| 59 | 61 |
print "others.value", others_sum; |
| 60 | 62 |
}' |
Formats disponibles : Unified diff