~ubuntu-branches/ubuntu/gutsy/munin/gutsy

« back to all changes in this revision

Viewing changes to node/node.d/mysql_queries.in

  • Committer: Bazaar Package Importer
  • Author(s): Tore Anderson
  • Date: 2004-05-21 20:51:19 UTC
  • Revision ID: james.westby@ubuntu.com-20040521205119-oz8bllbjp9hs80ig
Tags: upstream-0+1.0.0pre5
Import upstream version 0+1.0.0pre5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
#
 
3
# $Id: mysql_queries.in,v 1.5 2004/04/27 18:58:53 jimmyo Exp $
 
4
#
 
5
# Copyright 2003-2004 - Per Andreas Buer
 
6
#
 
7
# $Log: mysql_queries.in,v $
 
8
# Revision 1.5  2004/04/27 18:58:53  jimmyo
 
9
# Fixed bug in mysql-plugins (Deb#233762).
 
10
#
 
11
# Revision 1.4  2004/01/29 18:49:55  jimmyo
 
12
# Bugfix in plugin mysql_queries - insertions were no longer graphed. (SF#881483).
 
13
#
 
14
# Revision 1.3  2004/01/29 17:36:20  jimmyo
 
15
# Updated copyright information
 
16
#
 
17
# Revision 1.2  2004/01/15 16:35:43  jimmyo
 
18
# Bugfix from Dagfinn I. Manns�ker, closing SF#876443, SF#865125.
 
19
#
 
20
# Revision 1.1  2004/01/02 18:50:00  jimmyo
 
21
# Renamed occurrances of lrrd -> munin
 
22
#
 
23
# Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
 
24
# Import of LRRD CVS tree after renaming to Munin
 
25
#
 
26
# Revision 1.8  2003/12/01 13:31:37  jimmyo
 
27
# Bugfix to make stack/area right
 
28
#
 
29
# Revision 1.7  2003/11/08 00:10:13  jimmyo
 
30
# New mysql_queries plugin
 
31
#
 
32
#
 
33
# Parameters:
 
34
#
 
35
#   config
 
36
#   autoconf
 
37
#
 
38
# Configuration variables
 
39
#
 
40
#   mysqlopts     - Options to pass to mysql
 
41
#   mysqladmin    - Override location of mysqladmin
 
42
#
 
43
#%# family=auto
 
44
#%# capabilities=autoconf
 
45
 
 
46
use strict;
 
47
 
 
48
my $MYSQLADMIN = $ENV{mysqladmin} || "mysqladmin";
 
49
my $COMMAND    =      "$MYSQLADMIN $ENV{mysqlopts} extended-status";
 
50
 
 
51
 
 
52
my %WANTED = ( "Com_delete"  => "delete", 
 
53
                           "Com_insert"  => "insert",
 
54
               "Com_select"  => "select", 
 
55
               "Com_update"  => "update",
 
56
               "Com_replace" => "replace",
 
57
               "Qcache_hits" => "cache_hits",
 
58
             );
 
59
 
 
60
my $arg = shift();
 
61
 
 
62
if ($arg eq 'config') {
 
63
    print_config();
 
64
    exit();
 
65
} elsif ($arg eq 'autoconf') {
 
66
    unless (test_service() ) {
 
67
        print "yes\n";
 
68
    } else {
 
69
        print "no\n";
 
70
    }
 
71
    exit;
 
72
}
 
73
 
 
74
 
 
75
open(SERVICE, "$COMMAND |")
 
76
  or die("Coult not execute '$COMMAND': $!");
 
77
 
 
78
while (<SERVICE>) {
 
79
    my ($k, $v) = (m/(\w+).*?(\d+(?:\.\d+)?)/);
 
80
    next unless ($k);
 
81
    if (exists $WANTED{$k} ) {
 
82
        print("$WANTED{$k}.value $v\n");
 
83
    }
 
84
}
 
85
 
 
86
close(SERVICE);
 
87
 
 
88
 
 
89
sub print_config {
 
90
 
 
91
    my $num = 0;
 
92
 
 
93
    print("graph_title MySQL queries
 
94
graph_args --base 1000
 
95
graph_vlabel queries / sec
 
96
graph_total total\n");
 
97
 
 
98
    for my $key (keys %WANTED) {
 
99
        my $title = $WANTED{$key};
 
100
        print("$title.label ${title}\n",
 
101
              "$title.type COUNTER\n",
 
102
              "$title.max 500000\n",
 
103
              "$title.draw ", ($num) ? "STACK" : "AREA" ,  "\n",
 
104
             );
 
105
        $num++;
 
106
    }
 
107
    
 
108
}
 
109
 
 
110
 
 
111
sub test_service {
 
112
 
 
113
    my $return = 1;
 
114
 
 
115
    system ("$MYSQLADMIN --version >/dev/null 2>/dev/null");
 
116
    if ($? == 0)
 
117
    {
 
118
        system ("$COMMAND >/dev/null 2>/dev/null");
 
119
        if ($? == 0)
 
120
        {
 
121
            print "yes\n";
 
122
            $return = 0;
 
123
        }
 
124
        else
 
125
        {
 
126
            print "no (could not connect to mysql)\n";
 
127
        }
 
128
    }
 
129
    else
 
130
    {
 
131
        print "no (mysqadmin not found)\n";
 
132
    }
 
133
    exit $return;
 
134
}