diff options
Diffstat (limited to 'qa/pmdas/slow_python')
-rw-r--r-- | qa/pmdas/slow_python/GNUmakefile | 40 | ||||
-rw-r--r-- | qa/pmdas/slow_python/GNUmakefile.install | 5 | ||||
-rwxr-xr-x | qa/pmdas/slow_python/Install | 38 | ||||
-rwxr-xr-x | qa/pmdas/slow_python/Remove | 25 | ||||
-rw-r--r-- | qa/pmdas/slow_python/pmdaslow_python.python | 84 |
5 files changed, 192 insertions, 0 deletions
diff --git a/qa/pmdas/slow_python/GNUmakefile b/qa/pmdas/slow_python/GNUmakefile new file mode 100644 index 0000000..20ffe63 --- /dev/null +++ b/qa/pmdas/slow_python/GNUmakefile @@ -0,0 +1,40 @@ +# +# Copyright (c) 2014 Ken McDonell. 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 + +IAM = slow_python +TESTDIR = $(PCP_VAR_DIR)/testsuite/pmdas/$(IAM) +PYSCRIPT = pmda$(IAM).python +LSRCFILES = Install Remove $(PYSCRIPT) GNUmakefile.install + +# Uses some domain as slow PMDA (QA never installs both together) +# +DOMAIN = SLOW + +LDIRT = domain.h $(IAM).log pmns.python + +default default_pcp setup: check_domain + +include $(BUILDRULES) + +install_pcp install: default + $(INSTALL) -m 755 -d $(TESTDIR) + $(INSTALL) -m 755 Install Remove $(TESTDIR) + $(INSTALL) -m 644 $(PYSCRIPT) $(TESTDIR)/$(PYSCRIPT) + $(INSTALL) -m 644 GNUmakefile.install $(TESTDIR)/GNUmakefile + +check_domain: $(TOPDIR)/src/pmns/stdpmid + $(DOMAIN_PYTHONRULE) diff --git a/qa/pmdas/slow_python/GNUmakefile.install b/qa/pmdas/slow_python/GNUmakefile.install new file mode 100644 index 0000000..62a9c73 --- /dev/null +++ b/qa/pmdas/slow_python/GNUmakefile.install @@ -0,0 +1,5 @@ +default default_pcp setup: + +clobber clean: + rm -f domain.h domain.h.python domain.h.save + rm -f pmns pmns.python pmns.save diff --git a/qa/pmdas/slow_python/Install b/qa/pmdas/slow_python/Install new file mode 100755 index 0000000..ab05eb8 --- /dev/null +++ b/qa/pmdas/slow_python/Install @@ -0,0 +1,38 @@ +#! /bin/sh +# +# Copyright (c) 2014 Ken McDonell. 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 slow PMDA +# + +. $PCP_DIR/etc/pcp.env +. $PCP_SHARE_DIR/lib/pmdaproc.sh + +iam=slow_python +python_opt=true +daemon_opt=false +forced_restart=false + +pmdaSetup +$PCP_ECHO_PROG $PCP_ECHO_N "Startup delay (secs) [0]? $PCP_ECHO_C" +read x +[ -z "$x" ] && x=0 +$PCP_ECHO_PROG $PCP_ECHO_N "Fetch delay (secs) [0]? $PCP_ECHO_C" +read y +[ -z "$y" ] && y=0 +python_args="$python_args $x $y" +[ "$x" -lt 0 ] && check_delay=`expr -1 \* $x + 2` +[ "$x" -gt 0 ] && check_delay=`expr $x + 2` + +pmdaInstall +exit 0 diff --git a/qa/pmdas/slow_python/Remove b/qa/pmdas/slow_python/Remove new file mode 100755 index 0000000..c3cbda8 --- /dev/null +++ b/qa/pmdas/slow_python/Remove @@ -0,0 +1,25 @@ +#! /bin/sh +# +# Copyright (c) 2014 Ken McDonell. 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. +# +# Remove the slow PMDA +# + +. $PCP_DIR/etc/pcp.env +. $PCP_SHARE_DIR/lib/pmdaproc.sh + +iam=slow_python + +pmdaSetup +pmdaRemove +exit 0 diff --git a/qa/pmdas/slow_python/pmdaslow_python.python b/qa/pmdas/slow_python/pmdaslow_python.python new file mode 100644 index 0000000..c1da8e8 --- /dev/null +++ b/qa/pmdas/slow_python/pmdaslow_python.python @@ -0,0 +1,84 @@ +''' +Python implementation of the "slow_python" Performance Metrics Domain Agent. +''' +# +# Copyright (c) 2013 Red Hat. +# Copyright (c) 2014 Ken McDonell. 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. +# + +import sys +import os +import time +import ctypes +from ctypes import c_int, POINTER, cast +import cpmapi as c_api +from pcp.pmda import PMDA, pmdaMetric +from pcp.pmapi import pmUnits, pmContext as PCP + +class SlowPMDA(PMDA): + ''' + A slow Performance Metrics Domain Agent. + DO NOT INSTALL - for QA ONLY. + ''' + + def slow_fetch_callback(self, cluster, item, inst): + global fetch_delay + + if int(fetch_delay) < 0: + time.sleep(-1*int(fetch_delay)) + + if int(fetch_delay) > 0: + time.sleep(int(fetch_delay)) + + if cluster == 0 and item == 0: + return [13, 1] + return [c_api.PM_ERR_PMID, 0] + + def __init__(self, name, domain): + global start_delay + + PMDA.__init__(self, name, domain) + + self.configfile = PCP.pmGetConfig('PCP_PMDAS_DIR') + self.configfile += '/' + name + '/' + name + '.conf' + + if int(start_delay) > 0: + self.connect_pmcd() + + if int(start_delay) < 0: + time.sleep(-1*int(start_delay)) + if int(start_delay) > 0: + time.sleep(int(start_delay)) + + self.add_metric(name + '.thirteen', pmdaMetric(self.pmid(0, 0), + c_api.PM_TYPE_32, c_api.PM_INDOM_NULL, c_api.PM_SEM_INSTANT, + pmUnits(0, 0, 0, 0, 0, 0))) + + self.set_fetch_callback(self.slow_fetch_callback) + self.set_user(PCP.pmGetConfig('PCP_USER')) + +# Usage: pmdaslow [startdelay [fetchdelay]] +# +start_delay = 0 +if len(sys.argv) >= 2: + start_delay = sys.argv[1] +fetch_delay = 0 +if len(sys.argv) >= 3: + fetch_delay = sys.argv[2] + +#debug# print 'start delay: ', start_delay, ' sec' +#debug# print 'fetch delay: ', fetch_delay, ' sec' + +if __name__ == '__main__': + SlowPMDA('slow_python', 242).run() + |