summaryrefslogtreecommitdiff
path: root/qa/pmdas/slow/pmdaslow.pl
blob: 7d8311fa25d1457dc866f650b918447b58753a1c (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
#
# 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.
#

use strict;
use warnings;
use PCP::PMDA;

use vars qw( $pmda $start_delay $fetch_delay );

sub slow_fetch_callback
{
    my ($cluster, $item, $inst) = @_;
    my $metric_name = pmda_pmid_name($cluster, $item);

    if ($fetch_delay > 0) {
	sleep($fetch_delay);
    }

    $pmda->log("slow_fetch_callback $metric_name $cluster:$item ($inst)\n");

    if ($inst != PM_IN_NULL)	{ return (PM_ERR_INST, 0); }
    if (!defined($metric_name))	{ return (PM_ERR_PMID, 0); }

    return (17, 1);
}

# Usage: pmdaslow [startdelay [fetchdelay]]
#
$start_delay = 0;
$start_delay = $ARGV[0] unless !defined($ARGV[0]);
$fetch_delay = 0;
$fetch_delay = $ARGV[1] unless !defined($ARGV[1]);

#debug# print 'start delay: ',$start_delay,' sec\n';
#debug# print 'fetch delay: ',$fetch_delay,' sec\n';

$pmda = PCP::PMDA->new('slow', 243);
$pmda->connect_pmcd unless $start_delay < 0;

if ($start_delay < 0) {
    sleep(-$start_delay);
}
if ($start_delay > 0) {
    sleep($start_delay);
}

$pmda->add_metric(pmda_pmid(0,0), PM_TYPE_U32, PM_INDOM_NULL,
		  PM_SEM_INSTANT, pmda_units(0,0,0,0,0,0),
		  'slow.seventeen', '', '');

$pmda->set_fetch_callback(\&slow_fetch_callback);
$pmda->set_user('pcp');
$pmda->run;

=pod

=head1 NAME

pmdaslow - QA PMDA

=head1 DESCRIPTION

DO NOT INSTALL THIS PMDA.