1

I'm running the check_mysql plugin using NRPE on a remote DB-server, and while I can get satisfactory data on whether or not the server process is working as needed, I see that the plugin outputs a lot more info:

user@server:/etc/nagios# /usr/lib/nagios/plugins/check_mysql -H localhost -P 3306 -u nagios -psnip
Uptime: 112398  Threads: 5  Questions: 10921804  Slow queries: 0  Opens: 4408  Flush tables: 1  Open tables: 416  Queries per second avg: 97.170|Connections=137481c;;; Open_files=0;;; Open_tables=416;;; Qcache_free_memory=1031832;;; Qcache_hits=0c;;; Qcache_inserts=0c;;; Qcache_lowmem_prunes=0c;;; Qcache_not_cached=9427651c;;; Qcache_queries_in_cache=0;;; Queries=10921805c;;; Questions=10917613c;;; Table_locks_waited=0c;;; Threads_connected=5;;; Threads_running=1;;; Uptime=112398c;;;

Which makes me think that I can assert on things like the number of threads or slow queries to generate alert states.

The question is, how do I do that? The plugin's -w and -c parameters only deal with master-slave clock drift, but none of the other parameters.
Do I need to whip up some custom shell script to parse the output then return its own output? Or is there a built in facility in Nagios Core to do that sort of munging?

0

In the end I decided the best course of action would be to whip up a custom bit of scripting following the plugin specs, and do some string munging with awk. For future reference (caveat implementor):

#! /bin/bash

parse_mysql_output(){
    METRIC=`/usr/lib/nagios/plugins/check_mysql -H localhost -P 3306 -u nagios -p[REDACTED] | grep -shoP "${METRIC_NAME}: ([\d.]+)" | awk -F ': ' '{print $2}'`
    if (($(echo "$METRIC <= $WARNING_THRESHOLD" | bc -l))); then
        echo "OK - $METRIC_NAME: $METRIC"
        exit 0
    fi

    if (($(echo "$METRIC > $WARNING_THRESHOLD" | bc -l))); then
        if (($(echo "$METRIC <= $CRITICAL_THRESHOLD" | bc -l))); then
            echo "WARNING - $METRIC_NAME: $METRIC"
            exit 1
        fi
    fi

    if (($(echo "$METRIC >= $CRITICAL_THRESHOLD" | bc -l))); then
        echo "CRITICAL - $METRIC_NAME: $METRIC"
        exit 2
    fi

    echo "INDETERMINATE STATE - $METRIC_NAME: $METRIC"
    exit 3
}

if [[ -z "$1" || -z "$2" || -z "$3" ]]
then
    echo "Missing parameters! Syntax: ./`basename $0` metric warning_threshold critical_threshold"
    exit 3
else
    METRIC_NAME=$1
    WARNING_THRESHOLD=$2
    CRITICAL_THRESHOLD=$3
fi

parse_mysql_output

In the intended use-case, you'd call this via a custom command in the NRPE config, and pass the metrics and thresholds. Before calling, you'd need to change the connection as required for your installation.

Feedback and comments welcome.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.