diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2014-10-26 12:33:50 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2014-10-26 12:33:50 +0400 |
commit | 47e6e7c84f008a53061e661f31ae96629bc694ef (patch) | |
tree | 648a07f3b5b9d67ce19b0fd72e8caa1175c98f1a /qa/pmdas/slow_python/pmdaslow_python.python | |
download | pcp-debian/3.9.10.tar.gz |
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'qa/pmdas/slow_python/pmdaslow_python.python')
-rw-r--r-- | qa/pmdas/slow_python/pmdaslow_python.python | 84 |
1 files changed, 84 insertions, 0 deletions
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() + |