pcp
[Top] [All Lists]

[PATCH] Add a new PMDA exporting the Postfix queue lengths

To: pcp@xxxxxxxxxxx
Subject: [PATCH] Add a new PMDA exporting the Postfix queue lengths
From: "Josef 'Jeff' Sipek" <jeffpc@xxxxxxxxxxxxxx>
Date: Sun, 16 Aug 2009 16:20:19 -0400
Cc: "Josef 'Jeff' Sipek" <jeffpc@xxxxxxxxxxxxxx>, nathans@xxxxxxxxxx
Cc: nathans@xxxxxxxxxx
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@xxxxxxxxxxxxxx>
---
 src/pmdas/GNUmakefile            |    2 +-
 src/pmdas/postfix/.gitignore     |    2 +
 src/pmdas/postfix/GNUmakefile    |   45 ++++++++++
 src/pmdas/postfix/Install        |   27 ++++++
 src/pmdas/postfix/Remove         |   25 ++++++
 src/pmdas/postfix/pmdapostfix.pl |  164 ++++++++++++++++++++++++++++++++++++++
 src/pmns/stdpmid.pcp             |    1 +
 7 files changed, 265 insertions(+), 1 deletions(-)
 create mode 100644 src/pmdas/postfix/.gitignore
 create mode 100644 src/pmdas/postfix/GNUmakefile
 create mode 100755 src/pmdas/postfix/Install
 create mode 100755 src/pmdas/postfix/Remove
 create mode 100644 src/pmdas/postfix/pmdapostfix.pl

diff --git a/src/pmdas/GNUmakefile b/src/pmdas/GNUmakefile
index 8230be9..161ea65 100644
--- a/src/pmdas/GNUmakefile
+++ b/src/pmdas/GNUmakefile
@@ -22,7 +22,7 @@ SUBDIRS = pmcd linux solaris aix darwin windows \
        lmsensors process roomtemp summary hotproc jstat \
        dbping memcache systemtap mysql vmware kvm ib \
        bonding cluster lustrecomm mmv netfilter zimbra \
-       named pdns
+       named pdns postfix
 
 LDIRT = pmcd.conf
 
diff --git a/src/pmdas/postfix/.gitignore b/src/pmdas/postfix/.gitignore
new file mode 100644
index 0000000..9515eb3
--- /dev/null
+++ b/src/pmdas/postfix/.gitignore
@@ -0,0 +1,2 @@
+pmdapostfix.1
+pmdapostfix.1.gz
diff --git a/src/pmdas/postfix/GNUmakefile b/src/pmdas/postfix/GNUmakefile
new file mode 100644
index 0000000..535e07e
--- /dev/null
+++ b/src/pmdas/postfix/GNUmakefile
@@ -0,0 +1,45 @@
+#!gmake
+#
+# Copyright (c) 2009 Josef 'Jeff' Sipek <jeffpc@xxxxxxxxxxxxxx>
+#
+# 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.
+#
+
+TOPDIR = ../../..
+include $(TOPDIR)/src/include/builddefs
+
+IAM    = postfix
+PMDADIR        = $(PCP_PMDAS_DIR)/$(IAM)
+LSRCFILES = Install Remove pmda$(IAM).pl
+LDIRT  = domain.h root pmns *.log $(MAN_PAGES)
+
+ifneq ($(POD2MAN),)
+MAN_SECTION = 1
+MAN_PAGES = pmda$(IAM).$(MAN_SECTION)
+MAN_DEST = $(PCP_MAN_DIR)/man$(MAN_SECTION)
+endif
+
+default: $(MAN_PAGES)
+
+pmda$(IAM).1: pmda$(IAM).pl
+       $(POD_MAKERULE)
+
+include $(BUILDRULES)
+
+install: default
+       $(INSTALL) -m 755 -d $(PMDADIR)
+       $(INSTALL) -m 755 Install Remove $(PMDADIR)
+       $(INSTALL) -m 644 pmda$(IAM).pl $(PMDADIR)/pmda$(IAM).pl
+       @$(INSTALL_MAN)
+
+default_pcp : default
+
+install_pcp : install
diff --git a/src/pmdas/postfix/Install b/src/pmdas/postfix/Install
new file mode 100755
index 0000000..85477c8
--- /dev/null
+++ b/src/pmdas/postfix/Install
@@ -0,0 +1,27 @@
+#! /bin/sh
+#
+# Copyright (c) 2009 Josef 'Jeff' Sipek <jeffpc@xxxxxxxxxxxxxx>
+#
+# 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 postfix PMDA
+#
+
+. $PCP_DIR/etc/pcp.env
+. $PCP_SHARE_DIR/lib/pmdaproc.sh
+
+iam=postfix
+perl_opt=true
+daemon_opt=false
+
+pmdaSetup
+pmdaInstall
+exit 0
diff --git a/src/pmdas/postfix/Remove b/src/pmdas/postfix/Remove
new file mode 100755
index 0000000..5d06c62
--- /dev/null
+++ b/src/pmdas/postfix/Remove
@@ -0,0 +1,25 @@
+#! /bin/sh
+#
+# Copyright (c) 2009 Josef 'Jeff' Sipek <jeffpc@xxxxxxxxxxxxxx>
+#
+# 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.
+#
+# Remove the postfix PMDA
+#
+
+. $PCP_DIR/etc/pcp.env
+. $PCP_SHARE_DIR/lib/pmdaproc.sh
+
+iam=postfix
+
+pmdaSetup
+pmdaRemove
+exit 0
diff --git a/src/pmdas/postfix/pmdapostfix.pl b/src/pmdas/postfix/pmdapostfix.pl
new file mode 100644
index 0000000..3f15f59
--- /dev/null
+++ b/src/pmdas/postfix/pmdapostfix.pl
@@ -0,0 +1,164 @@
+#
+# Copyright (c) 2009 Josef 'Jeff' Sipek <jeffpc@xxxxxxxxxxxxxx>
+#
+# 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.
+#
+
+use strict;
+use warnings;
+use PCP::PMDA;
+use Time::HiRes qw ( time );
+
+use vars qw( $pmda );
+use vars qw( %caches );
+my $qshape = 'qshape -b 10 -t 5';
+my $refresh = 5; # 5 seconds between refreshes
+
+sub postfix_timer_callback
+{
+       my @items;
+
+       foreach my $qname ("maildrop", "incoming", "hold", "active", 
"deferred") {
+               open(PIPE, "$qshape $qname |") || die "couldn't execute 
'$qshape $qname'";
+               while(<PIPE>) {
+                       last if (/^[\t ]*TOTAL /);
+               }
+               close PIPE;
+
+               die "malformed output for '$qshape $qname'" unless (/^[\t 
]*TOTAL /);
+
+               s/^[\t ]*//;
+               s/[\t ]+/ /g;
+
+               @items = split(/ /);
+
+               $caches{$qname}{0}  = $items[1];
+               $caches{$qname}{1}  = $items[2];
+               $caches{$qname}{2}  = $items[3];
+               $caches{$qname}{3}  = $items[4];
+               $caches{$qname}{4}  = $items[5];
+               $caches{$qname}{5}  = $items[6];
+               $caches{$qname}{6}  = $items[7];
+               $caches{$qname}{7}  = $items[8];
+               $caches{$qname}{8}  = $items[9];
+               $caches{$qname}{9}  = $items[10];
+               $caches{$qname}{10} = $items[11];
+       }
+}
+
+sub postfix_fetch_callback
+{
+       my ($cluster, $item, $inst) = @_;
+       my $metric_name = pmda_pmid_name($cluster, $item);
+       my ($qname);
+
+       # $pmda->log("postfix_fetch_callback $metric_name $cluster:$item 
($inst)\n");
+
+       if (!defined($metric_name))    { return (PM_ERR_PMID, 0); }
+
+       if ($cluster == 0) {
+               $qname = $metric_name;
+               $qname =~ s/^postfix\.queues\.//;
+
+               return (PM_ERR_AGAIN, 0) unless defined($caches{$qname});
+               return ($caches{$qname}{$inst}, 1);
+       }
+
+       return (PM_ERR_PMID, 0);
+}
+
+my $postfix_queues_indom = 0;
+my @postfix_queues_dom = (     0 => 'total',
+                               1 => '0-5 mins',
+                               2 => '5-10 mins',
+                               3 => '10-20 mins',
+                               4 => '20-40 mins',
+                               5 => '40-80 mins',
+                               6 => '80-160 mins',
+                               7 => '160-320 mins',
+                               8 => '320-640 mins',
+                               9 => '640-1280 mins',
+                               10=> '1280+ mins',
+                        );
+
+$pmda = PCP::PMDA->new('postfix', 102);
+
+$pmda->add_metric(pmda_pmid(0,0), PM_TYPE_U32, $postfix_queues_indom, 
PM_SEM_INSTANT,
+                pmda_units(0,0,1,0,0,PM_COUNT_ONE),
+                "postfix.queues.maildrop", '', '');
+$pmda->add_metric(pmda_pmid(0,1), PM_TYPE_U32, $postfix_queues_indom, 
PM_SEM_INSTANT,
+                pmda_units(0,0,1,0,0,PM_COUNT_ONE),
+                "postfix.queues.incoming", '', '');
+$pmda->add_metric(pmda_pmid(0,2), PM_TYPE_U32, $postfix_queues_indom, 
PM_SEM_INSTANT,
+                pmda_units(0,0,1,0,0,PM_COUNT_ONE),
+                "postfix.queues.hold", '', '');
+$pmda->add_metric(pmda_pmid(0,3), PM_TYPE_U32, $postfix_queues_indom, 
PM_SEM_INSTANT,
+                pmda_units(0,0,1,0,0,PM_COUNT_ONE),
+                "postfix.queues.active", '', '');
+$pmda->add_metric(pmda_pmid(0,4), PM_TYPE_U32, $postfix_queues_indom, 
PM_SEM_INSTANT,
+                pmda_units(0,0,1,0,0,PM_COUNT_ONE),
+                "postfix.queues.deferred", '', '');
+
+$pmda->add_indom($postfix_queues_indom, \@postfix_queues_dom, '', '');
+
+$pmda->add_timer($refresh, \&postfix_timer_callback, 0);
+$pmda->set_fetch_callback(\&postfix_fetch_callback);
+$pmda->run;
+
+=pod
+
+=head1 NAME
+
+pmdapostfix - Postfix performance metrics domain agent (PMDA)
+
+=head1 DESCRIPTION
+
+B<pmdapostfix> is a Performance Metrics Domain Agent (PMDA) which exports
+mail queue sizes as reported by qshape(1).
+
+=head1 INSTALLATION
+
+If you want access to the names and values for the Postfix performance
+metrics, do the following as root:
+
+        # cd $PCP_PMDAS_DIR/postfix
+        # ./Install
+
+If you want to undo the installation, do the following as root:
+
+        # cd $PCP_PMDAS_DIR/postfix
+        # ./Remove
+
+B<pmdapostfix> 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/postfix/Install
+
+installation script for the B<pmdapostfix> agent
+
+=item $PCP_PMDAS_DIR/postfix/Remove
+
+undo installation script for the B<pmdapostfix> agent
+
+=item $PCP_LOG_DIR/pmcd/postfix.log
+
+default log file for error messages from B<pmdapostfix>
+
+=back
+
+=head1 SEE ALSO
+
+pmcd(1) and qshape(1).
diff --git a/src/pmns/stdpmid.pcp b/src/pmns/stdpmid.pcp
index 6f9a493..e4bbb09 100644
--- a/src/pmns/stdpmid.pcp
+++ b/src/pmns/stdpmid.pcp
@@ -78,6 +78,7 @@ ZIMBRA                98
 UV             99
 NAMED          100
 PDNS           101
+POSTFIX                102
 ### NEXT FREE SLOT ###
 DBPING         244
 COUNTD         245
-- 
1.6.2.4

<Prev in Thread] Current Thread [Next in Thread>
  • [PATCH] Add a new PMDA exporting the Postfix queue lengths, Josef 'Jeff' Sipek <=