Skip to content

Commit

Permalink
check_qemu_overcommit: libvirt passes -smp 1,sockets=1... so trim aft…
Browse files Browse the repository at this point in the history
…er the ,

Signed-off-by: Simon Deziel <[email protected]>
  • Loading branch information
simondeziel committed Apr 30, 2017
1 parent d6e1e19 commit 7029292
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions plugins/check_qemu_overcommit
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#!/bin/sh

# Nagios plugin to check if QEMU VMs use too much resources for what's available

# Copyright (c) 2016 Simon Deziel <[email protected]>

# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.

# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# Copyright (C) 2016-2017 Simon Deziel <[email protected]>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

# Explicitly set the PATH to that of ENV_SUPATH in /etc/login.defs and unset
# various other variables. For details, see:
Expand All @@ -31,7 +32,7 @@ MSG_OK="OK"
MSG_WARNING="WARNING"
MSG_CRITICAL="CRITICAL"
MSG_UNKNOWN="UNKNOWN"
SCRIPT_NAME="$(basename $0)"
SCRIPT_NAME="$(basename "$0")"
GETOPT="/usr/bin/getopt"
perf_data="|"

Expand All @@ -55,7 +56,7 @@ p_unknown () {
usage () {
cat << EOF
Usage:
$SCRIPT_NAME [-h] -m <warning>,<critical> -p <warning>,<critical>
$SCRIPT_NAME [-h] -m <warning> -M <critical> -p <warning> -P <critical>
Options:
-h
Expand Down Expand Up @@ -90,7 +91,7 @@ fi
# Note that we use `"$@"' to let each command-line parameter expand to a
# separate word. The quotes around `$@' are essential!
# We need TEMP as the `eval set --' would nuke the return value of getopt.
TEMP=`$GETOPT -q -s sh -n $SCRIPT_NAME -o +hm:M:p:P: -- "$@"`
TEMP=$($GETOPT -q -s sh -n "$SCRIPT_NAME" -o +hm:M:p:P: -- "$@")
if [ $? != 0 ]; then
p_unknown "Unknown/invalid argument, see $SCRIPT_NAME -h for help"
fi
Expand Down Expand Up @@ -118,7 +119,7 @@ parse_qemu_cmdline() {
while [ "$#" -ge 1 ]; do
case $1 in
-m) t_m=$((t_m+$2));shift 2;;
-smp) t_p=$((t_p+$2));shift 2;;
-smp) t_p=$((t_p+$(echo "$2" | cut -d, -f1)));shift 2;;
*) shift;;
esac
done
Expand All @@ -129,9 +130,8 @@ t_p=0
OIFS="$IFS"
IFS="
"
for vm in $(pgrep -a -f ^qemu-system-); do
IFS=' '
parse_qemu_cmdline $vm
for qemu_args in $(pgrep -a ^qemu-system-.+); do
IFS=' ' parse_qemu_cmdline $qemu_args
done
IFS="$OIFS"

Expand Down

0 comments on commit 7029292

Please sign in to comment.