diff options
Diffstat (limited to 'src/pmdas/news')
-rw-r--r-- | src/pmdas/news/GNUmakefile | 53 | ||||
-rw-r--r-- | src/pmdas/news/Install | 28 | ||||
-rw-r--r-- | src/pmdas/news/README | 58 | ||||
-rw-r--r-- | src/pmdas/news/Remove | 29 | ||||
-rw-r--r-- | src/pmdas/news/active | 12 | ||||
-rw-r--r-- | src/pmdas/news/pmdanews.pl | 196 |
6 files changed, 376 insertions, 0 deletions
diff --git a/src/pmdas/news/GNUmakefile b/src/pmdas/news/GNUmakefile new file mode 100644 index 0000000..cd58095 --- /dev/null +++ b/src/pmdas/news/GNUmakefile @@ -0,0 +1,53 @@ +#!gmake +# +# Copyright (c) 2000-2001,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 +# + +TOPDIR = ../../.. +include $(TOPDIR)/src/include/builddefs + +IAM = news +PMDADIR = $(PCP_PMDAS_DIR)/$(IAM) +LSRCFILES = Install Remove README active 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: check_domain $(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) -m 644 README active $(PMDADIR) + @$(INSTALL_MAN) + +default_pcp : default + +install_pcp : install + +check_domain: ../../pmns/stdpmid + $(DOMAIN_PERLRULE) diff --git a/src/pmdas/news/Install b/src/pmdas/news/Install new file mode 100644 index 0000000..79032ea --- /dev/null +++ b/src/pmdas/news/Install @@ -0,0 +1,28 @@ +#! /bin/sh +# +# Copyright (c) 2000 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. +# +# Install the news PMDA and/or PMNS +# + +. $PCP_DIR/etc/pcp.env +. $PCP_SHARE_DIR/lib/pmdaproc.sh + +iam=news +perl_opt=true +daemon_opt=false +forced_restart=false + +pmdaSetup +pmdaInstall +exit 0 diff --git a/src/pmdas/news/README b/src/pmdas/news/README new file mode 100644 index 0000000..6f8466b --- /dev/null +++ b/src/pmdas/news/README @@ -0,0 +1,58 @@ +Usenet News PMDA +================ + +This PMDA is a sample, that illustrates how a simple PMDA might be +constructed using the Perl PMDA API. + +Although the metrics supported are simple, the framework in the script +pmdanews is quite general, and could be re-used to implement other +PMDAs. + +Metrics +======= + +Once the PMDA has been installed, the following command will list all +the available metrics and their explanatory "help" text: + + $ pminfo -fT news + +Installation +============ + + + # cd $PCP_PMDAS_DIR/news + + + Check that there is no clash in the Performance Metrics Domain + defined in ./domain.h and the other PMDAs currently in use (see + $PCP_PMCDCONF_PATH). If there is, edit ./domain.h to choose another + domain number. + + + Then simply use + + # ./Install + + and choose both the "collector" and "monitor" installation + configuration options. + + + By default the script pmdanews operates on a small test-case copy a + news "active" file, installed from here into + $PCP_PMDAS_DIR/news/active. If you wish to use a more realistic base + of Usenet data, edit pmdanews.pl to make it use your "live active" + groups, then + + # ./Install. + +De-installation +=============== + + + Simply use + + # cd $PCP_PMDAS_DIR/news + # ./Remove + +Troubleshooting +=============== + + + After installing or restarting the agent, the PMCD log file + ($PCP_LOG_DIR/pmcd/pmcd.log) and the PMDA log file + ($PCP_LOG_DIR/pmcd/news.log) should be checked for any warnings + or errors. diff --git a/src/pmdas/news/Remove b/src/pmdas/news/Remove new file mode 100644 index 0000000..a14cbc2 --- /dev/null +++ b/src/pmdas/news/Remove @@ -0,0 +1,29 @@ +#! /bin/sh +# +# Copyright (c) 2000 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 +# +# Remove the news PMDA +# + +. $PCP_DIR/etc/pcp.env +. $PCP_SHARE_DIR/lib/pmdaproc.sh + +iam=news + +pmdaSetup +pmdaRemove +exit 0 diff --git a/src/pmdas/news/active b/src/pmdas/news/active new file mode 100644 index 0000000..30ce528 --- /dev/null +++ b/src/pmdas/news/active @@ -0,0 +1,12 @@ +# fake for testing +# the metrics should be as follows +# news.articles.total 1000 +# news.articles.last 100 0 0 200 1101 3795 7130 +# news.articles.count 0 0 0 100 100 700 100 +comp.sys.sgi 0100 0100 y +comp.sys.sgi.graphics 0000 0000 y +comp.sys.sgi.hardware 0000 0000 y +sgi.bad-attitude 3795 3095 y +sgi.bugs.sherwood 1101 1001 y +sgi.engr.all 0200 0100 y +sgi.general 7130 7030 y diff --git a/src/pmdas/news/pmdanews.pl b/src/pmdas/news/pmdanews.pl new file mode 100644 index 0000000..9d59178 --- /dev/null +++ b/src/pmdas/news/pmdanews.pl @@ -0,0 +1,196 @@ +# +# Copyright (c) 2012 Red Hat. +# 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. +# + +use strict; +use warnings; +use PCP::PMDA; + +my @newsgroups = ( + 1, 'comp.sys.sgi', + 2, 'comp.sys.sgi.graphics', + 3, 'comp.sys.sgi.hardware', + 4, 'sgi.bad-attitude', + 5, 'sgi.engr.all', +); + +use vars qw( $total $news_regex %news_hash @news_count @news_last ); +my ($nnrpd_count, $rn_count, $trn_count, $xrn_count, $vn_count) = (0,0,0,0,0); +my $news_file = pmda_config('PCP_PMDAS_DIR') . '/news/active'; +my $news_indom = 0; +my $pmda; + +sub news_fetch # called once per ``fetch'' pdu, before callbacks +{ + my ( $group, $cmd ); + + $total = 0; + seek ACTIVE,0,0; + while (<ACTIVE>) { + next unless /$news_regex/; + $group = $news_hash{$1} - 1; + $news_last[$group] = $2; + $total += $news_count[$group] = $2 - $3; + } + + ($nnrpd_count, $rn_count, $trn_count, $xrn_count, $vn_count) = (0,0,0,0,0); + if (open(READERS, 'ps -ef |')) { + while (<READERS>) { + s/\b(:?\d\d:){2}\d\d\b/ Mmm DD /; # replace times with dates + s/\s*?(\S+?\s+?){8}//; # nuke the first eight fields + next unless /(\S+)\s*?/; # prepare $cmd with command name + $cmd = $1; + ($cmd eq 'in.nnrpd' || $cmd =~ /\/in\.nnrpd$/) && $nnrpd_count++; + ($cmd eq 'rn' || $cmd =~ /\/rn$/) && $rn_count++; + ($cmd eq 'trn' || $cmd =~ /\/trn$/) && $trn_count++; + ($cmd eq 'xrn' || $cmd =~ /\/xrn$/) && $xrn_count++; + ($cmd eq 'vn' || $cmd =~ /\/vrn$/) && $vn_count++; + } + close READERS; + } + else { + $pmda->log("Cannot execute 'ps' to count news reader processes"); + } +} + +sub news_fetch_callback # must return array of value,status +{ + my ($cluster, $item, $inst) = @_; + + return (PM_ERR_INST, 0) unless ( $inst == PM_IN_NULL || + ( $cluster == 0 && ($item == 301 || $item == 302) && + $inst > 0 && $inst <= ($#newsgroups+1)/2 ) ); + if ($cluster == 0) { + if ($item == 201) { ($total, 1); } # articles.total + elsif ($item == 301) { ($news_count[$inst-1], 1); } # articles.count + elsif ($item == 302) { ($news_last[$inst-1], 1); } # articles.last + elsif ($item == 101) { ($nnrpd_count, 1); } # readers.nnrpd + elsif ($item == 111) { ($rn_count, 1); } # readers.rn + elsif ($item == 112) { ($trn_count, 1); } # readers.trn + elsif ($item == 113) { ($xrn_count, 1); } # readers.xrn + elsif ($item == 114) { ($vn_count, 1); } # readers.vn + else { (PM_ERR_PMID, 0); } + } + else { (PM_ERR_PMID, 0); } +} + +sub news_init +{ + ($#newsgroups > 0 && $#newsgroups % 2 != 0) + || die "Invalid newsgroups array has been specified\n"; + open(ACTIVE, $news_file) || die "Can't open $news_file: $!\n"; + + # build regex using the given newsgroup names + $_ = "^($newsgroups[1]"; + $news_hash{$newsgroups[1]} = $newsgroups[0]; + for (my $i = 2; $i < $#newsgroups; $i += 2) { + $_ .= "|$newsgroups[$i+1]"; + $news_hash{$newsgroups[$i+1]} = $newsgroups[$i]; + } + $news_regex = $_ . ") (\\d+) (\\d+) y\$"; +} + +$pmda = PCP::PMDA->new('news', 28); + +$pmda->add_metric(pmda_pmid(0,201), PM_TYPE_U32, PM_INDOM_NULL, + PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), + 'news.articles.total', + 'Total number of articles received for each newsgroup', +'Total number of articles received for each newsgroup. +Note this is the historical running total, see news.articles.count for +the current total of un-expired articles by newsgroup.'); + +$pmda->add_metric(pmda_pmid(0,301), PM_TYPE_U32, $news_indom, + PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), + 'news.articles.count', + 'Total number of un-expired articles in each newsgroup', ''); + +$pmda->add_metric(pmda_pmid(0,302), PM_TYPE_U32, $news_indom, + PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), + 'news.articles.last', '', ''); +$pmda->add_metric(pmda_pmid(0,101), PM_TYPE_U32, PM_INDOM_NULL, + PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), + 'news.readers.nnrpd', '', ''); +$pmda->add_metric(pmda_pmid(0,111), PM_TYPE_U32, PM_INDOM_NULL, + PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), + 'news.readers.rn', '', ''); +$pmda->add_metric(pmda_pmid(0,112), PM_TYPE_U32, PM_INDOM_NULL, + PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), + 'news.readers.trn', '', ''); +$pmda->add_metric(pmda_pmid(0,113), PM_TYPE_U32, PM_INDOM_NULL, + PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), + 'news.readers.xrn', '', ''); +$pmda->add_metric(pmda_pmid(0,114), PM_TYPE_U32, PM_INDOM_NULL, + PM_SEM_INSTANT, pmda_units(0,0,1,0,0,PM_COUNT_ONE), + 'news.readers.vn', '', ''); + +$pmda->add_indom($news_indom, \@newsgroups, '', ''); + +$pmda->set_fetch(\&news_fetch); +$pmda->set_fetch_callback(\&news_fetch_callback); + +&news_init; + +$pmda->set_user('pcp'); +$pmda->run; + +=pod + +=head1 NAME + +pmdanews - sample Usenet news performance metrics domain agent (PMDA) + +=head1 DESCRIPTION + +B<pmdanews> is an example Performance Metrics Domain Agent (PMDA) which +exports metric values related to a set of newsgroups. + +=head1 INSTALLATION + +If you want access to the names and values for the news performance +metrics, do the following as root: + + # cd $PCP_PMDAS_DIR/news + # ./Install + +If you want to undo the installation, do the following as root: + + # cd $PCP_PMDAS_DIR/news + # ./Remove + +B<pmdanews> 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/news/Install + +installation script for the B<pmdanews> agent + +=item $PCP_PMDAS_DIR/news/Remove + +undo installation script for the B<pmdanews> agent + +=item $PCP_LOG_DIR/pmcd/news.log + +default log file for error messages from B<pmdanews> + +=back + +=head1 SEE ALSO + +pmcd(1). |