6 my $host = shift @ARGV || die "usage: INFLUX=http://127.0.0.1:8086/write?db=snmp COMMUNITY=snmp-comminity $0 host";
7 my $community = $ENV{COMMUNITY} || 'public';
8 my $influx = $ENV{INFLUX} || 'http://127.0.0.1:8086/write?db=snmp';
10 use Data::Dump qw(dump);
11 sub XXX { warn "XXX ", scalar(@_), Data::Dump::dump(@_), join(' ',caller), "\n"; };
13 my ($sec,$min,$hour,$dd,$mm,$yyyy) = localtime(time); $mm++;
17 #warn "# time $yyyy-$mm-$dd $hour:$min:$sec $time\n";
18 $time = timelocal($sec,$min,$hour,$dd,$mm-1,$yyyy) * 1000_000_000;
22 # FIXME add -A to pull interfaces if they go up and down
25 my $cmd = qq{ifstat -s '$community@#$host' -b -n -t 1};
27 open(my $ifstat, '-|', $cmd);
29 my $first_skipped = 0;
34 open($curl, '|-', qq( curl -XPOST $influx --data-binary \@- ));
36 open($curl, '|-', 'tee /dev/shm/curl.debug');
46 my $host_tags = $host;
47 $host_tags =~ s/\./,domain=/;
53 s/(\w) (in|out)/$1_$2/g;
55 if ( $v[0] eq 'Time' ) {
58 } elsif ( $v[0] eq 'HH:MM:SS' ) {
60 @direction = map { s/\W+/_/g; s/^K//; $_ } @v;
61 } elsif ( $v[0] =~ m/^(\d\d):(\d\d):(\d\d)/ ) {
62 next unless $first_skipped++;
63 $hour = $1; $min = $2; $sec = $3; update_time;
68 foreach my $i ( 0 .. $#if ) {
70 my @tags = ( "host=$host_tags", $ENV{TAGS} || 'no_tags=true' );
73 if ( $port =~ m/if(\d\d)(\d\d\d\d)/ ) {
74 push @tags, "prefix=$1,vlan=$2";
75 } elsif ( m/if(\d+)/ ) {
76 push @tags, "port=$1";
79 print $curl "ifstat,", join(',', @tags),
80 " ", $direction[$i*2], "=", ( $v[$i*2+1] * 1024 ),
81 ",", $direction[$i*2+1], "=", ( $v[$i*2+2] * 1024 ),
89 warn "# $host ", $curl->tell, " total=$total\n";