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.
|
||||
#
|
||||
# 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
|
||||
# Created by Justin Shepherd <galstrom21@gmail.com>
|
||||
|
@ -31,6 +31,10 @@
|
|||
# Revision 2.0 2013/01/02
|
||||
# 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:
|
||||
#
|
||||
# config
|
||||
|
@ -39,10 +43,10 @@
|
|||
# Configuration variables
|
||||
#
|
||||
# mysqlopts - Options to pass to mysql
|
||||
# mysqladmin - Override location of mysqladmin
|
||||
# mysqlcli - Override location of mysql
|
||||
# numusers - Override maximum number of users to display
|
||||
# warning - Override default warning limit
|
||||
# critical - Override default critical limit
|
||||
# warning - Override default warning limit
|
||||
# critical - Override default critical limit
|
||||
#
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
@ -50,12 +54,13 @@
|
|||
use strict;
|
||||
|
||||
# Define the mysqladmin paths, and commands
|
||||
my $MYSQLADMIN = $ENV{mysqladmin} || "mysqladmin";
|
||||
my $TEST_COMMAND = "$MYSQLADMIN $ENV{mysqlopts} processlist";
|
||||
my $MYSQL_VARIABLES = "$MYSQLADMIN $ENV{mysqlopts} extended-status variables";
|
||||
my $warning = $ENV{warning} || "80";
|
||||
my $critical = $ENV{critical} || "90";
|
||||
my $numusers = $ENV{numusers} || 10;
|
||||
my $MYSQLCLI = $ENV{mysqlcli} || "mysql";
|
||||
my $TEST_COMMAND = "$MYSQLCLI $ENV{mysqlopts} -N -B -e \"SELECT NOW();\"";
|
||||
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 $critical = $ENV{critical} || "90";
|
||||
my $numusers = $ENV{numusers} || 10;
|
||||
my $numthreads = 0;
|
||||
|
||||
# Pull in any arguments
|
||||
my $arg = shift();
|
||||
|
@ -72,46 +77,36 @@ if ($arg eq 'config') {
|
|||
exit;
|
||||
|
||||
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
|
||||
my $counts = count_thread_users();
|
||||
my %counts = %{$counts};
|
||||
# Return the values to Munin
|
||||
my $counts = count_thread_users();
|
||||
my %counts = %{$counts};
|
||||
|
||||
sub valsort {
|
||||
return $counts{$a} <=> $counts{$b};
|
||||
sub valsort {
|
||||
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;
|
||||
my $total = 0;
|
||||
foreach my $user (sort valsort keys(%counts)) {
|
||||
last if $i++ >= $numusers;
|
||||
$total += $counts{$user};
|
||||
print "$user.value $counts{$user}\n";
|
||||
}
|
||||
my $other = poll_variables($MYSQL_VARIABLES,"Threads_connected") - $total;
|
||||
print "other.value $other\n";
|
||||
print "$print_user.value $counts{$user}\n";
|
||||
}
|
||||
my $other = $numthreads - $total;
|
||||
if($other < 0) {
|
||||
$other = 0;
|
||||
}
|
||||
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 {
|
||||
print <<EOM;
|
||||
print <<EOM;
|
||||
graph_title MySQL Connections per user
|
||||
graph_args --base 1000 --lower-limit 0
|
||||
graph_vlabel Connections
|
||||
|
@ -120,31 +115,36 @@ graph_category mysql
|
|||
graph_total Total
|
||||
EOM
|
||||
|
||||
my $counts = count_thread_users();
|
||||
my %counts = %{$counts};
|
||||
my $stacked = 0;
|
||||
my $counts = count_thread_users();
|
||||
my %counts = %{$counts};
|
||||
my $stacked = 0;
|
||||
|
||||
sub valsort {
|
||||
return $counts{$a} <=> $counts{$b};
|
||||
}
|
||||
my $i = 0;
|
||||
foreach my $user (sort valsort keys(%counts)) {
|
||||
last if $i++ >= $numusers;
|
||||
print <<EOM;
|
||||
$user.label $user
|
||||
$user.info Number of connexions used by user $user
|
||||
sub valsort {
|
||||
return $counts{$a} <=> $counts{$b};
|
||||
}
|
||||
my $i = 0;
|
||||
foreach my $user (reverse sort { $counts{$a} <=> $counts{$b} } keys %counts) {
|
||||
last if $i++ >= $numusers;
|
||||
my $print_user = $user;
|
||||
if($print_user eq "root") {
|
||||
$print_user = "root_";
|
||||
}
|
||||
print <<EOM;
|
||||
$print_user.label $user
|
||||
$print_user.info Number of connexions used by user $print_user
|
||||
EOM
|
||||
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 "$print_user.draw ";
|
||||
|
||||
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.draw STACK
|
||||
other.info Other connected threads not in the top $numusers
|
||||
|
@ -153,37 +153,32 @@ EOM
|
|||
|
||||
sub count_thread_users {
|
||||
my %counts = ();
|
||||
my $command = 'mysql -N -B -e "SHOW PROCESSLIST;"';
|
||||
open(SERVICE, "$command |")
|
||||
or die("Could not execute '$command': $!");
|
||||
open(SERVICE, "$MYSQL_QUERY |")
|
||||
or die("Could not execute '$MYSQL_QUERY': $!");
|
||||
while (<SERVICE>) {
|
||||
my ($threadid, $user) = split "\t";
|
||||
next unless ($threadid);
|
||||
$counts{$user} = 0 unless defined($counts{$user});
|
||||
$counts{$user}++;
|
||||
my ($no, $user) = split "\t";
|
||||
$user =~ s/^\s+|\s+$//g;
|
||||
$counts{$user} = $no;
|
||||
$numthreads += $no;
|
||||
}
|
||||
return \%counts;
|
||||
}
|
||||
|
||||
sub test_service {
|
||||
my $return = 1;
|
||||
system ("$MYSQLADMIN --version >/dev/null 2>/dev/null");
|
||||
if ($? == 0)
|
||||
{
|
||||
system ("$TEST_COMMAND >/dev/null 2>/dev/null");
|
||||
if ($? == 0)
|
||||
{
|
||||
print "yes\n";
|
||||
$return = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no (could not connect to mysql)\n";
|
||||
}
|
||||
system ("$MYSQLCLI --version >/dev/null 2>/dev/null");
|
||||
if ($? == 0) {
|
||||
system ("$TEST_COMMAND >/dev/null 2>/dev/null");
|
||||
if ($? == 0) {
|
||||
print "yes\n";
|
||||
$return = 0;
|
||||
}
|
||||
else {
|
||||
print "no (could not connect to mysql)\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no (mysqladmin not found)\n";
|
||||
else {
|
||||
print "no (mysql not found)\n";
|
||||
}
|
||||
exit $return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue