script/gmetric.pl

filter: Statementstmt 83.3% 25 / 30 Branchbran 42.8% 6 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod n/a totaltotal 71.4% 35 / 49 CC 2 SCAR 9.8
CC
2
Cov
70%
usage
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.7
« lib/Ganglia/Gmetric/PP.pm ↑ Summary
1 #!/usr/local/bin/perl
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use Ganglia::Gmetric::PP ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub usage {
Subroutine usage: not called CC=2 SCAR=17.9
10 0 (my $me = $0) =~ s,.*/,,;
11 0 my $error = shift;
12 0 ▶ print "Error: $error\n\n" if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
13 0 print <<EOD;
14 $me $Ganglia::Gmetric::PP::VERSION
15  
16 Usage: $me [OPTIONS]...
17  
18 -h, --help Print help and exit
19 -n, --name=STRING Name of the metric
20 -v, --value=STRING Value of the metric
21 -t, --type=STRING Either
22 string|int8|uint8|int16|uint16|int32|uint32|float|double
23 -u, --units=STRING Unit of measure for the value e.g. Kilobytes, Celcius
24 (default=`')
25 -s, --slope=STRING Either zero|positive|negative|both (default=`both')
26 -x, --tmax=INT The maximum time in seconds between gmetric calls
27 (default=`60')
28 -d, --dmax=INT The lifetime in seconds of this metric (default=`0')
29 -H, --host=STRING Host where gmond is listening (default=`localhost')
30 -p, --port=INT UDP port where gmond is listening (default=`8649')
31 EOD
32  
33 0 exit 1;
34 }
35  
36 9 GetOptions(
37 'n|name=s' => \(my $name),
38 'v|value=s' => \(my $value),
39 't|type=s' => \(my $type),
40 'u|units=s' => \(my $units = ''),
41 's|slope=s' => \(my $slope = 'both'),
42 'x|tmax=i' => \(my $tmax = 60),
43 'd|dmax=i' => \(my $dmax = 0),
44 'H|host=s' => \(my $host = 'localhost'),
45 'p|port=i' => \(my $port = 8649),
46 'h|help!' => \(my $help),
47 );
48  
49 9 my %types = map { $_ => 1 }
50 GANGLIA_VALUE_STRING,
51 GANGLIA_VALUE_CHAR, GANGLIA_VALUE_UNSIGNED_CHAR,
52 GANGLIA_VALUE_SHORT, GANGLIA_VALUE_UNSIGNED_SHORT,
53 GANGLIA_VALUE_INT, GANGLIA_VALUE_UNSIGNED_INT,
54 GANGLIA_VALUE_FLOAT, GANGLIA_VALUE_DOUBLE;
55  
56 9 my %slopes = (
57 zero => GANGLIA_SLOPE_ZERO,
58 positive => GANGLIA_SLOPE_POSITIVE,
59 negative => GANGLIA_SLOPE_NEGATIVE,
60 both => GANGLIA_SLOPE_BOTH,
61 );
62  
63 9 ▶usage if $help;
Branch: 1 branch
BranchTrueFalseTotal
if $help 0 9 9
64 9 ▶usage('--name required') unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 9 9
65 9 ▶usage('--value required') unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 9 9
66 9 ▶usage('--type required') unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 9 9
67 9 ▶usage("invalid type '$type'") unless exists $types{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $types{$type} 0 9 9
68 9 ▶usage('invalid slope') unless exists $slopes{$slope};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $slopes{$slope} 0 9 9
69  
70 9 $slope = $slopes{$slope};
71  
72 9 my $gmetric = Ganglia::Gmetric::PP->new(host => $host, port => $port);
73 9 $gmetric->send($type, $name, $value, $units, $slope, $tmax, $dmax);
« lib/Ganglia/Gmetric/PP.pm ↑ Summary