root / plugins / other / vserver_resources @ 08b6b881
Historique | Voir | Annoter | Télécharger (10,5 ko)
| 1 | 354fbdf7 | Micah Anderson and Holger Levsen | #!/bin/sh |
|---|---|---|---|
| 2 | # |
||
| 3 | # Copyright (C) 2006-2008 Holger Levsen, Micah Anderson |
||
| 4 | # |
||
| 5 | # This program is free software; you can redistribute it and/or |
||
| 6 | # modify it under the terms of the GNU General Public License |
||
| 7 | # as published by the Free Software Foundation; version 2 dated June, |
||
| 8 | # 1991. |
||
| 9 | # |
||
| 10 | # This program is distributed in the hope that it will be useful, |
||
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 13 | # GNU General Public License for more details. |
||
| 14 | # |
||
| 15 | # You should have received a copy of the GNU General Public License |
||
| 16 | # along with this program; if not, write to the Free Software |
||
| 17 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
||
| 18 | |||
| 19 | # Graph Vserver resource usage and limits |
||
| 20 | # |
||
| 21 | # Configuration variables |
||
| 22 | # vservers - specify the vservers to include in the graph (default: all) |
||
| 23 | # resource - specify the resource to be monitored (no default) |
||
| 24 | # limits - if true, turn on limit graphing (default: false) |
||
| 25 | # |
||
| 26 | # NOTE: If no configuration variables are set, the defaults will be used |
||
| 27 | |||
| 28 | # Example /etc/munin/plugin-conf.d/munin-node |
||
| 29 | # |
||
| 30 | # The following monitors the RSS value for the vservers named |
||
| 31 | # "vserver1 vserver2 vserver3 vserver4" and looks to see if the |
||
| 32 | # resource limit has been breached, if so it sends a message to nagios |
||
| 33 | # via send_nsca, and sends an email to notify that this has happened: |
||
| 34 | # |
||
| 35 | # [vserver_resources] |
||
| 36 | # user root |
||
| 37 | # env.vservers vserver1 vserver2 vserver3 vserver4 |
||
| 38 | # env.resource RSS |
||
| 39 | # env.limits 1 |
||
| 40 | # contacts nagios email |
||
| 41 | # contact.nagios.command /usr/bin/send_nsca -H your.nagios-host.here -c /etc/send_nsca.cfg |
||
| 42 | # contact.email.command mail -s "Munin-notification for ${var:group} :: ${var:host}" your@email.address.here
|
||
| 43 | # |
||
| 44 | # This second example monitors the VM value for all vservers on the system and |
||
| 45 | # has no limit notifications turned on: |
||
| 46 | # |
||
| 47 | # [vserver_resources] |
||
| 48 | # user root |
||
| 49 | # env.vservers vserver5 vserver6 vserver7 |
||
| 50 | # env.resource VM |
||
| 51 | # env.limits 0 |
||
| 52 | # |
||
| 53 | # This last example monitors all the resources for vserver5. Note that |
||
| 54 | # this will be a busy graph, and it would be really useless if you |
||
| 55 | # specified more than one vserver when the resource is set to ALL: |
||
| 56 | # |
||
| 57 | # [vserver_resources] |
||
| 58 | # user root |
||
| 59 | # env.vservers vserver5 |
||
| 60 | # env.resource ALL |
||
| 61 | # env.limits 0 |
||
| 62 | |||
| 63 | # Possible values for env.resource are: |
||
| 64 | # |
||
| 65 | # ALL - all the below resources |
||
| 66 | # PROC - number of processes |
||
| 67 | # VM - sum of all virtual pages inside the guest |
||
| 68 | # VML - sum of all virtual pages locked into memory |
||
| 69 | # RSS - number of pages currently present in RAM |
||
| 70 | # ANON - number of anonymous memory pages |
||
| 71 | # FILES - number of open files |
||
| 72 | # OFD |
||
| 73 | # LOCKS |
||
| 74 | # SOCK |
||
| 75 | # MSGQ |
||
| 76 | # SHM - number of shared memory pages |
||
| 77 | |||
| 78 | # Changelog |
||
| 79 | # version 0.1 - 2006 April xx |
||
| 80 | # Holger Levsen <debian@layer-acht.org> |
||
| 81 | # - initial author |
||
| 82 | # version 0.2 - 2006 April 24 |
||
| 83 | # Micah Anderson <micah@riseup.net> |
||
| 84 | # - Add dynamic arch page size determination |
||
| 85 | # - Some cleanup and clarification |
||
| 86 | # version 0.3 - 2006 May 3 |
||
| 87 | # Micah Anderson <micah@riseup.net> |
||
| 88 | # - Add ability to group vservers via environment vars |
||
| 89 | # - Fix missing close quotes and standardize indents |
||
| 90 | # - Add limit notification |
||
| 91 | # - Update documentation to include info on groups and limits |
||
| 92 | # version 0.4 - 2006 Jun 22 |
||
| 93 | # Micah Anderson <micah@riseup.net> |
||
| 94 | # - Fix error that results if NodeName is set to include a domain name |
||
| 95 | # version 0.5 - 2006 Oct |
||
| 96 | # Micah Anderson <micah@riseup.net> |
||
| 97 | # - fixed changelog entries so more changes can happen per version |
||
| 98 | # - standardized changelog date and name format |
||
| 99 | # - added myself to copyright |
||
| 100 | # - standardized indentation |
||
| 101 | # - abstracted from just RSS to be usable for any resource specified |
||
| 102 | # Holger Levsen <debian@layer-acht.org> |
||
| 103 | # - Fix hypens in NodeNames, replace them with underscores |
||
| 104 | # - Fix the fix from version 0.4 |
||
| 105 | # - allow specifying the ressource by linking |
||
| 106 | # (ln -s vserver_resources vserver_VM) |
||
| 107 | # - provided info about all resources |
||
| 108 | # - code cleaned |
||
| 109 | # - errors if an invalid resource is specified |
||
| 110 | # - handle identical vserver-names by using the vserver-id internally |
||
| 111 | # version 0.6 - 2007 Oct |
||
| 112 | # Micah Anderson <micah@riseup.net> |
||
| 113 | # - removed BASENAME - plugin isn't a wildcard plugin any longer |
||
| 114 | # - added $NAMELOC - fixes plugin so it works with VCI_SPACES (> 2.6.19) as well as older version |
||
| 115 | # |
||
| 116 | # TODO: |
||
| 117 | # - make it so you can specify more than one resource to be graphed? |
||
| 118 | # or define combined ressource-display: VM+RSS+ANON+SHM and FILES+OFD+LOCK+SOCK |
||
| 119 | # (for one vserver only) |
||
| 120 | # - and/or make it so you can graph all resources for one vserver |
||
| 121 | # - set a default for the resource if it is unset? |
||
| 122 | # - use /proc less often (100 times more overhead than talking to the kernel directly) |
||
| 123 | # i.e. use something like pagesize=`perl -MPOSIX -e 'print POSIX::sysconf(_SC_PAGESIZE), "\n";'` |
||
| 124 | # - ALL resource is broken |
||
| 125 | |||
| 126 | VSERVERS="$vservers" |
||
| 127 | LIMITS="$limits" |
||
| 128 | RESOURCE="$resource" |
||
| 129 | |||
| 130 | INFO=(`sed 's/.*:\t//' /proc/virtual/info 2>/dev/null || echo '<none>'`) |
||
| 131 | KCIN="$[ 16#${INFO[2]} ]";
|
||
| 132 | |||
| 133 | # If this is 1, then VCI_SPACES is present in the kernel (new in 2.6.19) |
||
| 134 | if [ $[ (KCIN >> 10) & 1 ] -eq 1 ] |
||
| 135 | then |
||
| 136 | NAMELOC="nsproxy" |
||
| 137 | else |
||
| 138 | NAMELOC="cvirt" |
||
| 139 | fi |
||
| 140 | |||
| 141 | if [ -z "$VSERVERS" ] ; then |
||
| 142 | XIDS=`find /proc/virtual/* -type d -exec basename {} \;`
|
||
| 143 | else |
||
| 144 | # it's really more performant to specify vservers by ids or not at all |
||
| 145 | XIDS="" |
||
| 146 | for i in $VSERVERS ; do |
||
| 147 | if [ -d /proc/virtual/$i ] ; then |
||
| 148 | XIDS="${XIDS}${i} "
|
||
| 149 | else |
||
| 150 | for j in `find /proc/virtual/* -type d -exec basename {} \;` ; do
|
||
| 151 | if [ "$i" = "`cat /proc/virtual/$j/$NAMELOC |grep NodeName |cut -f2`" ] ; then |
||
| 152 | XIDS="${XIDS}${j} "
|
||
| 153 | fi |
||
| 154 | done |
||
| 155 | fi |
||
| 156 | done |
||
| 157 | fi |
||
| 158 | |||
| 159 | if [ "$1" = "config" ]; then |
||
| 160 | case "$RESOURCE" in |
||
| 161 | PROC) |
||
| 162 | echo 'graph_title Processes used by vserver' |
||
| 163 | echo 'graph_args --base 1024k -l 0' |
||
| 164 | echo 'graph_vlabel Processes' |
||
| 165 | echo 'graph_info Shows the number of processes used by each vserver.' |
||
| 166 | ;; |
||
| 167 | VM) |
||
| 168 | echo 'graph_title Virtual memory used by vserver' |
||
| 169 | echo 'graph_args --base 1024k -l 0' |
||
| 170 | echo 'graph_vlabel VM pages' |
||
| 171 | echo 'graph_info Shows virtual memory (human readable) used by each vserver.' |
||
| 172 | ;; |
||
| 173 | VML) |
||
| 174 | echo 'graph_title Locked memory used by vserver' |
||
| 175 | echo 'graph_args --base 1024k -l 0' |
||
| 176 | echo 'graph_vlabel VML pages' |
||
| 177 | echo 'graph_info Shows locked memory (human readable) used by each vserver.' |
||
| 178 | ;; |
||
| 179 | RSS) |
||
| 180 | echo 'graph_title Resident set size used by vserver' |
||
| 181 | echo 'graph_args --base 1024k -l 0' |
||
| 182 | echo 'graph_vlabel RSS pages' |
||
| 183 | echo 'graph_info Shows resident set size (human readable) used by each vserver.' |
||
| 184 | ;; |
||
| 185 | ANON) |
||
| 186 | echo 'graph_title Anonymous memory used by vserver' |
||
| 187 | echo 'graph_args --base 1024k -l 0' |
||
| 188 | echo 'graph_vlabel ANON pages' |
||
| 189 | echo 'graph_info Shows anonymous memory (human readable) used by each vserver.' |
||
| 190 | ;; |
||
| 191 | FILES) |
||
| 192 | echo 'graph_title Files used by vserver' |
||
| 193 | echo 'graph_args --base 1024k -l 0' |
||
| 194 | echo 'graph_vlabel Files' |
||
| 195 | echo 'graph_info Shows files used by each vserver.' |
||
| 196 | ;; |
||
| 197 | OFD) |
||
| 198 | echo 'graph_title Open filedescriptors used by vserver' |
||
| 199 | echo 'graph_args --base 1024k -l 0' |
||
| 200 | echo 'graph_vlabel Open filedescriptors' |
||
| 201 | echo 'graph_info Shows open filedescriptors used by each vserver.' |
||
| 202 | ;; |
||
| 203 | LOCKS) |
||
| 204 | echo 'graph_title Locks used by vserver' |
||
| 205 | echo 'graph_args --base 1024k -l 0' |
||
| 206 | echo 'graph_vlabel Locks' |
||
| 207 | echo 'graph_info Shows locks used by each vserver.' |
||
| 208 | ;; |
||
| 209 | SOCK) |
||
| 210 | echo 'graph_title Sockets used by vserver' |
||
| 211 | echo 'graph_args --base 1024k -l 0' |
||
| 212 | echo 'graph_vlabel Sockets' |
||
| 213 | echo 'graph_info Shows sockets used by each vserver.' |
||
| 214 | ;; |
||
| 215 | MSGQ) |
||
| 216 | echo 'graph_title Message queues used by vserver' |
||
| 217 | echo 'graph_args --base 1024k -l 0' |
||
| 218 | echo 'graph_vlabel Message queues' |
||
| 219 | echo 'graph_info Shows message queues used by each vserver.' |
||
| 220 | ;; |
||
| 221 | SHM) |
||
| 222 | echo 'graph_title Shared memory used by vserver' |
||
| 223 | echo 'graph_args --base 1024k -l 0' |
||
| 224 | echo 'graph_vlabel SHM pages' |
||
| 225 | echo 'graph_info Shows shared memory (human readable) used by each vserver.' |
||
| 226 | ;; |
||
| 227 | *) |
||
| 228 | echo "$RESOURCE not defined." |
||
| 229 | exit 1 |
||
| 230 | ;; |
||
| 231 | esac |
||
| 232 | echo 'graph_category vserver' |
||
| 233 | |||
| 234 | |||
| 235 | # do not assume we are on i386 where pagesize is 4096... |
||
| 236 | pagesize=`perl -MPOSIX -e 'print POSIX::sysconf(_SC_PAGESIZE), "\n";'` |
||
| 237 | |||
| 238 | for xid in $XIDS ; do |
||
| 239 | |||
| 240 | LABEL=`cat /proc/virtual/$xid/$NAMELOC |grep NodeName |cut -f2` |
||
| 241 | NAME=`echo $LABEL | cut -d. -f1 | tr '-' '_'` |
||
| 242 | |||
| 243 | case "$RESOURCE" in |
||
| 244 | PROC) |
||
| 245 | echo "$NAME.label $LABEL: processes" |
||
| 246 | echo "$NAME.info Number of processes used by $LABEL." |
||
| 247 | ;; |
||
| 248 | VM) |
||
| 249 | echo "$NAME.label $LABEL: Virtual memory" |
||
| 250 | echo "$NAME.info Size of virtual memory used by $LABEL. (Number multipled by $pagesize to make it human readable)" |
||
| 251 | echo "$NAME.cdef $NAME,$pagesize,*" |
||
| 252 | ;; |
||
| 253 | VML) |
||
| 254 | echo "$NAME.label $LABEL: Locked memory" |
||
| 255 | echo "$NAME.info Size of locked memory used by $LABEL. (Number multipled by $pagesize to make it human readable)" |
||
| 256 | echo "$NAME.cdef $NAME,$pagesize,*" |
||
| 257 | ;; |
||
| 258 | RSS) |
||
| 259 | echo "$NAME.label $LABEL: Resident set size" |
||
| 260 | echo "$NAME.info Size of resident set size used by $LABEL. (Number multiplied by $pagesize to make it human readable)" |
||
| 261 | echo "$NAME.cdef $NAME,$pagesize,*" |
||
| 262 | ;; |
||
| 263 | ANON) |
||
| 264 | echo "$NAME.label $LABEL: Anonymous memory" |
||
| 265 | echo "$NAME.info Size of anonymous memory used by $LABEL. (Number multiplied by $pagesize to make it human readable)" |
||
| 266 | echo "$NAME.cdef $NAME,$pagesize,*" |
||
| 267 | ;; |
||
| 268 | FILES) |
||
| 269 | echo "$NAME.label $LABEL: Files" |
||
| 270 | echo "$NAME.info Number of files used by $LABEL." |
||
| 271 | ;; |
||
| 272 | OFD) |
||
| 273 | echo "$NAME.label $LABEL: Open filedescriptors" |
||
| 274 | echo "$NAME.info Number of open filedescriptors used by $LABEL." |
||
| 275 | ;; |
||
| 276 | LOCKS) |
||
| 277 | echo "$NAME.label $LABEL: Locks" |
||
| 278 | echo "$NAME.info Number of locks used by $LABEL." |
||
| 279 | ;; |
||
| 280 | SOCK) |
||
| 281 | echo "$NAME.label $LABEL: Sockets" |
||
| 282 | echo "$NAME.info Number of sockets used by $LABEL." |
||
| 283 | ;; |
||
| 284 | MSGQ) |
||
| 285 | echo "$NAME.label $LABEL: Message queues" |
||
| 286 | echo "$NAME.info Number of message queues used by $LABEL." |
||
| 287 | ;; |
||
| 288 | SHM) |
||
| 289 | echo "$NAME.label $LABEL: Shared memory" |
||
| 290 | echo "$NAME.info Size of shared memory used by $LABEL. (Number multiplied by $pagesize to make it human readable)" |
||
| 291 | echo "$NAME.cdef $1,$pagesize,*" |
||
| 292 | ;; |
||
| 293 | *) |
||
| 294 | echo "$RESOURCE not defined." |
||
| 295 | exit 1 |
||
| 296 | ;; |
||
| 297 | esac |
||
| 298 | |||
| 299 | if [ ! -z "$LIMITS" -a "$LIMITS" = 1 ]; then |
||
| 300 | LIMIT=`cat /proc/virtual/$xid/limit | grep $RESOURCE | cut -f4` |
||
| 301 | if [ ${LIMIT:-0} -gt 0 ]; then
|
||
| 302 | echo "$NAME.critical $LIMIT" |
||
| 303 | fi |
||
| 304 | fi |
||
| 305 | done |
||
| 306 | exit 0 |
||
| 307 | fi |
||
| 308 | |||
| 309 | |||
| 310 | for xid in $XIDS ; do |
||
| 311 | LABEL=`cat /proc/virtual/$xid/$NAMELOC |grep NodeName |cut -f2` |
||
| 312 | NAME=`echo $LABEL | cut -d. -f1 | tr '-' '_'` |
||
| 313 | cat /proc/virtual/$xid/limit | awk -v name="${NAME}" -v resource="${RESOURCE}:" \
|
||
| 314 | '{ if ( $1 == resource )
|
||
| 315 | printf "%s.value %d\n", name, $2 }' |
||
| 316 | done |
