Mercurial > openvz
comparison 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 |
comparison
equal
deleted
inserted
replaced
0:efb595e3b0a2 | 1:068d0e1deb08 |
---|---|
9 use IO::File; | 9 use IO::File; |
10 | 10 |
11 | 11 |
12 my $f_stat = "/proc/vz/vestat"; | 12 my $f_stat = "/proc/vz/vestat"; |
13 my $stat_ver = "2.2"; | 13 my $stat_ver = "2.2"; |
14 # jiffie per second ( zgrep ^CONFIG_HZ /proc/config.gz ) | |
15 my $jiffies = 100; | |
14 | 16 |
15 my $f = new IO::File "< $f_stat" or die $!; | |
16 my $l = <$f>; | |
17 if( $l !~ /Version: $stat_ver/ ) { | |
18 die "Unknown file version $l, required $stat_ver"; | |
19 } | |
20 | |
21 $l = <$f>; # headers | |
22 | 17 |
23 my @fields = (1,2,3,4,5,7,8); | 18 my @fields = (1,2,3,4,5,7,8); |
24 my %ve, %ve1; | 19 my (%ve, %ve1); |
20 | |
21 my $cpu_mhz = qx( egrep '^cpu MHz' /proc/cpuinfo | head -n1 | awk '{print \$4}' ); | |
22 chomp $cpu_mhz; | |
23 print "Running on $cpu_mhz MHz CPU(s)\n"; | |
24 | |
25 | 25 |
26 while(1) { | 26 while(1) { |
27 my $f = new IO::File "< $f_stat" or die $!; | |
28 my $l = <$f>; | |
29 if( $l !~ /Version: $stat_ver/ ) { | |
30 die "Unknown file version $l, required $stat_ver"; | |
31 } | |
32 $l = <$f>; # headers | |
33 | |
27 while( <$f> ) { | 34 while( <$f> ) { |
28 chomp; | 35 chomp; |
29 my @d = split; | 36 my @d = split; |
30 # 0veid, 1user, 2nice, 3systm, 4uptime, 5idle, (6strv) | 37 # 0veid, 1user, 2nice, 3systm, 4uptime, 5idle, (6strv) |
31 # 7uptime, 8used, (9maxlat, 10totlat, 11numched) | 38 # 7uptime, 8used, (9maxlat, 10totlat, 11numched) |
34 | 41 |
35 for my $veid ( sort {$a<=>$b} keys %ve ) { | 42 for my $veid ( sort {$a<=>$b} keys %ve ) { |
36 if( defined( $ve1{$veid} ) ) { | 43 if( defined( $ve1{$veid} ) ) { |
37 print "$veid: "; | 44 print "$veid: "; |
38 for my $field ( @fields ) { | 45 for my $field ( @fields ) { |
39 print "$field=", $ve{$veid}->[$field] - $ve1{$veid}->[$field]; | 46 #print "[$field,", $ve{$veid}, ",", $ve1{$veid} ,",", $ve{$veid}->[$field],",", $ve1{$veid}->[$field], "] "; |
47 my $val = $ve{$veid}->[$field] - $ve1{$veid}->[$field]; | |
48 print "field="; | |
49 if( $field <6 ) { | |
50 print &jiffie2ms( $val ); | |
51 } else { | |
52 print &clock2ms( $val ); | |
53 } | |
54 print "; "; | |
55 if( $field == 7 ) { | |
56 print "<", &clock2ms( $val - ($ve{$veid}->[5] - $ve1{$veid}->[5]) ), "> "; | |
57 } | |
40 } | 58 } |
41 print "\n"; | 59 print "\n"; |
42 } | 60 } |
43 $ve1{$veid}->[$field] = $ve{$veid}->[$field]; | 61 $ve1{$veid} = $ve{$veid}; |
44 } | 62 } |
45 | 63 print "\n"; |
46 sleep(1); | 64 sleep(1); |
47 } | 65 } |
66 | |
67 | |
68 sub clock2ms ($) { | |
69 return int( (shift) / ( $cpu_mhz * $jiffies * $jiffies ) * 1000 ); | |
70 } | |
71 | |
72 | |
73 sub jiffie2ms ($) { | |
74 return int( (shift) / $jiffies * 1000 ); | |
75 } | |
76 |