mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51:03 +00:00
commit
4fa1dd3837
1 changed files with 84 additions and 89 deletions
|
@ -23,7 +23,7 @@
|
||||||
#
|
#
|
||||||
# To enable, link mysql_connections to this file. E.g.
|
# To enable, link mysql_connections to this file. E.g.
|
||||||
#
|
#
|
||||||
# ln -s /usr/share/node/node/plugins/mysql_connections /etc/munin/plugins/mysql_connections
|
# ln -s /usr/share/node/node/plugins/mysql_connections_per_user /etc/munin/plugins/mysql_connections_per_user
|
||||||
#
|
#
|
||||||
# Revision 1.0 2007/08/03
|
# Revision 1.0 2007/08/03
|
||||||
# Created by Justin Shepherd <galstrom21@gmail.com>
|
# Created by Justin Shepherd <galstrom21@gmail.com>
|
||||||
|
@ -31,6 +31,10 @@
|
||||||
# Revision 2.0 2013/01/02
|
# Revision 2.0 2013/01/02
|
||||||
# Per user support by anarcat@koumbit.org
|
# Per user support by anarcat@koumbit.org
|
||||||
#
|
#
|
||||||
|
# Revision 3.0 2014/06/11
|
||||||
|
# Fix now showing if not connected by transilvlad@gmail.com
|
||||||
|
# Other fixes and performance by transilvlad@gmail.com
|
||||||
|
#
|
||||||
# Parameters:
|
# Parameters:
|
||||||
#
|
#
|
||||||
# config
|
# config
|
||||||
|
@ -39,10 +43,10 @@
|
||||||
# Configuration variables
|
# Configuration variables
|
||||||
#
|
#
|
||||||
# mysqlopts - Options to pass to mysql
|
# mysqlopts - Options to pass to mysql
|
||||||
# mysqladmin - Override location of mysqladmin
|
# mysqlcli - Override location of mysql
|
||||||
# numusers - Override maximum number of users to display
|
# numusers - Override maximum number of users to display
|
||||||
# warning - Override default warning limit
|
# warning - Override default warning limit
|
||||||
# critical - Override default critical limit
|
# critical - Override default critical limit
|
||||||
#
|
#
|
||||||
#%# family=auto
|
#%# family=auto
|
||||||
#%# capabilities=autoconf
|
#%# capabilities=autoconf
|
||||||
|
@ -50,12 +54,13 @@
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
# Define the mysqladmin paths, and commands
|
# Define the mysqladmin paths, and commands
|
||||||
my $MYSQLADMIN = $ENV{mysqladmin} || "mysqladmin";
|
my $MYSQLCLI = $ENV{mysqlcli} || "mysql";
|
||||||
my $TEST_COMMAND = "$MYSQLADMIN $ENV{mysqlopts} processlist";
|
my $TEST_COMMAND = "$MYSQLCLI $ENV{mysqlopts} -N -B -e \"SELECT NOW();\"";
|
||||||
my $MYSQL_VARIABLES = "$MYSQLADMIN $ENV{mysqlopts} extended-status variables";
|
my $MYSQL_QUERY = "$MYSQLCLI $ENV{mysqlopts} -N -B -e \"SELECT SUM(NO) AS NO, USER FROM (SELECT 1 AS NO, USER FROM INFORMATION_SCHEMA.PROCESSLIST UNION ALL SELECT DISTINCT 0 AS NO, User AS USER FROM mysql.user WHERE User != '') AS Q GROUP BY USER ORDER BY NO DESC;\"";
|
||||||
my $warning = $ENV{warning} || "80";
|
my $warning = $ENV{warning} || "80";
|
||||||
my $critical = $ENV{critical} || "90";
|
my $critical = $ENV{critical} || "90";
|
||||||
my $numusers = $ENV{numusers} || 10;
|
my $numusers = $ENV{numusers} || 10;
|
||||||
|
my $numthreads = 0;
|
||||||
|
|
||||||
# Pull in any arguments
|
# Pull in any arguments
|
||||||
my $arg = shift();
|
my $arg = shift();
|
||||||
|
@ -72,46 +77,36 @@ if ($arg eq 'config') {
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
sub print_graph_data() {
|
sub print_graph_data() {
|
||||||
# Define the values that are returned to munin
|
# Define the values that are returned to munin
|
||||||
|
|
||||||
# Return the values to Munin
|
# Return the values to Munin
|
||||||
my $counts = count_thread_users();
|
my $counts = count_thread_users();
|
||||||
my %counts = %{$counts};
|
my %counts = %{$counts};
|
||||||
|
|
||||||
sub valsort {
|
sub valsort {
|
||||||
return $counts{$a} <=> $counts{$b};
|
return $counts{$a} <=> $counts{$b};
|
||||||
|
}
|
||||||
|
my $i = 0;
|
||||||
|
my $total = 0;
|
||||||
|
my $print_user = "";
|
||||||
|
foreach my $user (reverse sort { $counts{$a} <=> $counts{$b} } keys %counts) {
|
||||||
|
last if $i++ >= $numusers;
|
||||||
|
$total += $counts{$user};
|
||||||
|
$print_user = $user;
|
||||||
|
if($print_user eq "root") {
|
||||||
|
$print_user = "root_";
|
||||||
}
|
}
|
||||||
my $i = 0;
|
print "$print_user.value $counts{$user}\n";
|
||||||
my $total = 0;
|
}
|
||||||
foreach my $user (sort valsort keys(%counts)) {
|
my $other = $numthreads - $total;
|
||||||
last if $i++ >= $numusers;
|
if($other < 0) {
|
||||||
$total += $counts{$user};
|
$other = 0;
|
||||||
print "$user.value $counts{$user}\n";
|
}
|
||||||
}
|
print "other.value $other\n";
|
||||||
my $other = poll_variables($MYSQL_VARIABLES,"Threads_connected") - $total;
|
|
||||||
print "other.value $other\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub poll_variables {
|
|
||||||
my $command = shift;
|
|
||||||
my $expression = shift;
|
|
||||||
my $ret = 0;
|
|
||||||
open(SERVICE, "$command |")
|
|
||||||
or die("Coult not execute '$command': $!");
|
|
||||||
while (<SERVICE>) {
|
|
||||||
my ($field, $value) = (m/(\w+).*?(\d+(?:\.\d+)?)/);
|
|
||||||
next unless ($field);
|
|
||||||
if ($field eq $expression ) {
|
|
||||||
$ret = "$value";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close(SERVICE);
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub print_graph_information {
|
sub print_graph_information {
|
||||||
print <<EOM;
|
print <<EOM;
|
||||||
graph_title MySQL Connections per user
|
graph_title MySQL Connections per user
|
||||||
graph_args --base 1000 --lower-limit 0
|
graph_args --base 1000 --lower-limit 0
|
||||||
graph_vlabel Connections
|
graph_vlabel Connections
|
||||||
|
@ -120,31 +115,36 @@ graph_category mysql
|
||||||
graph_total Total
|
graph_total Total
|
||||||
EOM
|
EOM
|
||||||
|
|
||||||
my $counts = count_thread_users();
|
my $counts = count_thread_users();
|
||||||
my %counts = %{$counts};
|
my %counts = %{$counts};
|
||||||
my $stacked = 0;
|
my $stacked = 0;
|
||||||
|
|
||||||
sub valsort {
|
sub valsort {
|
||||||
return $counts{$a} <=> $counts{$b};
|
return $counts{$a} <=> $counts{$b};
|
||||||
}
|
}
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
foreach my $user (sort valsort keys(%counts)) {
|
foreach my $user (reverse sort { $counts{$a} <=> $counts{$b} } keys %counts) {
|
||||||
last if $i++ >= $numusers;
|
last if $i++ >= $numusers;
|
||||||
print <<EOM;
|
my $print_user = $user;
|
||||||
$user.label $user
|
if($print_user eq "root") {
|
||||||
$user.info Number of connexions used by user $user
|
$print_user = "root_";
|
||||||
|
}
|
||||||
|
print <<EOM;
|
||||||
|
$print_user.label $user
|
||||||
|
$print_user.info Number of connexions used by user $print_user
|
||||||
EOM
|
EOM
|
||||||
print "$user.draw ";
|
print "$print_user.draw ";
|
||||||
# if we already printed an entry, make the next ones stacked
|
|
||||||
if ($i > 1) {
|
|
||||||
print "STACK\n";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
print "AREA\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
print <<EOM;
|
# if we already printed an entry, make the next ones stacked
|
||||||
|
if ($i > 1) {
|
||||||
|
print "STACK\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print "AREA\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print <<EOM;
|
||||||
other.label Others
|
other.label Others
|
||||||
other.draw STACK
|
other.draw STACK
|
||||||
other.info Other connected threads not in the top $numusers
|
other.info Other connected threads not in the top $numusers
|
||||||
|
@ -153,37 +153,32 @@ EOM
|
||||||
|
|
||||||
sub count_thread_users {
|
sub count_thread_users {
|
||||||
my %counts = ();
|
my %counts = ();
|
||||||
my $command = 'mysql -N -B -e "SHOW PROCESSLIST;"';
|
open(SERVICE, "$MYSQL_QUERY |")
|
||||||
open(SERVICE, "$command |")
|
or die("Could not execute '$MYSQL_QUERY': $!");
|
||||||
or die("Could not execute '$command': $!");
|
|
||||||
while (<SERVICE>) {
|
while (<SERVICE>) {
|
||||||
my ($threadid, $user) = split "\t";
|
my ($no, $user) = split "\t";
|
||||||
next unless ($threadid);
|
$user =~ s/^\s+|\s+$//g;
|
||||||
$counts{$user} = 0 unless defined($counts{$user});
|
$counts{$user} = $no;
|
||||||
$counts{$user}++;
|
$numthreads += $no;
|
||||||
}
|
}
|
||||||
return \%counts;
|
return \%counts;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub test_service {
|
sub test_service {
|
||||||
my $return = 1;
|
my $return = 1;
|
||||||
system ("$MYSQLADMIN --version >/dev/null 2>/dev/null");
|
system ("$MYSQLCLI --version >/dev/null 2>/dev/null");
|
||||||
if ($? == 0)
|
if ($? == 0) {
|
||||||
{
|
system ("$TEST_COMMAND >/dev/null 2>/dev/null");
|
||||||
system ("$TEST_COMMAND >/dev/null 2>/dev/null");
|
if ($? == 0) {
|
||||||
if ($? == 0)
|
print "yes\n";
|
||||||
{
|
$return = 0;
|
||||||
print "yes\n";
|
}
|
||||||
$return = 0;
|
else {
|
||||||
}
|
print "no (could not connect to mysql)\n";
|
||||||
else
|
}
|
||||||
{
|
|
||||||
print "no (could not connect to mysql)\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
print "no (mysql not found)\n";
|
||||||
print "no (mysqladmin not found)\n";
|
|
||||||
}
|
}
|
||||||
exit $return;
|
exit $return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue