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