1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
#!@@PERL@@
#
# $Id: mysql_queries.in 860 2005-03-29 20:32:59Z ilmari $
#
# Copyright 2003-2004 - Per Andreas Buer
#
# $Log$
# Revision 1.11 2004/12/10 18:51:43 jimmyo
# linux/apt* has been forced to LANG=C, to get predictable output.
#
# Revision 1.10 2004/12/10 10:47:47 jimmyo
# Change name from ${scale} to ${graph_period}, to be more consistent.
#
# Revision 1.9 2004/12/09 22:12:55 jimmyo
# Added "graph_period" option, to make "graph_sums" usable.
#
# Revision 1.8 2004/11/21 00:16:56 jimmyo
# Changed a lot of plugins so they use DERIVE instead of COUNTER.
#
# Revision 1.7 2004/09/08 15:25:33 ilmari
# Use @@PERL@@ in all perl shebang lines.
#
# Revision 1.6 2004/05/20 13:57:12 jimmyo
# Set categories to some of the plugins.
#
# Revision 1.5 2004/04/27 18:58:53 jimmyo
# Fixed bug in mysql-plugins (Deb#233762).
#
# Revision 1.4 2004/01/29 18:49:55 jimmyo
# Bugfix in plugin mysql_queries - insertions were no longer graphed. (SF#881483).
#
# Revision 1.3 2004/01/29 17:36:20 jimmyo
# Updated copyright information
#
# Revision 1.2 2004/01/15 16:35:43 jimmyo
# Bugfix from Dagfinn I. Mannsker, closing SF#876443, SF#865125.
#
# Revision 1.1 2004/01/02 18:50:00 jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1 2004/01/02 15:18:07 jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.8 2003/12/01 13:31:37 jimmyo
# Bugfix to make stack/area right
#
# Revision 1.7 2003/11/08 00:10:13 jimmyo
# New mysql_queries plugin
#
#
# Parameters:
#
# config
# autoconf
#
# Configuration variables
#
# mysqlopts - Options to pass to mysql
# mysqladmin - Override location of mysqladmin
#
#%# family=auto
#%# capabilities=autoconf
use strict;
my $MYSQLADMIN = $ENV{mysqladmin} || "mysqladmin";
my $COMMAND = "$MYSQLADMIN $ENV{mysqlopts} extended-status";
my %WANTED = ( "Com_delete" => "delete",
"Com_insert" => "insert",
"Com_select" => "select",
"Com_update" => "update",
"Com_replace" => "replace",
"Qcache_hits" => "cache_hits",
);
my $arg = shift();
if ($arg eq 'config') {
print_config();
exit();
} elsif ($arg eq 'autoconf') {
unless (test_service() ) {
print "yes\n";
} else {
print "no\n";
}
exit;
}
open(SERVICE, "$COMMAND |")
or die("Coult not execute '$COMMAND': $!");
while (<SERVICE>) {
my ($k, $v) = (m/(\w+).*?(\d+(?:\.\d+)?)/);
next unless ($k);
if (exists $WANTED{$k} ) {
print("$WANTED{$k}.value $v\n");
}
}
close(SERVICE);
sub print_config {
my $num = 0;
print("graph_title MySQL queries
graph_args --base 1000
graph_vlabel queries / \${graph_period}
graph_category mysql
graph_total total\n");
for my $key (keys %WANTED) {
my $title = $WANTED{$key};
print("$title.label ${title}\n",
"$title.min 0\n",
"$title.type DERIVE\n",
"$title.max 500000\n",
"$title.draw ", ($num) ? "STACK" : "AREA" , "\n",
);
$num++;
}
}
sub test_service {
my $return = 1;
system ("$MYSQLADMIN --version >/dev/null 2>/dev/null");
if ($? == 0)
{
system ("$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 (mysqadmin not found)\n";
}
exit $return;
}
|