| 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
| |||||||||||
| 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
| |||||||||||
| 64 | 9 | ▶ | usage('--name required') unless defined $name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 9 | ▶ | usage('--value required') unless defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 9 | ▶ | usage('--type required') unless defined $type; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 9 | ▶ | usage("invalid type '$type'") unless exists $types{$type}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 9 | ▶ | usage('invalid slope') unless exists $slopes{$slope}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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); | |||||||||