root / plugins / user / membyuser @ a1c4bcb2
Historique | Voir | Annoter | Télécharger (1,59 ko)
| 1 | ec285287 | Sebastien Campion | #!/bin/bash |
|---|---|---|---|
| 2 | # |
||
| 3 | 17f78427 | Lars Kruse | # Plugin to monitor Memory usage inspired by cpubyuser |
| 4 | # |
||
| 5 | a1c4bcb2 | pcy | # 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 | ec285287 | Sebastien Campion | |
| 10 | a1c4bcb2 | pcy | ## 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 | ec285287 | Sebastien Campion | |
| 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 | a1c4bcb2 | pcy | echo "graph_args --base 1024" |
| 29 | ec285287 | Sebastien Campion | echo "graph_title Memory usage, by user" |
| 30 | 4b400a73 | dipohl | echo "graph_category memory" |
| 31 | ec285287 | Sebastien Campion | echo "graph_info This graph shows memory usage, for monitored users." |
| 32 | a1c4bcb2 | pcy | echo "graph_vlabel Bytes" |
| 33 | ec285287 | Sebastien Campion | 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 | a1c4bcb2 | pcy | echo "${_USER}.draw AREASTACK"
|
| 43 | ec285287 | Sebastien Campion | done |
| 44 | exit |
||
| 45 | fi |
||
| 46 | |||
| 47 | a1c4bcb2 | pcy | ps -e -o rss,user | \ |
| 48 | ec285287 | Sebastien Campion | 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 | a1c4bcb2 | pcy | print _user".value", (MEM_USER[user] * 1024) |
| 58 | ec285287 | Sebastien Campion | } else |
| 59 | a1c4bcb2 | pcy | others_sum += (MEM_USER[user] * 1024) |
| 60 | ec285287 | Sebastien Campion | } |
| 61 | print "others.value", others_sum; |
||
| 62 | }' |
