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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
1 #!/usr/bin/perl
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
2 #$Id$
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
3 #(C)Peter Gervai, 2009
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
4 #
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
5
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
6 use strict;
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
7 use warnings;
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
8
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
9 use IO::File;
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
10
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
11
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
12 my $f_stat = "/proc/vz/vestat";
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
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
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
16
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
17
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
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
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
25
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
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
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
34 while( <$f> ) {
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
35 chomp;
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
36 my @d = split;
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
37 # 0veid, 1user, 2nice, 3systm, 4uptime, 5idle, (6strv)
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
38 # 7uptime, 8used, (9maxlat, 10totlat, 11numched)
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
39 $ve{$d[0]} = [ @d[0..11] ];
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
40 }
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
41
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
42 for my $veid ( sort {$a<=>$b} keys %ve ) {
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
43 if( defined( $ve1{$veid} ) ) {
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
44 print "$veid: ";
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
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
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
58 }
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
59 print "\n";
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
60 }
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
61 $ve1{$veid} = $ve{$veid};
0
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
62 }
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
63 print "\n";
0
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
64 sleep(1);
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
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