root / plugins / system / cpubyuser @ e5ce7492
Historique | Voir | Annoter | Télécharger (2,13 ko)
| 1 | 3bd553cd | fireba11 | #!/bin/bash |
|---|---|---|---|
| 2 | # |
||
| 3 | # Plugin to monitor CPU usage, for a selected set of users |
||
| 4 | # |
||
| 5 | # Usage: Place in /etc/munin/node.d/ (or link it there using ln -s) |
||
| 6 | # Add this to your /etc/munin/plugin-conf.d/munin-node: |
||
| 7 | # [cpubyuser] |
||
| 8 | # env.USERS root yann |
||
| 9 | # |
||
| 10 | # root and yann being a list of the users to monitor. |
||
| 11 | # You need to also make sure that awk is installed |
||
| 12 | # |
||
| 13 | # 2008-12-08 v 1.3.1 Hanisch Elián: |
||
| 14 | # - support for dots in user names. |
||
| 15 | # - fix labels |
||
| 16 | # |
||
| 17 | # 2008-12-01 v 1.3 Hanisch Elián: |
||
| 18 | # - fixes, refactoring and code cleanup |
||
| 19 | # - Users that use cpu but aren't in the USERS env var |
||
| 20 | # are plotted as "others", set others.graph to 'no' if |
||
| 21 | # you don't want this. |
||
| 22 | # |
||
| 23 | # 2008-03-20 v 1.2 fireball: fixed minor screwup, works now ^^ |
||
| 24 | # |
||
| 25 | # 2008-01-09 v 1.1 fireball: fixed "-" in usernames, those get replaced by "_" now. |
||
| 26 | # set usernames in config accordingly (that is with _) |
||
| 27 | # |
||
| 28 | # |
||
| 29 | # Parameters understood: |
||
| 30 | # |
||
| 31 | # config (required) |
||
| 32 | # autoconf (optional - used by munin-config) |
||
| 33 | # |
||
| 34 | |||
| 35 | #%# family=auto |
||
| 36 | #%# capabilities=autoconf |
||
| 37 | |||
| 38 | if [ "$1" = "autoconf" ]; then |
||
| 39 | if [ -n "$USERS" ]; then |
||
| 40 | echo "yes" |
||
| 41 | else |
||
| 42 | echo "\$USERS not defined." |
||
| 43 | fi |
||
| 44 | exit |
||
| 45 | fi |
||
| 46 | |||
| 47 | if [ "$1" = "config" ]; then |
||
| 48 | echo "graph_args --base 1000 -r --lower-limit 0" |
||
| 49 | echo "graph_title CPU usage, by user" |
||
| 50 | echo "graph_category system" |
||
| 51 | echo "graph_info This graph shows CPU usage, for monitored users." |
||
| 52 | echo "graph_vlabel %" |
||
| 53 | echo "graph_scale no" |
||
| 54 | echo "graph_period second" |
||
| 55 | _USERS=${USERS//[-.]/_}
|
||
| 56 | echo "graph_order $_USERS others" |
||
| 57 | FIRSTUSER=1; |
||
| 58 | for USER in $USERS "others"; do |
||
| 59 | _USER=${USER//[-.]/_}
|
||
| 60 | echo "${_USER}.label $USER"
|
||
| 61 | echo "${_USER}.info CPU used by user $USER"
|
||
| 62 | echo "${_USER}.type GAUGE"
|
||
| 63 | if [ $FIRSTUSER -eq 1 ]; then |
||
| 64 | echo "${_USER}.draw AREA"
|
||
| 65 | FIRSTUSER=0 |
||
| 66 | else |
||
| 67 | echo "${_USER}.draw STACK"
|
||
| 68 | fi |
||
| 69 | done |
||
| 70 | exit |
||
| 71 | fi |
||
| 72 | |||
| 73 | ps -e -o "%C%U" | \ |
||
| 74 | awk -v USERS="$USERS" ' |
||
| 75 | { if ($2 != "USER") CPU_USER[$2]+=$1 }
|
||
| 76 | END {
|
||
| 77 | others_sum = 0 |
||
| 78 | for (user in CPU_USER) {
|
||
| 79 | m = match(USERS,user) |
||
| 80 | if (m != 0) {
|
||
| 81 | _user=user |
||
| 82 | gsub(/[-.]/,"_", _user); |
||
| 83 | print _user".value", CPU_USER[user] |
||
| 84 | } else |
||
| 85 | others_sum += CPU_USER[user] |
||
| 86 | } |
||
| 87 | print "others.value", others_sum; |
||
| 88 | }' |
