root/lib/Core/MysqlStatus.pm

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

MysqlStatus? retrieves the SHOW GLOBAL STATUS of a MySQL service

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@301 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 =over
52
53 This check returns a significant number of metrics.  There are too many to go
54 into detail here.  For more information, refer to the MySQL developer
55 documentation at http://dev.mysql.com/doc/.
56
57 =back
58
59 =cut
60
61 sub handler {
62     my $self = shift;
63     my $config = $self->{'config'};
64     my $target = $self->{'check_name'};
65     my $port = $config->{'port'} || 3306;
66     my $user = $config->{'user'};
67     my $pass = $config->{'pass'};
68     my $dbh = DBI->connect("DBI:mysql::$target;port=$port", $user, $pass);
69
70     my $select_query = "SHOW GLOBAL STATUS";
71     my $sth = $dbh->prepare($select_query);
72     $sth->execute();
73
74     my %metrics;
75     while (my $result = $sth->fetchrow_hashref) {
76         $metrics{$result->{'Variable_name'}} = $result->{'Value'};
77     }
78
79     return { %metrics };
80 };
81
82 1;
Note: See TracBrowser for help on using the browser.