Debian Codegraph @

gmond/perl_modules/example/example.pl

raw
1 #
2 # Copyright (C) 2010 Bernard Li <[email protected]>
3 # All Rights Reserved.
4 #
5 # This code is part of a perl module for ganglia.
6 #
7 # Contributors : Nicolas Brousse <[email protected]>
8 #
9
10 use strict;
11 our @descriptors;
12 our $Random_Max = 50;
13 our $Constant_Value = 50;
14 use vars qw(@descriptors $Random_Max $Constant_Value);
15
16 sub Random_Numbers {
17 my $i = int(rand($Random_Max));
18 printf("Value from Random_Numbers : %d\n", $i);
19 return $i;
20 }
21
22 sub Constant_Number {
23 my $i = int($Constant_Value);
24 printf("Value from Constant_Numbers : %d\n", $i);
25 return $i;
26 }
27
28 sub metric_init {
29 my $params = shift;
30
31 if (exists($params->{'RandomMax'})) {
32 $Random_Max = int($params->{'RandomMax'});
33 }
34
35 if (exists($params->{'ConstantValue'})) {
36 $Constant_Value = int($params->{'ConstantValue'});
37 }
38
39 my %d1 = (
40 'name' => 'PlRandom_Numbers',
41 'call_back' => 'Random_Numbers',
42 'time_max' => 90,
43 'value_type' => 'uint',
44 'units' => 'N',
45 'slope' => 'both',
46 'format' => '%u',
47 'description' => 'Example module metric (random numbers)',
48 'groups' => 'example,random'
49 );
50 my %d2 = (
51 'name' => 'PlConstant_Number',
52 'call_back' => 'Constant_Number',
53 'time_max' => 90,
54 'value_type' => 'uint',
55 'units' => 'N',
56 'slope' => 'zero',
57 'format' => '%u',
58 'description' => 'Example module metric (constant number)',
59 'groups' => 'example'
60 );
61
62 push @descriptors, { %d1 };
63 push @descriptors, { %d2 };
64 return @descriptors;
65 }
66
67 sub metric_cleanup {
68 }
69
70 if ($ENV{_} !~ /gmond/) {
71 my $params = {'RandomMax' => 500, 'ConstantValue' => 322};
72
73 metric_init($params);
74 foreach (@descriptors) {
75 my $v = eval($_->{'call_back'});
76 printf("value for %s is %u\n", $_->{'name'}, $v);
77 }
78 }