Merge branch 'develop' into tee_fixes

This commit is contained in:
Markus Makela 2015-03-06 22:43:04 +02:00
commit dc1829fc8a
6 changed files with 824 additions and 0 deletions

44
plugins/nagios/README Normal file
View File

@ -0,0 +1,44 @@
MaxScale Nagios plugins, for Nagios 3.5.1
MaxScale must be configured with 'maxscaled' protocol for the administration interface
[AdminInterface]
type=service
router=cli
[AdminListener]
type=listener
service=AdminInterface
protocol=maxscaled
port=6603
1) copy check_maxscale_*.pl under /usr/lib64/nagios/plugins
2) copy maxscale_commands.cfg, server1.cfg to /etc/nagios/objects/
3) Edit /etc/nagios/nagios.cfg
add
cfg_file=/etc/nagios/objects/maxscale_commands.cfg
cfg_file=/etc/nagios/objects/server1.cfg
Please note:
- modify server IP address in server1.cfg, pointing to MaxScale server
- maxadmin executable must be in the nagios server
- default AdminInterface port is 6603
- default maxadmin executable path is /usr/local/skysql/maxscale/bin/maxadmin
It can be changed by -m option
Example related to server1.cfg
# Check MaxScale sessions, on the remote machine.
define service{
use local-service ; Name of service template to use
host_name server1
service_description MaxScale_sessions
check_command check_maxscale_resource!6603!admin!skysql!sessions!/path_to/maxadmin
notifications_enabled 0
}
4) Restart Nagios

View File

@ -0,0 +1,213 @@
#!/usr/bin/perl
#
#
#
# This file is distributed as part of the MariaDB Corporation MaxScale. It is free
# software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation,
# version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright MariaDB Corporation Ab 2013-2015
#
#
#
# @file check_maxscale_monitors.pl - Nagios plugin for MaxScale monitors
#
# Revision History
#
# Date Who Description
# 06-03-2015 Massimiliano Pinto Initial implementation
#
#use strict;
#use warnings;
use Getopt::Std;
my %opts;
my $TIMEOUT = 15; # we don't want to wait long for a response
my %ERRORS = ('UNKNOWN' , '3',
'OK', '0',
'WARNING', '1',
'CRITICAL', '2');
my $curr_script = "$0";
$curr_script =~ s{.*/}{};
sub usage {
my $rc = shift;
print <<"EOF";
MaxScale monitor checker plugin for Nagios
Usage: $curr_script [-r <resource>] [-H <host>] [-P <port>] [-u <user>] [-p <pass>] [-m <maxadmin>] [-h]
Options:
-r <resource> = monitors
-h = provide this usage message
-H <host> = which host to connect to
-P <port> = port to use
-u <user> = username to connect as
-p <pass> = password to use for <user> at <host>
-m <maxadmin> = /path/to/maxadmin
EOF
exit $rc;
}
%opts =(
'r' => 'monitors', # default maxscale resource to show
'h' => '', # give help
'H' => 'localhost', # host
'u' => 'root', # username
'p' => '', # password
'P' => 6603, # port
'm' => '/usr/local/skysql/maxscale/bin/maxadmin', # maxadmin
);
my $MAXADMIN_DEFAULT = $opts{'m'};
getopts('r:hH:u:p:P:m:', \%opts)
or usage( $ERRORS{"UNKNOWN"} );
usage( $ERRORS{'OK'} ) if $opts{'h'};
my $MAXADMIN_RESOURCE = $opts{'r'};
my $MAXADMIN = $opts{'m'};
if (!defined $MAXADMIN || length($MAXADMIN) == 0) {
$MAXADMIN = $MAXADMIN_DEFAULT;
}
-x $MAXADMIN or
die "$curr_script: Failed to find required tool: $MAXADMIN. Please install it or use the -m option to point to another location.";
# Just in case of problems, let's not hang Nagios
$SIG{'ALRM'} = sub {
print ("UNKNOWN: No response from MaxScale server (alarm)\n");
exit $ERRORS{"UNKNOWN"};
};
alarm($TIMEOUT);
my $command = $MAXADMIN . ' -h ' . $opts{'H'} . ' -u ' . $opts{'u'} . ' -p "' . $opts{'p'} . '" -P ' . $opts{'P'} . ' ' . "show " . $MAXADMIN_RESOURCE;
#print "maxadmin command: $command\n";
open (MAXSCALE, "$command 2>&1 |")
or die "can't get data out of Maxscale: $!";
my $hostname = qx{hostname}; chomp $hostname;
my $waiting_backend = 0;
my $service;
my $start_output = 0;
my $n_threads = 0;
my $p_threads = 0;
my $performance_data="";
my $resource_type = $MAXADMIN_RESOURCE;
chop($resource_type);
my $resource_match = ucfirst("$resource_type Name");
my $this_key;
my %monitor_data;
while ( <MAXSCALE> ) {
chomp;
if ( /(Failed|Unable) to connect to MaxScale/ ) {
printf "CRITICAL: $_\n";
close(MAXSCALE);
exit(2);
}
if ( /^Monitor\:/ ) {
$n_threads++;
$this_key = 'monitor' . $n_threads;
$monitor_data{$this_key} = {
'1name'=> '',
'2state' => '',
'3servers' => '',
'4interval' => '',
'5repl_lag' => ''
};
next;
}
next if (/--/ || $_ eq '');
if ( /\s+Name/) {
my $str;
my $perf_line;
my @data_row = split(':', $_);
my $name = $data_row[1];
$name =~ s/^\s+|\s+$//g;
$monitor_data{$this_key}{'1name'}=$name;
}
if (/(\s+Monitor )(.*)/) {
$monitor_data{$this_key}{'2state'}=$2;
}
if ( /Monitored servers\:/ ) {
my $server_list;
my @data_row = split(':', $_);
shift(@data_row);
foreach my $name (@data_row) {
$name =~ s/^\s+|\s+$//g;
$name =~ s/ //g;
$server_list .= $name . ":";
}
chop($server_list);
$monitor_data{$this_key}{'3servers'}=$server_list;
}
if ( /(Sampling interval\:)\s+(\d+) milliseconds/ ) {
#my @data_row = split(':', $_);
#my $name = $data_row[1];
#$name =~ s/^\s+|\s+$//g;
#$monitor_data{$this_key}{'4interval'}=$name;
$monitor_data{$this_key}{'4interval'}=$2;
}
if ( /Replication lag\:/ ) {
my @data_row = split(':', $_);
my $name = $data_row[1];
$name =~ s/^\s+|\s+$//g;
$monitor_data{$this_key}{'5repl_lag'}=$name;
}
}
for my $key ( sort(keys %monitor_data) ) {
#print "-- key: [$key]\n";
my $local_hash = {};
$performance_data .= " $key=";
$local_hash = $monitor_data{$key};
my %new_hash = %$local_hash;
foreach my $key (sort (keys (%new_hash))) {
$performance_data .= $new_hash{$key} . ";";
}
}
chop($performance_data);
if ($n_threads) {
printf "OK: %d monitors found |%s\n", $n_threads, $performance_data;
close(MAXSCALE);
exit 0;
} else {
printf "CRITICAL: 0 monitors found\n";
close(MAXSCALE);
exit 2;
}

View File

@ -0,0 +1,181 @@
#!/usr/bin/perl
#
#
#
# This file is distributed as part of the MariaDB Corporation MaxScale. It is free
# software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation,
# version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright MariaDB Corporation Ab 2013-2015
#
#
#
# @file check_maxscale_resources.pl - Nagios plugin for MaxScale resources
#
# Revision History
#
# Date Who Description
# 06-03-2015 Massimiliano Pinto Initial implementation
#
#use strict;
#use warnings;
use Getopt::Std;
my %opts;
my $TIMEOUT = 15; # we don't want to wait long for a response
my %ERRORS = ('UNKNOWN' , '3',
'OK', '0',
'WARNING', '1',
'CRITICAL', '2');
my $curr_script = "$0";
$curr_script =~ s{.*/}{};
sub usage {
my $rc = shift;
print <<"EOF";
MaxScale monitor checker plugin for Nagios
Usage: $curr_script [-r <resource>] [-H <host>] [-P <port>] [-u <user>] [-p <pass>] [-m <maxadmin>] [-h]
Options:
-r <resource> = modules|services|filters|listeners|servers|sessions
-h = provide this usage message
-H <host> = which host to connect to
-P <port> = port to use
-u <user> = username to connect as
-p <pass> = password to use for <user> at <host>
-m <maxadmin> = /path/to/maxadmin
EOF
exit $rc;
}
%opts =(
'r' => 'services', # default maxscale resource to show
'h' => '', # give help
'H' => 'localhost', # host
'u' => 'root', # username
'p' => '', # password
'P' => 6603, # port
'm' => '/usr/local/skysql/maxscale/bin/maxadmin', # maxadmin
);
my $MAXADMIN_DEFAULT = $opts{'m'};
getopts('r:hH:u:p:P:m:', \%opts)
or usage( $ERRORS{"UNKNOWN"} );
usage( $ERRORS{'OK'} ) if $opts{'h'};
my $MAXADMIN_RESOURCE = $opts{'r'};
my $MAXADMIN = $opts{'m'};
if (!defined $MAXADMIN || length($MAXADMIN) == 0) {
$MAXADMIN = $MAXADMIN_DEFAULT;
}
-x $MAXADMIN or
die "$curr_script: Failed to find required tool: $MAXADMIN. Please install it or use the -m option to point to another location.";
# Just in case of problems, let's not hang Nagios
$SIG{'ALRM'} = sub {
print ("UNKNOWN: No response from MaxScale server (alarm)\n");
exit $ERRORS{"UNKNOWN"};
};
alarm($TIMEOUT);
my $command = $MAXADMIN . ' -h ' . $opts{'H'} . ' -u ' . $opts{'u'} . ' -p "' . $opts{'p'} . '" -P ' . $opts{'P'} . ' ' . "list " . $MAXADMIN_RESOURCE;
#print "maxadmin command: $command\n";
open (MAXSCALE, "$command 2>&1 |")
or die "can't get data out of Maxscale: $!";
my $hostname = qx{hostname}; chomp $hostname;
my $waiting_backend = 0;
my $service;
my $start_output = 0;
my $n_threads = 0;
my $p_threads = 0;
my $performance_data="";
my $resource_type = $MAXADMIN_RESOURCE;
chop($resource_type);
my $resource_match = ucfirst("$resource_type Name");
if ($resource_type eq "listener") {
$resource_match = "Service Name";
}
if ($resource_type eq "filter") {
$resource_match = "Filter";
}
if ($resource_type eq "server") {
$resource_match = "Server";
}
if ($resource_type eq "session") {
$resource_match = "Session";
}
#print "Matching [$resource_match]\n";
while ( <MAXSCALE> ) {
chomp;
if ( /(Failed|Unable) to connect to MaxScale/ ) {
printf "CRITICAL: $_\n";
close(MAXSCALE);
exit(2);
}
if ( ! /^$resource_match/ ) {
} else {
$start_output = 1;
next;
}
if ($start_output) {
next if (/--/ || $_ eq '');
$n_threads++;
if ($resource_type ne "session") {
my $str;
my $perf_line;
my @data_row = split('\|', $_);
$performance_data .= "module$n_threads=";
foreach my $val (@data_row) {
$str = $val;
$str =~ s/^\s+|\s+$//g;
$perf_line .= $str . ';';
}
chop($perf_line);
$performance_data .= $perf_line . ' ';
}
}
}
chop($performance_data);
if ($n_threads) {
if ($performance_data eq '') {
printf "OK: %d $MAXADMIN_RESOURCE found\n", $n_threads;
} else {
printf "OK: %d $MAXADMIN_RESOURCE found | %s\n", $n_threads, $performance_data;
}
close(MAXSCALE);
exit 0;
} else {
printf "CRITICAL: 0 $MAXADMIN_RESOURCE found\n";
close(MAXSCALE);
exit 2;
}

View File

@ -0,0 +1,244 @@
#!/usr/bin/perl
#
#
#
# This file is distributed as part of the MariaDB Corporation MaxScale. It is free
# software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation,
# version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright MariaDB Corporation Ab 2013-2015
#
#
#
# @file check_maxscale_threads.pl - Nagios plugin for MaxScale threads and events
#
# Revision History
#
# Date Who Description
# 06-03-2015 Massimiliano Pinto Initial implementation
#
#use strict;
#use warnings;
use Getopt::Std;
my %opts;
my $TIMEOUT = 15; # we don't want to wait long for a response
my %ERRORS = ('UNKNOWN' , '3',
'OK', '0',
'WARNING', '1',
'CRITICAL', '2');
my $curr_script = "$0";
$curr_script =~ s{.*/}{};
sub usage {
my $rc = shift;
print <<"EOF";
MaxScale monitor checker plugin for Nagios
Usage: $curr_script [-r <resource>] [-H <host>] [-P <port>] [-u <user>] [-p <pass>] [-m <maxadmin>] [-h]
Options:
-r <resource> = threads
-h = provide this usage message
-H <host> = which host to connect to
-P <port> = port to use
-u <user> = username to connect as
-p <pass> = password to use for <user> at <host>
-m <maxadmin> = /path/to/maxadmin
EOF
exit $rc;
}
%opts =(
'r' => 'threads', # default maxscale resource to show
'h' => '', # give help
'H' => 'localhost', # host
'u' => 'root', # username
'p' => '', # password
'P' => 6603, # port
'm' => '/usr/local/skysql/maxscale/bin/maxadmin', # maxadmin
);
my $MAXADMIN_DEFAULT = $opts{'m'};
getopts('r:hH:u:p:P:m:', \%opts)
or usage( $ERRORS{"UNKNOWN"} );
usage( $ERRORS{'OK'} ) if $opts{'h'};
my $MAXADMIN_RESOURCE = $opts{'r'};
my $MAXADMIN = $opts{'m'};
if (!defined $MAXADMIN || length($MAXADMIN) == 0) {
$MAXADMIN = $MAXADMIN_DEFAULT;
}
-x $MAXADMIN or
die "$curr_script: Failed to find required tool: $MAXADMIN. Please install it or use the -m option to point to another location.";
# Just in case of problems, let's not hang Nagios
$SIG{'ALRM'} = sub {
print ("UNKNOWN: No response from MaxScale server (alarm)\n");
exit $ERRORS{"UNKNOWN"};
};
alarm($TIMEOUT);
my $command = $MAXADMIN . ' -h ' . $opts{'H'} . ' -u ' . $opts{'u'} . ' -p "' . $opts{'p'} . '" -P ' . $opts{'P'} . ' ' . "show " . $MAXADMIN_RESOURCE;
#print "maxadmin command: $command\n";
open (MAXSCALE, "$command 2>&1 |")
or die "can't get data out of Maxscale: $!";
my $hostname = qx{hostname}; chomp $hostname;
my $waiting_backend = 0;
my $service;
my $start_output = 0;
my $n_threads = 0;
my $p_threads = 0;
my $performance_data="";
my $resource_type = $MAXADMIN_RESOURCE;
chop($resource_type);
my $resource_match = ucfirst("$resource_type Name");
my $historic_thread_load_average = 0;
my $current_thread_load_average = 0;
my %thread_data;
my %event_data;
my $start_queue_len = 0;
while ( <MAXSCALE> ) {
chomp;
if ( /(Failed|Unable) to connect to MaxScale/ ) {
printf "CRITICAL: $_\n";
close(MAXSCALE);
exit(2);
}
if ( /Historic Thread Load Average/) {
my $str;
my @data_row = split(':', $_);
foreach my $val (@data_row) {
$str = $val;
$str =~ s/^\s+|\s+$//g;
}
chop($str);
$historic_thread_load_average = $str;
}
if (/Current Thread Load Average/) {
my $str;
my @data_row = split(':', $_);
foreach my $val (@data_row) {
$str = $val;
$str =~ s/^\s+|\s+$//g;
}
chop($str);
$current_thread_load_average = $str;
}
if (/Minute Average/) {
my $str;
my $in_str;
my @data_row = split(',', $_);
foreach my $val (@data_row) {
my ($i,$j)= split(':', $val);
$i =~ s/^\s+|\s+$//g;
$j =~ s/^\s+|\s+$//g;
if ($start_queue_len) {
$event_data{$i} = $j;
} else {
$thread_data{$i} = $j;
}
}
}
if ( /Pending event queue length averages/) {
$start_queue_len = 1;
next;
}
if ( ! /^\s+ID/ ) {
#printf $_ ."\n";
} else {
#printf "[$_]" ."\n";
$start_output = 1;
next;
}
if ($start_output && /^\s+\d/) {
#printf "Thread [$_]" . "\n";
$n_threads++;
if (/Processing/) {
$p_threads++;
}
}
}
close(MAXSCALE);
open( MAXSCALE, "/servers/maxinfo/bin/maxadmin -h 127.0.0.1 -P 8444 -uadmin -pskysql show epoll 2>&1 |" )
or die "can't get data out of Maxscale: $!";
my $queue_len = 0;
while ( <MAXSCALE> ) {
chomp;
if ( ! /Current event queue length/ ) {
next;
} else {
my $str;
my @data_row = split(':', $_);
foreach my $val (@data_row) {
$str = $val;
$str =~ s/^\s+|\s+$//g;
}
$queue_len = $str;
last;
}
}
my $performance_data = "";
my $performance_data_thread = "";
my $performance_data_event = "";
my $in_str;
my $in_key;
my $in_val;
my @new_thread_array = @thread_data{'15 Minute Average', '5 Minute Average', '1 Minute Average'};
my @new_event_array = @event_data{'15 Minute Average', '5 Minute Average', '1 Minute Average'};
$performance_data_thread = join(';', @new_thread_array);
$performance_data_event = join(';', @new_event_array);
$performance_data .= "threads=$historic_thread_load_average;$current_thread_load_average avg_threads=$performance_data_thread avg_events=$performance_data_event";
if ($p_threads < $n_threads) {
printf "OK: Processing threads: %d/%d Events: %d | $performance_data\n", $p_threads, $n_threads, $queue_len;
close(MAXSCALE);
exit 0;
} else {
printf "WARNING: Processing threads: %d/%d Events: %d | $performance_data\n", $p_threads, $n_threads, $queue_len;
close(MAXSCALE);
exit 1;
}

View File

@ -0,0 +1,31 @@
###############################################################################
# MAXSCALE_COMMANDS.CFG - SAMPLE COMMAND DEFINITIONS FOR NAGIOS 3.5.1
#
# Last Modified: 06-03-2015
#
# NOTES: This config file provides you with some example command definitions
# that you can reference in host, service, and contact definitions.
#
# You don't need to keep commands in a separate file from your other
# object definitions. This has been done just to make things easier to
# understand.
#
###############################################################################
# check maxscale monitors
define command{
command_name check_maxscale_monitors
command_line $USER1$/check_maxscale_monitors.pl -H $HOSTADDRESS$ -P $ARG1$ -u $ARG2$ -p $ARG3$ -r $ARG4$ -m $ARG5$
}
# check maxscale threads
define command{
command_name check_maxscale_threads
command_line $USER1$/check_maxscale_threads.pl -H $HOSTADDRESS$ -P $ARG1$ -u $ARG2$ -p $ARG3$ -r $ARG4$ -m $ARG5$
}
# check maxscale resource (listeners, services, etc)
define command{
command_name check_maxscale_resource
command_line $USER1$/check_maxscale_resources.pl -H $HOSTADDRESS$ -P $ARG1$ -u $ARG2$ -p $ARG3$ -r $ARG4$ -m $ARG5$
}

111
plugins/nagios/server1.cfg Normal file
View File

@ -0,0 +1,111 @@
###############################################################################
###############################################################################
#
# HOST DEFINITION
#
###############################################################################
###############################################################################
# Define a host for the remote machine
define host{
use linux-server ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name server1
alias server1
address xxx.xxx.xxx.xxx
}
###############################################################################
###############################################################################
#
# HOST GROUP DEFINITION
#
###############################################################################
###############################################################################
# Define an optional hostgroup for Linux machines
define hostgroup{
hostgroup_name linux-real-servers ; The name of the hostgroup
alias Linux Real Servers ; Long name of the group
members server1 ; Comma separated list of hosts that belong to this group
}
# Check MaxScale modules, on the remote machine.
define service{
use local-service ; Name of service template to use
host_name server1
service_description MaxScale_modules
check_command check_maxscale_resource!6603!admin!skysql!modules
notifications_enabled 0
}
# Check MaxScale services, on the remote machine.
define service{
use local-service ; Name of service template to use
host_name server1
service_description MaxScale_services
check_command check_maxscale_resource!6603!admin!skysql!services
notifications_enabled 0
}
# Check MaxScale listeners, on the remote machine.
define service{
use local-service ; Name of service template to use
host_name server1
service_description MaxScale_listeners
check_command check_maxscale_resource!6603!admin!skysql!listeners
notifications_enabled 0
}
# Check MaxScale servers, on the remote machine.
define service{
use local-service ; Name of service template to use
host_name server1
service_description MaxScale_servers
check_command check_maxscale_resource!6603!admin!skysql!servers
notifications_enabled 0
}
# Check MaxScale sessions, on the remote machine.
define service{
use local-service ; Name of service template to use
host_name server1
service_description MaxScale_sessions
check_command check_maxscale_resource!6603!admin!skysql!sessions
notifications_enabled 0
}
# Check MaxScale filters, on the remote machine.
define service{
use local-service ; Name of service template to use
host_name server1
service_description MaxScale_filters
check_command check_maxscale_resource!6603!admin!skysql!filters
notifications_enabled 0
}
# Check MaxScale monitors, on the remote machine.
define service{
use local-service ; Name of service template to use
host_name server1
service_description MaxScale_monitors
check_command check_maxscale_monitors!6603!admin!skysql!monitors
notifications_enabled 0
}
# Define a service to check Script on the remote machine.
define service{
use local-service ; Name of service template to use
host_name server1
service_description MaxScale_threads
check_command check_maxscale_threads!6603!admin!skysql!threads
notifications_enabled 0
}