X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=gnt-i;h=4d85f48b3f1b935a8b50ba05f3f333994f6f2497;hb=1a0bcd5f323bb04252c16748d2a1e86acc77a5c8;hp=115b8467bb998c7229be208a58902203885e7c23;hpb=a0e4964c4c87e27da8bdb0471e23bbc527b9aa34;p=gnt-info diff --git a/gnt-i b/gnt-i index 115b846..4d85f48 100755 --- a/gnt-i +++ b/gnt-i @@ -11,10 +11,23 @@ chomp $hostname; use Data::Dumper; sub XXX { $DEBUG ? warn "XXX ",Dumper( @_ ) : {} }; +my $stat; +my $mac_to_name; +my $instance_tap; +my $tap_instance; +my $lines; + +my @nodes = @ARGV; + +@nodes = map { chomp ; $_ } `gnt-node list -o name --no-header` unless @nodes; + +next_node: my $ssh = ''; -if ( @ARGV ) { - $hostname = $ARGV[0]; +if ( @nodes ) { + $hostname = shift @nodes; $ssh = "ssh $hostname "; + $hostname =~ s/\..+$//; # -s + warn "## hostname $hostname\n"; } # if prefixed with _ it will be hiddden from output, _args must be last! @@ -30,10 +43,7 @@ my @ps_cols = qw( user pid _args); sub ps_cols_all { map { my $t = $_; $t =~ s/^_//; $t } @ps_cols }; -sub ps_cols_visible { grep { ! /^_/ } @ps_cols }; - -my $stat; -my $mac_to_name; +sub ps_cols_visible { 'node', grep { ! /^_/ } @ps_cols, 'rx', 'tx' }; sub DD_hh_mm_ss { my $t = shift; @@ -53,9 +63,15 @@ sub DD_hh_mm_ss { return $t_sec; } -my $cmd = 'ps --no-headers axwwo ' . join(',', ps_cols_all); -warn "## $cmd\n"; -open(my $ps, '-|', $ssh . $cmd); +sub sh { + my $cmd = join(' ', @_); + $cmd = "$ssh '$cmd'"; + warn "## $cmd\n"; + open(my $fh, '-|', $cmd); + return $fh; +} + +my $ps = sh 'ps --no-headers axwwo ' . join(',', ps_cols_all); while(<$ps>) { chomp; s/^\s*//; @@ -70,39 +86,104 @@ while(<$ps>) { my $name = $1; $stat->{$name}->{$_} = $h{$_} foreach ps_cols_all; + $stat->{$name}->{node} = $hostname; + while ( $h{_args} =~ m/mac=([0-9a-fA-F:]+)/g ) { - $mac_to_name->{$1} = $name; + $mac_to_name->{$hostname}->{$1} = $name; } } else { # warn "## SKIP [$_]\n"; - $stat->{ '__' . $hostname }->{$_} += $h{$_} foreach qw( pcpu pmem vsz rss cputime etimes maj_flt min_flt ); + $stat->{ '__' . $hostname }->{$_} += $h{$_} foreach qw( pcpu pmem vsz rss + nlwp cputime etimes + maj_flt min_flt + ); } } -warn '# mac_to_name ', Dumper( $mac_to_name ); -open(my $ip, '-|', $ssh . 'ip -s -o link'); +my $tap = sh('grep . /var/run/ganeti/kvm-hypervisor/nic/*/*'); +while(<$tap>) { + chomp; +# warn "## tap $_\n"; + my @p = split(/\//,$_); + push @{ $instance_tap->{$hostname}->{ $p[-2] } }, $p[-1]; + + my $if = $p[-1]; + $if =~ s/\d://; + $tap_instance->{$hostname}->{$if} = $p[-2]; +} + +=for later + +my $ip = sh('ip -s -o link'); while(<$ip>) { chomp; if ( m/master\s+(\S+).+ether\s+([0-9a-fA-F:]+).+RX:\s+.+\\\s+(\d+).+TX:\s+.+\\\s+(\d+)/ ) { - my ( $br, $mac, $rx, $tx ) = ( $1, $2, $3, $4 ); - if ( my $name = $mac_to_name->{$mac} ) { - $stat->{$name}->{link}->{ $br } = [ $rx, $tx ]; + my ( $if, $mac, $rx, $tx ) = ( $1, $2, $3, $4 ); + if ( my $name = $tap_instance->{$hostname}->{$if} ) { + $stat->{$name}->{link}->{ $if } = [ $rx, $tx ]; + warn "## ip $name $ip $mac $rx $tx\n"; } else { - warn "## SKIP MAC $mac [$_]\n" if $DEBUG; + warn "## ip SKIP $if $mac $rx $tx\n"; # XXX if $DEBUG; } } else { warn "## SKIP $_\n" if $DEBUG; } } +=cut + +my $dev = sh 'grep : /proc/net/dev'; +while(<$dev>) { + chomp; + s/^\s+//; + my @l = split(/[:\s]+/, $_); +#warn "XXX $_ -> ",Dumper( \@l ); + if ( my $instance = $tap_instance->{$hostname}->{ $l[0] } ) { + $stat->{$instance}->{rx} += $l[1]; + $stat->{$instance}->{tx} += $l[9]; + } elsif ( $l[0] =~ m/eth/ ) { # connect hardware eth devices under node + $stat->{ '__' . $hostname }->{rx} += $l[1]; + $stat->{ '__' . $hostname }->{tx} += $l[9]; + } +} + + +goto next_node if @nodes; + + + +# dump some useful data structures + +sub tab_dump { + my ( $name, $hash ) = @_; + warn "# $name\n"; + foreach my $key ( sort keys %$hash ) { + warn $key, "\t", $hash->{$key}, "\n"; + } +} + + + +foreach my $node ( sort keys %$mac_to_name ) { + tab_dump "$node mac instance", $mac_to_name->{$node}; +} +#warn Dumper( $mac_to_name ); +#tab_dump 'instance_tap', $instance_tap; +#warn Dumper( $instance_tap ); +#warn Dumper( $tap_instance ); + + warn "# stat ", Dumper( $stat ) if $DEBUG; -XXX( @ps_cols ); -my $lines; + +# dump tablable ascii output + +#XXX( @ps_cols ); + sub push_line { my @l = @_; foreach my $i ( 0 .. $#l ) { @@ -121,10 +202,11 @@ foreach my $name ( sort keys %$stat ) { push_line( $name, map { $stat->{$name}->{$_} } ps_cols_visible ); } -XXX $lines; +#XXX $lines; my $fmt = join(' ', map { '%' . $_ . 's' } @{ $lines->{len} } ) . "\n"; warn "# fmt = [$fmt]" if $DEBUG; foreach my $line ( @{ $lines->{line} } ) { printf $fmt, @$line; } +