Change output to KB or MB..

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
xerez
Posts: 77
Joined: Wed Apr 22, 2015 7:50 am

Change output to KB or MB..

Post 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.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Change output to KB or MB..

Post 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.
xerez
Posts: 77
Joined: Wed Apr 22, 2015 7:50 am

Re: Change output to KB or MB..

Post 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?
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Change output to KB or MB..

Post by tgriep »

Could you post the script so we can review it?
Be sure to check out our Knowledgebase for helpful articles and solutions!
xerez
Posts: 77
Joined: Wed Apr 22, 2015 7:50 am

Re: Change output to KB or MB..

Post 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
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Change output to KB or MB..

Post 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.
Locked