mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 14:16:00 +00:00
Make it usable
Fixed the display issue for formerly active users that wore no longer showing once they closed all connections. Also made other fixes like the negative others and improved performance. It could still be improved but for now it should do.
This commit is contained in:
parent
624c826a27
commit
0866999f9d
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,7 +43,7 @@
|
||||||
# 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
|
||||||
|
@ -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();
|
||||||
|
@ -83,35 +88,25 @@ sub print_graph_data() {
|
||||||
}
|
}
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
my $total = 0;
|
my $total = 0;
|
||||||
foreach my $user (sort valsort keys(%counts)) {
|
my $print_user = "";
|
||||||
|
foreach my $user (reverse sort { $counts{$a} <=> $counts{$b} } keys %counts) {
|
||||||
last if $i++ >= $numusers;
|
last if $i++ >= $numusers;
|
||||||
$total += $counts{$user};
|
$total += $counts{$user};
|
||||||
print "$user.value $counts{$user}\n";
|
$print_user = $user;
|
||||||
|
if($print_user eq "root") {
|
||||||
|
$print_user = "root_";
|
||||||
|
}
|
||||||
|
print "$print_user.value $counts{$user}\n";
|
||||||
|
}
|
||||||
|
my $other = $numthreads - $total;
|
||||||
|
if($other < 0) {
|
||||||
|
$other = 0;
|
||||||
}
|
}
|
||||||
my $other = poll_variables($MYSQL_VARIABLES,"Threads_connected") - $total;
|
|
||||||
print "other.value $other\n";
|
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,21 +115,26 @@ 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;
|
||||||
|
my $print_user = $user;
|
||||||
|
if($print_user eq "root") {
|
||||||
|
$print_user = "root_";
|
||||||
|
}
|
||||||
print <<EOM;
|
print <<EOM;
|
||||||
$user.label $user
|
$print_user.label $user
|
||||||
$user.info Number of connexions used by user $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 we already printed an entry, make the next ones stacked
|
||||||
if ($i > 1) {
|
if ($i > 1) {
|
||||||
print "STACK\n";
|
print "STACK\n";
|
||||||
|
@ -142,9 +142,9 @@ print "$user.draw ";
|
||||||
else {
|
else {
|
||||||
print "AREA\n";
|
print "AREA\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print <<EOM;
|
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";
|
print "yes\n";
|
||||||
$return = 0;
|
$return = 0;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
print "no (could not connect to mysql)\n";
|
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