User Tools

Site Tools


pretty_nagios_nrpe_check_with_performance_data

Pretty Nagios nrpe check with performance data

This script gives a count of the number of open file handles for an RTP Proxy, plus one for the application itself. It exports performance data that gets graphed over time, spitting out a line like;

OK - File Handle Use is low : 22% | Open_File_Handles=902;2730;3072;0;4096

The variable names are pretty self explanatory, the loop at the beginning iterates through all of the command line options looking for -L and returning the next argument after that.

RTPProxy.sh
#!/usr/bin/bash
# Steve Jones, 2023-05-03
# Return data to Nagios about file handle usage on the RTP Proxy server
ServiceFile=/etc/systemd/system/rtp.service
Requested=4095
Application=rtpproxy
 
if [[ -f "${ServiceFile}" ]]
then
        Array=($(cat ${ServiceFile} | grep ExecStart=/bin/rtpproxy))
        for Loop in $(seq 0 1 ${#Array[@]}) ; do
        [[ "${Array[Loop]}" = "-L" ]] && Requested=${Array[((Loop+1))]}
        done
# Number of file handles returned in ${Requested} if defined, otherwise 4095
fi
 
# Critical limit for PerformanceData=3/4;
CriticalLimit=$(( 3 * $(( Requested / 4 )) ))
 
# Warning Limit for PerformanceData=2/3;
WarningLimit=$(( 2 * $(( Requested / 3 )) ))
 
# Get the current number of file handles open - this is what requires sudo;
OpenHandles=$(lsof -p $(pidof ${Application}) | grep -E 'UDP|txt' | wc --lines)
 
# We divide Requested by 100, that multiplies the result for percent;
Percent=$(( ${OpenHandles} / $(( ${Requested} / 100 )) ))
 
# Check Status
# Greater than limit warnings
if   [[ ${OpenHandles} -gt ${CriticalLimit} ]]; then
        STATUS="CRITICAL - File Handle use is very high, something seems wrong : ${Percent}% "
        EXIT=2
# Warning limit.
elif [[ ${OpenHandles} -gt ${WarningLimit} ]]; then
        STATUS="WARNING - File Handle use is high : ${Percent}% "
        EXIT=1
# All is ok.
elif [[ ${OpenHandles} -le ${WarningLimit} ]]; then
        STATUS="OK - File Handle Use is low : ${Percent}% "
        EXIT=0
# All is not okay, rtpproxy doesn't have a pid.
elif [[ ${OpenHandles} = 0 ]]; then
                STATUS="CRITICAL - rtpproxy seems to have died! "
                EXIT=2
fi
PerfData=" | Open_File_Handles=${OpenHandles};${WarningLimit};${CriticalLimit};0;${Requested}"
 
# Status and quit
echo ${STATUS}${PerfData}
exit ${EXIT}
pretty_nagios_nrpe_check_with_performance_data.txt · Last modified: by steve