pcp
[Top] [All Lists]

MySQL PMDA Does not re-connect after a MySQL re-start

To: pcp@xxxxxxxxxxx
Subject: MySQL PMDA Does not re-connect after a MySQL re-start
From: Chandana De Silva <chandana@xxxxxxxxxxxxx>
Date: Sun, 23 Dec 2012 18:37:57 +1100
Reply-to: chandana@xxxxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0
The MySQL PMDA dies if the MySQL database is re-started, or if some other error error occurs while fetching data.

I have got a preliminary fix for this, which works for the database re-start use case.

Chandana

--- pmdamysql.pl.orig   2012-12-23 18:18:27.438466152 +1100
+++ pmdamysql.pl        2012-12-23 18:17:54.996470514 +1100
@@ -42,6 +42,9 @@
     if (!defined($dbh)) {
        $dbh = DBI->connect($database, $username, $password);
        if (defined($dbh)) {
+        # set the db handle to undef in case of any failure
+        # this will force a database reconnect
+        $dbh->{HandleError} = sub { $dbh = undef; };
            $pmda->log("MySQL connection established\n");
            $sth_variables = $dbh->prepare('show variables');
            $sth_status = $dbh->prepare('show status');
@@ -1838,3 +1841,4 @@
 =head1 SEE ALSO

 pmcd(1), pmdadbping.pl(1) and DBI(3).
+# vi: sw=4 ts=4 et

PMCD - MySQL log output:
--------------------------
[Sun Dec 23 18:23:17] pmdamysql(16160) Info: MySQL connection established

DBD::mysql::st execute failed: MySQL server has gone away at /var/lib/pcp/pmdas/mysql/pmdamysql.pl line 77. DBD::mysql::st fetchall_arrayref failed: fetch() without execute() at /var/lib/pcp/pmdas/mysql/pmdamysql.pl line 78. DBI connect('mysql','root',...) failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) adas/mysql/pmdamysql.pl line 43 DBI connect('mysql','root',...) failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) adas/mysql/pmdamysql.pl line 43 DBI connect('mysql','root',...) failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) adas/mysql/pmdamysql.pl line 43 DBI connect('mysql','root',...) failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) adas/mysql/pmdamysql.pl line 43 DBI connect('mysql','root',...) failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) adas/mysql/pmdamysql.pl line 43
[Sun Dec 23 18:27:33] pmdamysql(16160) Info: MySQL connection established

Test using pmval
----------------
pmval mysql.status.uptime

metric:    mysql.status.uptime
host:      localhost
semantics: cumulative counter (converting to rate)
units:     sec (converting to time utilization)
samples:   all
     0.9932
     0.9973
     0.9927
     0.9932

pmval: pmFetch: Metric not supported by this version of monitored application

pmval: pmFetch: Metric not supported by this version of monitored application

pmval: pmFetch: Metric not supported by this version of monitored application

pmval: pmFetch: Metric not supported by this version of monitored application

pmval: pmFetch: Metric not supported by this version of monitored application

pmval: pmFetch: Metric not supported by this version of monitored application
No values available
     0.9931
     0.9931
     0.9931
     0.9934
     0.9932
     0.9933
     0.9932
     0.9930
     0.9930
^C

<Prev in Thread] Current Thread [Next in Thread>
  • MySQL PMDA Does not re-connect after a MySQL re-start, Chandana De Silva <=