line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ganglia::Gmetric; |
2
|
|
|
|
|
|
|
$VERSION=0.3; |
3
|
1
|
|
|
1
|
|
969
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
4
|
1
|
|
|
1
|
|
8
|
use base qw(Class::Accessor); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1213
|
|
5
|
1
|
|
|
1
|
|
3260
|
use IO::CaptureOutput qw/capture/; |
|
1
|
|
|
|
|
26627
|
|
|
1
|
|
|
|
|
422
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Ganglia::Gmetric - perl gmetric wrapper |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Ganglia::Gmetric; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $gmetric=Ganglia::Gmetric->new({ |
16
|
|
|
|
|
|
|
name => 'some name', |
17
|
|
|
|
|
|
|
value => 'some value', |
18
|
|
|
|
|
|
|
units => 'm/s', |
19
|
|
|
|
|
|
|
type => 'int16' |
20
|
|
|
|
|
|
|
}); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$gmetric->ttl('5'); |
23
|
|
|
|
|
|
|
$gmetric->run(\$stdout,\$stderr); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $gmetric='gmetric'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Simple perl wrapper around ganglia's gmetric. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 new |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $gmetric=Ganglia::Gmetric->new; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $gmetric=Ganglia::Gmetric->new({name => 'some name', |
38
|
|
|
|
|
|
|
value => 'some value', |
39
|
|
|
|
|
|
|
units => 'm/s', |
40
|
|
|
|
|
|
|
type => 'int16', |
41
|
|
|
|
|
|
|
channel => 'channel', |
42
|
|
|
|
|
|
|
port => 'port', |
43
|
|
|
|
|
|
|
iface => 'iface', |
44
|
|
|
|
|
|
|
ttl => 'ttl', |
45
|
|
|
|
|
|
|
path => '/path/to/gmetric/', |
46
|
|
|
|
|
|
|
}); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new { |
51
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
52
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
53
|
0
|
|
|
|
|
|
return $self; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw[name value type path units channel port iface ttl]); |
56
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors(qw[command]); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 run |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$gmetric->run(\$stdout,\$stderr); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
runs the gmetric command. returns gmetric return code (0 on succes). |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
sub run { |
66
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
67
|
0
|
|
|
|
|
|
my ($stdout, $stderr)=@_; |
68
|
0
|
0
|
|
|
|
|
if ($self->{path}){$gmetric=$self->{path}.$gmetric} |
|
0
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $command="$gmetric -n $self->{name} -v $self->{value} -t $self->{type}"; |
70
|
0
|
0
|
|
|
|
|
if ($self->{units}){$command.=" -u $self->{units}"} |
|
0
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
if ($self->{channel}){$command.=" -c $self->{channel}"} |
|
0
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
if ($self->{port}){$command.=" -p $self->{port}"} |
|
0
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if ($self->{iface}){$command.=" -i $self->{iface}"} |
|
0
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if ($self->{ttl}){$command.=" -l $self->{ttl}"} |
|
0
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$self->{command}=$command; |
76
|
0
|
|
|
|
|
|
print $self->command; |
77
|
|
|
|
|
|
|
capture sub { |
78
|
0
|
|
|
0
|
|
|
system($command); |
79
|
0
|
|
|
|
|
|
} => $stdout, $stderr; |
80
|
0
|
|
|
|
|
|
return $? >> 8; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
__END__ |