summaryrefslogtreecommitdiff
path: root/src/pmdas/trivial
diff options
context:
space:
mode:
Diffstat (limited to 'src/pmdas/trivial')
-rw-r--r--src/pmdas/trivial/GNUmakefile43
-rw-r--r--src/pmdas/trivial/GNUmakefile.install51
-rw-r--r--src/pmdas/trivial/Install27
-rw-r--r--src/pmdas/trivial/README63
-rw-r--r--src/pmdas/trivial/Remove38
-rw-r--r--src/pmdas/trivial/help35
-rw-r--r--src/pmdas/trivial/pmns23
-rw-r--r--src/pmdas/trivial/root10
-rw-r--r--src/pmdas/trivial/trivial.c138
9 files changed, 428 insertions, 0 deletions
diff --git a/src/pmdas/trivial/GNUmakefile b/src/pmdas/trivial/GNUmakefile
new file mode 100644
index 0000000..dfa9d8c
--- /dev/null
+++ b/src/pmdas/trivial/GNUmakefile
@@ -0,0 +1,43 @@
+#
+# Copyright (c) 2012 Red Hat.
+# Copyright (c) 2000,2003,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.
+#
+
+TOPDIR = ../../..
+include $(TOPDIR)/src/include/builddefs
+
+DFILES = README
+CFILES = trivial.c
+CMDTARGET = pmdatrivial$(EXECSUFFIX)
+LLDLIBS = $(PCP_PMDALIB)
+LCFLAGS = -I.
+LSRCFILES = Install Remove pmns help $(DFILES) root GNUmakefile.install
+
+IAM = trivial
+DOMAIN = TRIVIAL
+PMDADIR = $(PCP_PMDAS_DIR)/$(IAM)
+
+LDIRT = domain.h *.o $(IAM).log pmda$(IAM) pmda_$(IAM).so
+
+default_pcp default: domain.h $(CMDTARGET)
+
+include $(BUILDRULES)
+
+install install_pcp: default
+ $(INSTALL) -m 755 -d $(PMDADIR)
+ $(INSTALL) -m 755 Install Remove $(PMDADIR)
+ $(INSTALL) -m 644 GNUmakefile.install $(PMDADIR)/Makefile
+ $(INSTALL) -m 644 $(DFILES) root help pmns domain.h $(CFILES) $(PMDADIR)
+
+domain.h: ../../pmns/stdpmid
+ $(DOMAIN_MAKERULE)
diff --git a/src/pmdas/trivial/GNUmakefile.install b/src/pmdas/trivial/GNUmakefile.install
new file mode 100644
index 0000000..92f1351
--- /dev/null
+++ b/src/pmdas/trivial/GNUmakefile.install
@@ -0,0 +1,51 @@
+#
+# Copyright (c) 2000,2003,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.
+#
+
+SHELL = sh
+
+ifdef PCP_CONF
+include $(PCP_CONF)
+else
+include $(PCP_DIR)/etc/pcp.conf
+endif
+include $(PCP_INC_DIR)/builddefs
+
+# remove -Lpath and -Ipath options from builddefs CFLAGS value
+#
+PCP_LIBS =
+TMP := $(CFLAGS:-I%=)
+ifdef PCP_DIR
+# put -Ipath and -Lpath back but use paths for run-time environment
+#
+CFLAGS = $(TMP) -I$(PCP_INC_DIR)/..
+LDFLAGS = -L$(PCP_LIB_DIR)
+else
+CFLAGS = $(TMP)
+endif
+
+IAM = trivial
+CFILES = $(IAM).c
+
+LIBTARGET = pmda_$(IAM).$(DSOSUFFIX)
+CMDTARGET = pmda$(IAM)
+TARGETS = $(LIBTARGET) $(CMDTARGET)
+
+LLDLIBS = -lpcp_pmda -lpcp $(LIB_FOR_MATH) $(LIB_FOR_PTHREADS)
+LDIRT = *.log help.dir help.pag
+
+default: $(TARGETS)
+
+install: default
+
+include $(PCP_INC_DIR)/buildrules
diff --git a/src/pmdas/trivial/Install b/src/pmdas/trivial/Install
new file mode 100644
index 0000000..02fb13a
--- /dev/null
+++ b/src/pmdas/trivial/Install
@@ -0,0 +1,27 @@
+#! /bin/sh
+#
+# Copyright (c) 1997 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 trivial PMDA and/or PMNS
+#
+
+. $PCP_DIR/etc/pcp.env
+. $PCP_SHARE_DIR/lib/pmdaproc.sh
+
+iam=trivial
+pmda_interface=2
+forced_restart=false
+
+pmdaSetup
+pmdaInstall
+exit 0
diff --git a/src/pmdas/trivial/README b/src/pmdas/trivial/README
new file mode 100644
index 0000000..9561cc6
--- /dev/null
+++ b/src/pmdas/trivial/README
@@ -0,0 +1,63 @@
+Trivial PMDA
+============
+
+This PMDA is a sample that illustrates how a simple PMDA might be
+constructed using libpcp_pmda.
+
+Although the metrics supported as simple, the framework is quite
+general, and could be extended to implement a much more complex PMDA.
+
+Note:
+ This PMDA may be remade from source and hence requires IDO (or
+ more specifically a C compiler) to be installed.
+
+ Uses of make(1) may fail (without removing or clobbering files)
+ if the C compiler cannot be found. This is most likely to
+ happen when running the PMDA ./Install script.
+
+ The only remedial action is to install the C compiler, or
+ hand-craft changes to the Makefile.
+
+Metrics
+=======
+
+The file ./help contains descriptions for all of the metrics exported
+by this PMDA.
+
+Once the PMDA has been installed, the following command will list all
+the available metrics and their explanatory "help" text:
+
+ $ pminfo -fT trivial
+
+Installation
+============
+
+ + # cd $PCP_PMDAS_DIR/trivial
+
+ + 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 -- everything else is automated.
+
+De-installation
+===============
+
+ + Simply use
+
+ # cd $PCP_PMDAS_DIR/trivial
+ # ./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/trivial.log) should be checked for any warnings
+ or errors.
diff --git a/src/pmdas/trivial/Remove b/src/pmdas/trivial/Remove
new file mode 100644
index 0000000..7de9372
--- /dev/null
+++ b/src/pmdas/trivial/Remove
@@ -0,0 +1,38 @@
+#! /bin/sh
+#
+# Copyright (c) 1997 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 trivial PMDA
+#
+
+# source the PCP configuration environment variables
+. $PCP_DIR/etc/pcp.env
+
+# Get the common procedures and variable assignments
+#
+. $PCP_SHARE_DIR/lib/pmdaproc.sh
+
+# The name of the PMDA
+#
+iam=trivial
+
+# Do it
+#
+pmdaSetup
+pmdaRemove
+
+exit 0
diff --git a/src/pmdas/trivial/help b/src/pmdas/trivial/help
new file mode 100644
index 0000000..300bcd4
--- /dev/null
+++ b/src/pmdas/trivial/help
@@ -0,0 +1,35 @@
+#
+# Copyright (c) 2000-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
+#
+# trivial PMDA help file in the ASCII format
+#
+# lines beginning with a # are ignored
+# lines beginning @ introduce a new entry of the form
+# @ metric_name oneline-text
+# help test goes
+# here over multiple lines
+# ...
+#
+# the metric_name is decoded against the default PMNS -- as a special case,
+# a name of the form NNN.MM (for numeric NNN and MM) is interpreted as an
+# instance domain identification, and the text describes the instance domain
+#
+# blank lines before the @ line are ignored
+#
+
+@ trivial.time The time in seconds since 1 Jan 1970
+The time in seconds since the 1st of January, 1970.
diff --git a/src/pmdas/trivial/pmns b/src/pmdas/trivial/pmns
new file mode 100644
index 0000000..f7a6167
--- /dev/null
+++ b/src/pmdas/trivial/pmns
@@ -0,0 +1,23 @@
+/*
+ * Metrics for trivial PMDA
+ *
+ * Copyright (c) 2000-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
+ */
+
+trivial {
+ time TRIVIAL:0:0
+}
diff --git a/src/pmdas/trivial/root b/src/pmdas/trivial/root
new file mode 100644
index 0000000..579f567
--- /dev/null
+++ b/src/pmdas/trivial/root
@@ -0,0 +1,10 @@
+/*
+ * fake "root" for validating the local PMNS subtree
+ */
+
+#include <stdpmid>
+
+root { trivial }
+
+#include "pmns"
+
diff --git a/src/pmdas/trivial/trivial.c b/src/pmdas/trivial/trivial.c
new file mode 100644
index 0000000..b395538
--- /dev/null
+++ b/src/pmdas/trivial/trivial.c
@@ -0,0 +1,138 @@
+/*
+ * Trivial, configurable PMDA
+ *
+ * Copyright (c) 2014 Red Hat.
+ * Copyright (c) 1995,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.
+ */
+
+#include <pcp/pmapi.h>
+#include <pcp/impl.h>
+#include <pcp/pmda.h>
+#include "domain.h"
+
+/*
+ * Trivial PMDA
+ *
+ * This PMDA is a sample that illustrates how a trivial PMDA might be
+ * constructed using libpcp_pmda.
+ *
+ * Although the metrics supported are trivial, the framework is quite general,
+ * and could be extended to implement a much more complex PMDA.
+ *
+ * Metrics
+ * trivial.time - time in seconds since the 1st of Jan, 1970.
+ */
+
+/*
+ * all metrics supported in this PMDA - one table entry for each
+ */
+
+static pmdaMetric metrictab[] = {
+/* time */
+ { NULL,
+ { PMDA_PMID(0,0), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ PMDA_PMUNITS(0, 1, 0, 0, PM_TIME_SEC, 0) } }
+};
+
+static char *username;
+static char mypath[MAXPATHLEN];
+static int isDSO = 1; /* ==0 if I am a daemon */
+
+static pmLongOptions longopts[] = {
+ PMDA_OPTIONS_HEADER("Options"),
+ PMOPT_DEBUG,
+ PMDAOPT_DOMAIN,
+ PMDAOPT_LOGFILE,
+ PMDAOPT_USERNAME,
+ PMOPT_HELP,
+ PMDA_OPTIONS_END
+};
+static pmdaOptions opts = {
+ .short_options = "D:d:l:U:?",
+ .long_options = longopts,
+};
+
+/*
+ * callback provided to pmdaFetch
+ */
+static int
+trivial_fetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom)
+{
+ __pmID_int *idp = (__pmID_int *)&(mdesc->m_desc.pmid);
+
+ if (idp->cluster != 0 || idp->item != 0)
+ return PM_ERR_PMID;
+ else if (inst != PM_IN_NULL)
+ return PM_ERR_INST;
+
+ atom->ul = time(NULL);
+ return 0;
+}
+
+/*
+ * Initialise the agent (both daemon and DSO).
+ */
+void
+trivial_init(pmdaInterface *dp)
+{
+ if (isDSO) {
+ int sep = __pmPathSeparator();
+ snprintf(mypath, sizeof(mypath), "%s%c" "trivial" "%c" "help",
+ pmGetConfig("PCP_PMDAS_DIR"), sep, sep);
+ pmdaDSO(dp, PMDA_INTERFACE_2, "trivial DSO", mypath);
+ } else {
+ __pmSetProcessIdentity(username);
+ }
+
+ if (dp->status != 0)
+ return;
+
+ pmdaSetFetchCallBack(dp, trivial_fetchCallBack);
+
+ pmdaInit(dp, NULL, 0,
+ metrictab, sizeof(metrictab)/sizeof(metrictab[0]));
+}
+
+/*
+ * Set up the agent if running as a daemon.
+ */
+int
+main(int argc, char **argv)
+{
+ int sep = __pmPathSeparator();
+ pmdaInterface desc;
+
+ isDSO = 0;
+ __pmSetProgname(argv[0]);
+ __pmGetUsername(&username);
+
+ snprintf(mypath, sizeof(mypath), "%s%c" "trivial" "%c" "help",
+ pmGetConfig("PCP_PMDAS_DIR"), sep, sep);
+ pmdaDaemon(&desc, PMDA_INTERFACE_2, pmProgname, TRIVIAL,
+ "trivial.log", mypath);
+
+ pmdaGetOptions(argc, argv, &opts, &desc);
+ if (opts.errors) {
+ pmdaUsageMessage(&opts);
+ exit(1);
+ }
+ if (opts.username)
+ username = opts.username;
+
+ pmdaOpenLog(&desc);
+ trivial_init(&desc);
+ pmdaConnect(&desc);
+ pmdaMain(&desc);
+
+ exit(0);
+}