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/src/check_import.python | |
download | pcp-debian.tar.gz |
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'qa/src/check_import.python')
-rwxr-xr-x | qa/src/check_import.python | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/qa/src/check_import.python b/qa/src/check_import.python new file mode 100755 index 0000000..a10ece2 --- /dev/null +++ b/qa/src/check_import.python @@ -0,0 +1,69 @@ +""" Python test case for Log Import API wrapper module +""" +# +# Copyright (C) 2012-2014 Red Hat Inc. +# +# 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 math +import time +import cpmapi +from pcp import pmi +from pcp import pmapi + +def check_import(archive, hostname, timezone): + """ Test body - check many of the Log Import API wrapper interfaces + """ + log = pmi.pmiLogImport(archive) + log.pmiSetHostname(hostname) + log.pmiSetTimezone(timezone) + + domain = 60 # Linux kernel + pmid = log.pmiID(domain, 2, 0) + indom = log.pmiInDom(domain, 2) + units = log.pmiUnits(0, 0, 0, 0, 0, 0) + + # create a metric with no instances (hinv.ncpu) + log.pmiAddMetric("hinv.ncpu", cpmapi.PM_ID_NULL, cpmapi.PM_TYPE_U32, + cpmapi.PM_INDOM_NULL, cpmapi.PM_SEM_DISCRETE, units) + + # give it a value + log.pmiPutValue("hinv.ncpu", "", "%d" % 42) + + # create a metric with instances (kernel.all.load) + log.pmiAddMetric("kernel.all.load", pmid, + cpmapi.PM_TYPE_FLOAT, indom, cpmapi.PM_SEM_INSTANT, units) + log.pmiAddInstance(indom, "1 minute", 1) + log.pmiAddInstance(indom, "5 minute", 5) + log.pmiAddInstance(indom, "15 minute", 15) + + # give them values + log.pmiPutValue("kernel.all.load", "1 minute", "%f" % 0.01) + log.pmiPutValue("kernel.all.load", "5 minute", "%f" % 0.05) + log.pmiPutValue("kernel.all.load", "15 minute", "%f" % 0.15) + + timetuple = math.modf(time.time()) + useconds = int(timetuple[0] * 1000000) + seconds = int(timetuple[1]) + log.pmiWrite(seconds, useconds) + + del log + +if __name__ == '__main__': + + if (len(sys.argv) != 2): + print("Usage: " + sys.argv[0] + " <path>") + sys.exit(1) + + check_import(sys.argv[1], "www.abc.com", "EST-10") + |