Page 1 of 1

Change output to KB or MB..

Posted: Wed Sep 30, 2015 10:21 am
by xerez
Hi, I want monitor the memory usage of a process. I run the following:

Code: Select all

[nagios@hostname libexec]$ ./check_nrpe -H [IP] -c checkcounter -a "Counter=\\Process(nscp)\Working Set"
OK: \Process(nscp)\Working Set = 22421504|'\Process(nscp)\Working Setnone'=22421504;0;0
However, I prefer the output in other size, KB, MB... How can I get it?

Thanks.

Re: Change output to KB or MB..

Posted: Wed Sep 30, 2015 4:04 pm
by ssax
Unit conversions aren't supported by default, you would have to write a wrapper script on the XI server or write a script on the remote server that would handle the conversions.

Re: Change output to KB or MB..

Posted: Thu Oct 01, 2015 3:36 am
by xerez
I did the script but in nagiosgraph I see an error:

Code: Select all

No data available: host=hostname service=Check NSClien db=
Why? How can I fix it?

Re: Change output to KB or MB..

Posted: Thu Oct 01, 2015 12:54 pm
by tgriep
Could you post the script so we can review it?

Re: Change output to KB or MB..

Posted: Fri Oct 02, 2015 2:08 am
by xerez

Code: Select all

#!/bin/bash
############################################################################
# check_win_procs.sh
#
# Description:
# This script check the memory usage by a process on the target server.
#
#############################################################################
# Set path to the location of your Nagios plugin (check_nrpe)
pluginlocation="/usr/local/nagios/libexec"

#############################################################################
# Help
help="check_win_procs.sh \n
Usage: ./check_win_procs.sh -H host -p process [-o output]
\nOptions:\n-H Hostname of Windows server to check
-p Process to monitor
-o Choose output of value in KB, MB (default Byte)"

#############################################################################
# Check for people who need help - aren't we all nice ;-)
if [ "${1}" = "--help" -o "${#}" = "0" ];
       then
       echo -e "${help}";
       exit 1;
fi

#############################################################################
# Some people might forget to set the plugin path (pluginlocation)
if [ ! -x ${pluginlocation}/check_nrpe ]
then
echo "CRITICAL - Plugin check_nrpe not found in ${pluginlocation}"; exit 2
fi

#############################################################################
# Get user-given variables
while getopts "H:p:o:" Input;
do
       case ${Input} in
       H)      host=${OPTARG};;
       p)      proc=${OPTARG};;
       o)      output=${OPTARG};;
       *)      echo "Wrong option given. Please rtfm or launch --help"
               exit 1
               ;;
       esac
done

#############################################################################
# Catch error
if [ -z "${host}" ]; then
        echo "ERROR: You must specify a host"
        exit 3
elif [ -z "${proc}" ]; then
        echo "ERROR: You must specify a process"
        exit 3
fi

# Output
command=$(${pluginlocation}/check_nrpe -H ${host} -c checkcounter -a "Counter=\Process(${proc})\Working Set")

# In case KB or MB has been set in -o option
if [ -n "${output}" ]; then
        if [ "${output}" = "KB" ] || [ "${output}" = "kb" ]; then
                bytes=$(echo ${command} | cut -d = -f 3 | cut -d \; -f 1)
                return_bytes=$(expr ${bytes} / 1024)
                out=$(echo ${command} | sed "s/${bytes}/${return_bytes} KB/" | sed "s/${bytes};/${return_bytes};/")
        elif [ "${output}" = "MB" ] || [ "${output}" = "mb" ]; then
                bytes=$(echo ${command} | cut -d = -f 3 | cut -d \; -f 1)
                return_bytes=$(expr ${bytes} / 1024 / 1024)
                out=$(echo ${command} | sed "s/${bytes}/${return_bytes} MB/" | sed "s/${bytes};/${return_bytes};/")
        fi
else
        bytes=$(echo ${command} | cut -d = -f 3 | cut -d \; -f 1)
        out=$(echo ${command} | sed "s/${bytes}/${bytes} Bytes/" | sed "s/${bytes};/${bytes};/")
fi

# Output
echo ${out}
exit 0

Re: Change output to KB or MB..

Posted: Fri Oct 02, 2015 2:18 pm
by jdalrymple
When you changed your code did you per-chance change the service name? This looks like a misspelling of sorts otherwise:
xerez wrote:No data available: host=hostname service=Check NSClien db=
Actually, truth be told, it doesn't even look related to the plugin you're munging.