root/lib/Core/MysqlStatus.pm

Revision 8ce41499f5ae9839b3e159855a1684572673e7ab, 1.5 kB (checked in by Jason Dixon <jdixon@omniti.com>, 5 years ago)

ah, that feels better

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@380 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100644
Line 
1 package Core::MysqlStatus;
2
3 use strict;
4 use warnings;
5
6 use base 'Resmon::Module';
7 use DBI;
8
9 =pod
10
11 =head1 NAME
12
13 Core::MysqlStatus - check MySQL global statistics
14
15 =head1 SYNOPSIS
16
17 Core::MysqlStatus {
18    127.0.0.1 : port => 3306, user => foo, pass => bar
19 }
20
21 =head1 DESCRIPTION
22
23 This module retrieves the SHOW GLOBAL STATUS of a MySQL service.
24
25 =head1 CONFIGURATION
26
27 =over
28
29 =item check_name
30
31 The target of the MySQL service.  This can be represented as an IP
32 address or FQDN.
33
34 =item port
35
36 The port that the target service listens on.  This defaults to 3306.
37
38 =item user
39
40 The username to connect as.  The user must have SELECT access to the
41 "mysql" database;
42
43 =item pass
44
45 The password to connect with.
46
47 =back
48
49 =head1 METRICS
50
51 This check returns a significant number of metrics.  There are too many to go
52 into detail here.  For more information, refer to the MySQL developer
53 documentation at http://dev.mysql.com/doc/.
54
55 =cut
56
57 sub handler {
58     my $self = shift;
59     my $config = $self->{'config'};
60     my $target = $self->{'check_name'};
61     my $port = $config->{'port'} || 3306;
62     my $user = $config->{'user'};
63     my $pass = $config->{'pass'};
64     my $dbh = DBI->connect("DBI:mysql::$target;port=$port", $user, $pass);
65
66     my $select_query = "SHOW GLOBAL STATUS";
67     my $sth = $dbh->prepare($select_query);
68     $sth->execute();
69
70     my %metrics;
71     while (my $result = $sth->fetchrow_hashref) {
72         $metrics{$result->{'Variable_name'}} = $result->{'Value'};
73     }
74
75     return \%metrics;
76 };
77
78 1;
Note: See TracBrowser for help on using the browser.