X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=sidebyside;f=atop2influx.pl;h=19f0768d14f0348b291bfdc839d7c65ebac68907;hb=refs%2Fheads%2Fmaster;hp=bd26ad5201ba336d303ee7985dfaca7cb518893f;hpb=49ce72e9f869759e735155cb4e99210f11475e49;p=atop-influxdb diff --git a/atop2influx.pl b/atop2influx.pl index bd26ad5..19f0768 100755 --- a/atop2influx.pl +++ b/atop2influx.pl @@ -20,6 +20,9 @@ sub update_time { return $time; } +my $tags = $ENV{TAGS}; +$tags = ",$tags" if $tags && $tags !~ m/^,/; + while(<>) { chomp; next if /^$/; @@ -28,7 +31,7 @@ while(<>) { my @vals; - if ( /^(\w+)\s+(\S+)\s+(.+)\s+(\w+)\s+(\d\d\d\d)\/(\d\d)\/(\d\d)$/ ) { + if ( /^([\w\-]+)\s+(\d+\S+)\s+(.+)\s+(\w+)\s+(\d\d\d\d)\/(\d\d)\/(\d\d)$/ ) { $host = $1; @cols = qw( kernel build arch ); @vals = ( qq{"$2"}, qq{"$3"}, qq{"$4"} ); # must quote all this as strings for influx @@ -38,7 +41,7 @@ while(<>) { ( $yyyy, $mm, $dd ) = split(/\//, $1, 3); update_time; next; - } elsif ( m/^00:00:01\s+(.+)_(\w+)_/ ) { + } elsif ( m/^\d\d:\d\d:\d\d\s+(.+)_(\w+)_/ ) { $measurement = $2; my $cols = $1; $cols =~ s/(in|out):\s+(\w+)/$1_$2/g; # ipv4, ipv6 @@ -46,12 +49,13 @@ while(<>) { next; } elsif ( m/^(\d\d:\d\d:\d\d)\s+(.+)/ ) { + next if m/logging restarted/; ( $hour, $min, $sec ) = split(/:/, $1, 3); update_time; @vals = split(/\s+/, $2); } elsif ( m/^\s+(.+)/ ) { @vals = split(/\s+/, $1); } else { - die "UNPARSED: $_\n"; + warn "UNPARSED: $_\n"; } next unless @vals; @@ -59,7 +63,7 @@ while(<>) { next if $measurement =~ /top3/; # FIXME this isn't parsed yet #XXX { cols => \@cols, vals => \@vals }; - print "atop_$measurement,host=$host"; + print "$measurement,host=$host$tags"; my $d = " "; foreach my $i ( 0 .. $#cols ) { if ( my $c = $cols[$i] ) { @@ -74,16 +78,21 @@ while(<>) { $c =~ s/\W+/_/g; my $v = $vals[$i]; - die "line: [$_]\nno vals[$i] in ",Data::Dump::dump( @vals ) if ! defined $v; + if ( ! defined $v ) { + warn "WARN line: [$_]\nno vals[$i] in ",Data::Dump::dump( @vals ); + next; + }; - #$v *= 1024 * 1024 if $v =~ s/M$//; - $v =~ s/M$//; + $v *= 1024 * 1024 if $v =~ s/M$//; + #$v =~ s/M$//; $v =~ s/%$//; $v =~ s/\s/\\ /g unless $v =~ m/"/; next if $c eq "busy" && $v eq "?"; +# $s = 'i' if $v =~ m/^\d+$/; + print "$d$c=$v$s"; $d ||= ',';