-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathexample.pl
More file actions
78 lines (67 loc) · 1.86 KB
/
Copy pathexample.pl
File metadata and controls
78 lines (67 loc) · 1.86 KB
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
#
# Copyright (C) 2010 Bernard Li <bernard@vanhpc.org>
# All Rights Reserved.
#
# This code is part of a perl module for ganglia.
#
# Contributors : Nicolas Brousse <nicolas@brousse.info>
#
use strict;
our @descriptors;
our $Random_Max = 50;
our $Constant_Value = 50;
use vars qw(@descriptors $Random_Max $Constant_Value);
sub Random_Numbers {
my $i = int(rand($Random_Max));
printf("Value from Random_Numbers : %d\n", $i);
return $i;
}
sub Constant_Number {
my $i = int($Constant_Value);
printf("Value from Constant_Numbers : %d\n", $i);
return $i;
}
sub metric_init {
my $params = shift;
if (exists($params->{'RandomMax'})) {
$Random_Max = int($params->{'RandomMax'});
}
if (exists($params->{'ConstantValue'})) {
$Constant_Value = int($params->{'ConstantValue'});
}
my %d1 = (
'name' => 'PlRandom_Numbers',
'call_back' => 'Random_Numbers',
'time_max' => 90,
'value_type' => 'uint',
'units' => 'N',
'slope' => 'both',
'format' => '%u',
'description' => 'Example module metric (random numbers)',
'groups' => 'example,random'
);
my %d2 = (
'name' => 'PlConstant_Number',
'call_back' => 'Constant_Number',
'time_max' => 90,
'value_type' => 'uint',
'units' => 'N',
'slope' => 'zero',
'format' => '%u',
'description' => 'Example module metric (constant number)',
'groups' => 'example'
);
push @descriptors, { %d1 };
push @descriptors, { %d2 };
return @descriptors;
}
sub metric_cleanup {
}
if ($ENV{_} !~ /gmond/) {
my $params = {'RandomMax' => 500, 'ConstantValue' => 322};
metric_init($params);
foreach (@descriptors) {
my $v = eval($_->{'call_back'});
printf("value for %s is %u\n", $_->{'name'}, $v);
}
}