fix import issues
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 10 Dec 2016 12:28:59 +0000 (13:28 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 10 Dec 2016 12:28:59 +0000 (13:28 +0100)
atop2influx.pl

index bd26ad5..691defc 100755 (executable)
@@ -28,7 +28,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 +38,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,6 +46,7 @@ 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+(.+)/ ) {
@@ -74,7 +75,10 @@ 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$//;
@@ -84,6 +88,8 @@ while(<>) {
 
                        next if $c eq "busy" && $v eq "?";
 
+#                      $s = 'i' if $v =~ m/^\d+$/;
+
                        print "$d$c=$v$s";
 
                        $d ||= ',';