summaryrefslogtreecommitdiff
path: root/src/pmdas/dbping
diff options
context:
space:
mode:
Diffstat (limited to 'src/pmdas/dbping')
-rw-r--r--src/pmdas/dbping/GNUmakefile56
-rwxr-xr-xsrc/pmdas/dbping/Install36
-rwxr-xr-xsrc/pmdas/dbping/Remove29
-rw-r--r--src/pmdas/dbping/dbprobe.pl93
-rw-r--r--src/pmdas/dbping/pmdadbping.pl192
5 files changed, 406 insertions, 0 deletions
diff --git a/src/pmdas/dbping/GNUmakefile b/src/pmdas/dbping/GNUmakefile
new file mode 100644
index 0000000..43044e3
--- /dev/null
+++ b/src/pmdas/dbping/GNUmakefile
@@ -0,0 +1,56 @@
+#!gmake
+#
+# Copyright (c) 2008 Aconex. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+TOPDIR = ../../..
+include $(TOPDIR)/src/include/builddefs
+
+IAM = dbping
+DOMAIN = DBPING
+PMDADIR = $(PCP_PMDAS_DIR)/$(IAM)
+LSRCFILES = Install Remove dbprobe.pl pmda$(IAM).pl
+
+ifneq ($(POD2MAN),)
+MAN_SECTION = 1
+MAN_PAGES = pmda$(IAM).$(MAN_SECTION) dbprobe.$(MAN_SECTION)
+MAN_DEST = $(PCP_MAN_DIR)/man$(MAN_SECTION)
+endif
+
+LDIRT = domain.h root pmns *.log $(MAN_PAGES)
+
+default: check_domain $(MAN_PAGES)
+
+pmda$(IAM).1: pmda$(IAM).pl
+ $(POD_MAKERULE)
+dbprobe.1: dbprobe.pl
+ $(POD_MAKERULE)
+
+include $(BUILDRULES)
+
+install: default
+ $(INSTALL) -m 755 -d $(PMDADIR)
+ $(INSTALL) -m 755 Install Remove $(PMDADIR)
+ $(INSTALL) -m 644 pmda$(IAM).pl dbprobe.pl $(PMDADIR)
+ @$(INSTALL_MAN)
+
+default_pcp : default
+
+install_pcp : install
+
+check_domain: ../../pmns/stdpmid
+ $(DOMAIN_PERLRULE)
diff --git a/src/pmdas/dbping/Install b/src/pmdas/dbping/Install
new file mode 100755
index 0000000..09f5432
--- /dev/null
+++ b/src/pmdas/dbping/Install
@@ -0,0 +1,36 @@
+#! /bin/sh
+#
+# Copyright (c) 2008 Aconex. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# Install the Database Ping PMDA
+#
+
+. $PCP_DIR/etc/pcp.env
+. $PCP_SHARE_DIR/lib/pmdaproc.sh
+
+iam=dbping
+dso_opt=false
+perl_opt=true
+daemon_opt=false
+forced_restart=false
+
+perl -e "use DBI" 2>/dev/null
+if test $? -ne 0; then
+ echo "Perl database interface (DBI) is not installed"
+ exit 1
+fi
+
+pmdaSetup
+pmdaInstall
+
+exit 0
diff --git a/src/pmdas/dbping/Remove b/src/pmdas/dbping/Remove
new file mode 100755
index 0000000..7924339
--- /dev/null
+++ b/src/pmdas/dbping/Remove
@@ -0,0 +1,29 @@
+#! /bin/sh
+#
+# Copyright (c) 2008 Aconex. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Remove the Database Ping PMDA
+#
+
+. $PCP_DIR/etc/pcp.env
+. $PCP_SHARE_DIR/lib/pmdaproc.sh
+
+iam=dbping
+pmdaSetup
+pmdaRemove
+
+exit 0
diff --git a/src/pmdas/dbping/dbprobe.pl b/src/pmdas/dbping/dbprobe.pl
new file mode 100644
index 0000000..5f822dc
--- /dev/null
+++ b/src/pmdas/dbping/dbprobe.pl
@@ -0,0 +1,93 @@
+#
+# Copyright (c) 2008 Aconex. All Rights Reserved.
+# Copyright (c) 2004 Silicon Graphics, Inc. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+use strict;
+use warnings;
+use DBI;
+use PCP::PMDA qw(pmda_config);
+use Time::HiRes qw(gettimeofday);
+
+my $database = 'DBI:mysql:mysql';
+my $username = 'dbmonitor';
+my $password = 'dbmonitor';
+my $response = 'SELECT 1';
+my $delay = $ARGV[0]; # delay in seconds between database ping's
+$delay = 60 unless defined($delay);
+
+# Configuration files for overriding the above settings
+for my $file ( '/etc/pcpdbi.conf', # system defaults (lowest priority)
+ pmda_config('PCP_PMDAS_DIR') . '/dbping/dbprobe.conf',
+ './dbprobe.conf' ) { # current directory (high priority)
+ eval `cat $file` unless ! -f $file;
+}
+
+use vars qw( $pmda $dbh $sth );
+
+sub dbping { # must return array of (response_time, status, time_stamp)
+ my $before;
+
+ if (!defined($dbh)) { # reconnect if necessary
+ $dbh = DBI->connect($database, $username, $password, undef) || return;
+ $pmda->log("Connected to database.\n");
+ undef $sth;
+ }
+ if (!defined($sth)) { # prepare SQL statement once only
+ $sth = $dbh->prepare($response) || return;
+ }
+ $before = gettimeofday;
+ $sth->execute || return;
+ while (my @row = $sth->fetchrow_array) {
+ ($sth->err) && return;
+ }
+
+ my $timenow = localtime;
+ print "$timenow\t", gettimeofday - $before, "\n";
+}
+
+$dbh = DBI->connect($database, $username, $password, undef) ||
+ $pmda->log("Failed initial connect: $dbh->errstr\n");
+
+$| = 1; # IMPORTANT! Enables auto-flush, for piping hot pipes.
+for (;;) {
+ dbping;
+ sleep($delay);
+}
+
+=pod
+
+=head1 NAME
+
+dbprobe.pl - database response time and availability information
+
+=head1 SYNOPSIS
+
+dbprobe.pl [ delay ]
+
+=head1 DESCRIPTION
+
+The B<dbprobe.pl> utility is used by pmdadbping(1) to measure
+response time from a database. A given query is executed on
+the database at the requested interval (I<delay>, which defaults
+to 60 seconds). This response time measure can be exported
+via the Performance Co-Pilot framework for live and historical
+monitoring using pmdadbping(1).
+
+=head1 SEE ALSO
+
+pmcd(1), pmdadbping(1) and DBI(3).
diff --git a/src/pmdas/dbping/pmdadbping.pl b/src/pmdas/dbping/pmdadbping.pl
new file mode 100644
index 0000000..ec8f2a0
--- /dev/null
+++ b/src/pmdas/dbping/pmdadbping.pl
@@ -0,0 +1,192 @@
+#
+# Copyright (c) 2004 Silicon Graphics, Inc. All Rights Reserved.
+# Copyright (c) 2008 Aconex. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+use strict;
+use warnings;
+use PCP::PMDA;
+use vars qw( $pmda $stamp $response $status $timestamp );
+
+my $delay = $ARGV[0]; # delay in seconds between database ping's
+$delay = 60 unless defined($delay);
+my $dbprobe = pmda_config('PCP_PMDAS_DIR') . '/dbping/dbprobe.pl';
+$dbprobe = "perl " . $dbprobe . " $delay";
+my ( $stamp, $response, $status, $timestamp ) = ( 0, 0, 1, 0 );
+
+sub dbping_probe_callback
+{
+ ( $_ ) = @_;
+ ($stamp, $response) = split(/\t/);
+
+ # $pmda->log("dbping_probe_callback: time=$stamp resp=$response\n");
+
+ if (defined($stamp) && defined($response)) {
+ $timestamp = $stamp;
+ $status = 0;
+ } else {
+ $response = -1;
+ $status = 1; # bad result, keep old $timestamp
+ }
+}
+
+sub dbping_fetch_callback # must return array of value,status
+{
+ my ($cluster, $item, $inst) = @_;
+
+ # $pmda->log("dbping_fetch_callback $cluster:$item ($inst)\n");
+
+ return (PM_ERR_INST, 0) unless ($inst == PM_IN_NULL);
+
+ if ($cluster == 0) {
+ if ($item == 0) { return ($response, 1); }
+ elsif ($item == 1) { return ($status, 1); }
+ }
+ elsif ($cluster == 1) {
+ if ($item == 0) { return ($timestamp, 1); }
+ elsif ($item == 1) { return ($delay, 1); }
+ }
+ return (PM_ERR_PMID, 0);
+}
+
+sub dbping_store_callback # must return a single value (scalar context)
+{
+ my ($cluster, $item, $inst, $val) = @_;
+ my $sts = 0;
+
+ # $pmda->log("dbping_store_callback $cluster:$item ($inst) $val\n");
+
+ if ($cluster == 1 && $item == 1) {
+ $delay = $val;
+ return 0;
+ }
+ elsif ( ($cluster == 0 && ($item == 0 || $item == 1))
+ || ($cluster == 1 && $item == 0) ) {
+ return PM_ERR_PERMISSION;
+ }
+ return PM_ERR_PMID;
+}
+
+$pmda = PCP::PMDA->new('dbping', 244);
+
+$pmda->add_metric(pmda_pmid(0,0), PM_TYPE_DOUBLE, PM_INDOM_NULL,
+ PM_SEM_INSTANT, pmda_units(0,1,0,0,PM_TIME_SEC,0),
+ 'dbping.response_time',
+ 'Length of time taken to access the database', '');
+$pmda->add_metric(pmda_pmid(0,1), PM_TYPE_32, PM_INDOM_NULL,
+ PM_SEM_INSTANT, pmda_units(0,0,0,0,0,0),
+ 'dbping.status',
+ 'Success state of last attempt to ping the database', '');
+$pmda->add_metric(pmda_pmid(1,0), PM_TYPE_STRING, PM_INDOM_NULL,
+ PM_SEM_INSTANT, pmda_units(0,0,0,0,0,0),
+ 'dbping.control.timestamp',
+ 'Time of last successful database ping', '');
+$pmda->add_metric(pmda_pmid(1,1), PM_TYPE_U32, PM_INDOM_NULL,
+ PM_SEM_INSTANT, pmda_units(0,1,0,0,PM_TIME_SEC,0),
+ 'dbping.control.delay',
+ 'Time to sleep between database ping attempts', '');
+$pmda->set_fetch_callback( \&dbping_fetch_callback );
+$pmda->set_store_callback( \&dbping_store_callback );
+$pmda->add_pipe( $dbprobe, \&dbping_probe_callback, 0 );
+$pmda->set_user('pcp');
+$pmda->run;
+
+=pod
+
+=head1 NAME
+
+pmdadbping - database response time and availability PMDA
+
+=head1 DESCRIPTION
+
+Simple database response time measurement PMDA. dbprobe.pl(1)
+should be configured to use the type of DBI appropriate
+for your database, which includes: RDBMS flavour, user/password,
+delay between "ping" requests, and the SQL statement to use.
+B<pmdadbping> runs dbprobe.pl(1), and exports the performance
+measurements it makes available as PCP metrics.
+
+=head1 INSTALLATION
+
+Configure dbprobe.pl(1) - it uses a configuration file from
+(in this order):
+
+=over
+
+=item * /etc/pcpdbi.conf
+
+=item * $PCP_PMDAS_DIR/dbping/dbprobe.conf
+
+=back
+
+This file can contain overridden values (Perl code) for the settings
+listed at the start of dbprobe.pl, namely:
+
+=over
+
+=item * database name (see DBI(3) for details)
+
+=item * database user name
+
+=item * database pass word
+
+=item * SQL statement to measure (probe)
+
+=item * delay between probes
+
+=back
+
+Once this is setup, you can access the names and values for the
+dbping performance metrics by doing the following as root:
+
+ # cd $PCP_PMDAS_DIR/dbping
+ # ./Install
+
+If you want to undo the installation, do the following as root:
+
+ # cd $PCP_PMDAS_DIR/dbping
+ # ./Remove
+
+B<pmdadbping> is launched by pmcd(1) and should never be executed
+directly. The Install and Remove scripts notify pmcd(1) when
+the agent is installed or removed.
+
+=head1 FILES
+
+=over
+
+=item $PCP_PMDAS_DIR/dbping/probes.stp
+
+probe configuration file for stap(1), run by B<pmdadbping>
+
+=item $PCP_PMDAS_DIR/dbping/Install
+
+installation script for the B<pmdadbping> agent
+
+=item $PCP_PMDAS_DIR/dbping/Remove
+
+undo installation script for the B<pmdadbping> agent
+
+=item $PCP_LOG_DIR/pmcd/dbping.log
+
+default log file for error messages from B<pmdadbping>
+
+=back
+
+=head1 SEE ALSO
+
+pmcd(1), dbprobe.pl(1) and DBI(3).