line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Measure::Everything::Adapter::InfluxDB::TCP; |
2
|
1
|
|
|
1
|
|
667
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
67
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.002'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Send stats to Influx via TCP using Telegraf |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
15
|
use base qw(Measure::Everything::Adapter::Base); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
686
|
|
10
|
1
|
|
|
1
|
|
873
|
use InfluxDB::LineProtocol qw(); |
|
1
|
|
|
|
|
5248
|
|
|
1
|
|
|
|
|
35
|
|
11
|
1
|
|
|
1
|
|
619
|
use IO::Socket::INET; |
|
1
|
|
|
|
|
21020
|
|
|
1
|
|
|
|
|
9
|
|
12
|
1
|
|
|
1
|
|
881
|
use Log::Any qw($log); |
|
1
|
|
|
|
|
8705
|
|
|
1
|
|
|
|
|
4
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub init { |
15
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
0
|
|
|
|
my $host = $self->{host} || 'localhost'; |
18
|
0
|
|
0
|
|
|
|
my $port = $self->{port} || 8094; |
19
|
0
|
0
|
|
|
|
|
my $precision = $self->{precision} ? 'precision='.$self->{precision} : ''; |
20
|
0
|
|
|
|
|
|
InfluxDB::LineProtocol->import('data2line', $precision); |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $socket = IO::Socket::INET->new( |
23
|
|
|
|
|
|
|
PeerAddr => $host, |
24
|
|
|
|
|
|
|
PeerPort => $port, |
25
|
|
|
|
|
|
|
Proto => 'tcp', |
26
|
|
|
|
|
|
|
); |
27
|
0
|
0
|
|
|
|
|
if ($socket) { |
28
|
0
|
|
|
|
|
|
$self->{socket} = $socket; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
0
|
|
|
|
|
|
$log->errorf( |
32
|
|
|
|
|
|
|
"Cannot set up TCP socket on %s:%s, no stats will be recorded!", |
33
|
|
|
|
|
|
|
$host, $port ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub write { |
38
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
39
|
0
|
|
|
|
|
|
my $line = data2line(@_); |
40
|
0
|
0
|
|
|
|
|
if ( $self->{socket} ) { |
41
|
0
|
|
|
|
|
|
return $self->{socket}->send($line."\n"); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |