summaryrefslogtreecommitdiff
path: root/qa/pmdas/slow_python/pmdaslow_python.python
blob: c1da8e874c299ff0036b8fc242569c29c105243f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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()