root / plugins / user / membyuser @ a1c4bcb2
Historique | Voir | Annoter | Télécharger (1,59 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
# |
| 3 |
# Plugin to monitor Memory usage inspired by cpubyuser |
| 4 |
# |
| 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! |
| 9 |
|
| 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$')" |
| 17 |
|
| 18 |
if [ "$1" = "autoconf" ]; then |
| 19 |
if [ -n "$USERS" ]; then |
| 20 |
echo "yes" |
| 21 |
else |
| 22 |
echo "\$USERS not defined." |
| 23 |
fi |
| 24 |
exit |
| 25 |
fi |
| 26 |
|
| 27 |
if [ "$1" = "config" ]; then |
| 28 |
echo "graph_args --base 1024" |
| 29 |
echo "graph_title Memory usage, by user" |
| 30 |
echo "graph_category memory" |
| 31 |
echo "graph_info This graph shows memory usage, for monitored users." |
| 32 |
echo "graph_vlabel Bytes" |
| 33 |
echo "graph_period second" |
| 34 |
_USERS=${USERS//[-.]/_}
|
| 35 |
echo "graph_order $_USERS others" |
| 36 |
FIRSTUSER=1; |
| 37 |
for USER in $USERS "others"; do |
| 38 |
_USER=${USER//[-.]/_}
|
| 39 |
echo "${_USER}.label $USER"
|
| 40 |
echo "${_USER}.info Memory used by user $USER"
|
| 41 |
echo "${_USER}.type GAUGE"
|
| 42 |
echo "${_USER}.draw AREASTACK"
|
| 43 |
done |
| 44 |
exit |
| 45 |
fi |
| 46 |
|
| 47 |
ps -e -o rss,user | \ |
| 48 |
awk -v USERS="$USERS" ' |
| 49 |
{ if ($2 != "USER") MEM_USER[$2]+=$1 }
|
| 50 |
END {
|
| 51 |
others_sum = 0 |
| 52 |
for (user in MEM_USER) {
|
| 53 |
m = match(USERS,user) |
| 54 |
if (m != 0) {
|
| 55 |
_user=user |
| 56 |
gsub(/[-.]/,"_", _user); |
| 57 |
print _user".value", (MEM_USER[user] * 1024) |
| 58 |
} else |
| 59 |
others_sum += (MEM_USER[user] * 1024) |
| 60 |
} |
| 61 |
print "others.value", others_sum; |
| 62 |
}' |
