X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=gnt-i;h=6b1dade6aae7a9182664f0efd66b914aed83ff35;hb=0c93539e382dc062a659390cebf32a835dbbe02d;hp=92fd314d559fa6d86b70170cf190cad4a6e5a9ea;hpb=31d67c12cb6f26514787e114f9c9eeccc6e63f22;p=gnt-info diff --git a/gnt-i b/gnt-i index 92fd314..6b1dade 100755 --- a/gnt-i +++ b/gnt-i @@ -2,8 +2,10 @@ use warnings; use strict; use autodie; +use Storable; my $DEBUG = $ENV{DEBUG} || 0; +my $INFLUX = 'http://10.60.0.89:8186/write'; my $hostname = `hostname -s`; chomp $hostname; @@ -19,7 +21,7 @@ my $lines; my @nodes = @ARGV; -@nodes = map { chomp ; $_ } `gnt-node list -o name --no-header` unless @nodes; +@nodes = map { chomp ; s/\s+N$// ; $_ } grep { /N$/ } `gnt-node list -o name,offline --no-header` unless @nodes; next_node: my $ssh = ''; @@ -204,9 +206,34 @@ foreach my $name ( sort keys %$stat ) { #XXX $lines; +open(my $influx_fh, '>', '/dev/shm/ganeti.influx'); + +my $last_lines; +$last_lines = retrieve('/dev/shm/ganeti.last.storable') if -e '/dev/shm/ganeti.last.storable'; + my $fmt = join(' ', map { '%' . $_ . 's' } @{ $lines->{len} } ) . "\n"; warn "# fmt = [$fmt]" if $DEBUG; -foreach my $line ( @{ $lines->{line} } ) { +foreach my $i ( 0 .. $#{ $lines->{line} } ) { + my $line = $lines->{line}->[$i]; printf $fmt, @$line; + + next unless $last_lines; + + my $last_line = $last_lines->[$i]; + my @c = ( 'instance', ps_cols_visible ); + my @influx; + foreach my $j ( 0 .. $#$line ) { + #push @influx, $c[$j] . '=' . $line->[$j]; + push @influx, $c[$j] . '=' + . ( $j >= 9 && $j != 13 ? $line->[$j] - $last_line->[$j] : $line->[$j] ) + . ( $j == 3 || $j >= 6 && $j != 9 ? 'i' : '' ); + } + my $influx = join(',', @influx); + $influx =~ s/,user=([^,]+)/ user="$1"/; + print $influx_fh "ganeti,$influx\n" unless $influx =~ m/(#|__)/; + } +store $lines->{line}, '/dev/shm/ganeti.last.storable'; + +#system "curl -i -XPOST 'http://127.0.0.1:8186/write?db=ganeti' --data-binary '@/dev/shm/ganeti.influx'";