Mercurial > openvz
diff ovz_statshow.pl @ 1:068d0e1deb08
ovz_statshow: almost works now :)
author | Peter Gervai <grin@grin.hu> |
---|---|
date | Mon, 23 Mar 2009 14:08:23 +0100 |
parents | efb595e3b0a2 |
children | 4080b53fd4a2 |
line wrap: on
line diff
--- a/ovz_statshow.pl Mon Mar 23 13:26:48 2009 +0100 +++ b/ovz_statshow.pl Mon Mar 23 14:08:23 2009 +0100 @@ -11,19 +11,26 @@ my $f_stat = "/proc/vz/vestat"; my $stat_ver = "2.2"; +# jiffie per second ( zgrep ^CONFIG_HZ /proc/config.gz ) +my $jiffies = 100; -my $f = new IO::File "< $f_stat" or die $!; -my $l = <$f>; -if( $l !~ /Version: $stat_ver/ ) { - die "Unknown file version $l, required $stat_ver"; -} - -$l = <$f>; # headers my @fields = (1,2,3,4,5,7,8); -my %ve, %ve1; +my (%ve, %ve1); + +my $cpu_mhz = qx( egrep '^cpu MHz' /proc/cpuinfo | head -n1 | awk '{print \$4}' ); +chomp $cpu_mhz; +print "Running on $cpu_mhz MHz CPU(s)\n"; + while(1) { + my $f = new IO::File "< $f_stat" or die $!; + my $l = <$f>; + if( $l !~ /Version: $stat_ver/ ) { + die "Unknown file version $l, required $stat_ver"; + } + $l = <$f>; # headers + while( <$f> ) { chomp; my @d = split; @@ -36,12 +43,34 @@ if( defined( $ve1{$veid} ) ) { print "$veid: "; for my $field ( @fields ) { - print "$field=", $ve{$veid}->[$field] - $ve1{$veid}->[$field]; + #print "[$field,", $ve{$veid}, ",", $ve1{$veid} ,",", $ve{$veid}->[$field],",", $ve1{$veid}->[$field], "] "; + my $val = $ve{$veid}->[$field] - $ve1{$veid}->[$field]; + print "field="; + if( $field <6 ) { + print &jiffie2ms( $val ); + } else { + print &clock2ms( $val ); + } + print "; "; + if( $field == 7 ) { + print "<", &clock2ms( $val - ($ve{$veid}->[5] - $ve1{$veid}->[5]) ), "> "; + } } print "\n"; } - $ve1{$veid}->[$field] = $ve{$veid}->[$field]; + $ve1{$veid} = $ve{$veid}; } - + print "\n"; sleep(1); } + + +sub clock2ms ($) { + return int( (shift) / ( $cpu_mhz * $jiffies * $jiffies ) * 1000 ); +} + + +sub jiffie2ms ($) { + return int( (shift) / $jiffies * 1000 ); +} +