Nagios modul til overvågning af antal MySQL Connections

Jeg har gemt selve modulet i /opt/nagios/mysql_conn.php:

#!/usr/bin/php
<?
# Copyright (c) 2013 Mikkel Mikjaer Christensen

function get_args()
{
        global $argv;
        $a = $argv;
        unset($a[0]);
        $b = preg_split("/-/",implode(" ",$a),NULL,PREG_SPLIT_NO_EMPTY);
        foreach ($b as $_)
        {
                $c = preg_split("/ /",$_,NULL,PREG_SPLIT_NO_EMPTY);
                $ret[$c[0]]=$c[1];
        }
        return $ret;
}
$a = get_args();
$warning = $a["w"];
$critical = $a["c"];

mysql_connect("localhost","root","p3wOgsq8");
$conn = mysql_num_rows(mysql_query("show processlist"));

if ($conn >= $critical)
{       
        print "CRITICAL, MySQL Connections: $conn\n";
        die(2);
} else if ($conn >= $warning) {
        print "WARNING, MySQL Connections: $conn\n";
        die(1);
} else {
        print "OK, MySQL Connections: $conn\n";
        die(0);
}
?>

Jeg satte den op via nrpe, så på min mysql server i /etc/nagios/nrpe.cfg indsatte jeg flg. linie:
command[check_mysql_conn]=/opt/nagios/mysql_conn.php -w 300 -c 400

og på nagios serveren tilføjede jeg flg. i /etc/nagios-plugins/config/nrpe.cfg:

define command{
        command_name    check_mysql_conn
        command_line    /usr/lib/nagios/plugins/check_nrpe -H '$HOSTADDRESS$' -c check_mysql_conn -u # -w 30
}

og til sidst kan du oprette flg. service-definition:

define service{
        use                     generic-service         ; Inherit default values from a template
        host_name               mysql.example.com
        service_description     Current MySQL Connections
        check_command           check_mysql_conn
        }

 

Dette indlæg blev udgivet i Knowledge Base, Linux, Monitoring, Mysql, Nagios, Old Base. Bogmærk permalinket.

Skriv et svar