annotate ovz_statshow.pl @ 0:efb595e3b0a2

ovz_statshow v0.0
author Peter Gervai <grin@grin.hu>
date Mon, 23 Mar 2009 13:26:48 +0100
parents
children 068d0e1deb08
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";
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
14
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
15 my $f = new IO::File "< $f_stat" or die $!;
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
16 my $l = <$f>;
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
17 if( $l !~ /Version: $stat_ver/ ) {
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
18 die "Unknown file version $l, required $stat_ver";
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
19 }
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
20
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
21 $l = <$f>; # headers
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
22
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
23 my @fields = (1,2,3,4,5,7,8);
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
24 my %ve, %ve1;
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) {
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
27 while( <$f> ) {
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
28 chomp;
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
29 my @d = split;
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
30 # 0veid, 1user, 2nice, 3systm, 4uptime, 5idle, (6strv)
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
31 # 7uptime, 8used, (9maxlat, 10totlat, 11numched)
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
32 $ve{$d[0]} = [ @d[0..11] ];
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
33 }
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
34
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
35 for my $veid ( sort {$a<=>$b} keys %ve ) {
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
36 if( defined( $ve1{$veid} ) ) {
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
37 print "$veid: ";
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
38 for my $field ( @fields ) {
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
39 print "$field=", $ve{$veid}->[$field] - $ve1{$veid}->[$field];
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 print "\n";
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
42 }
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
43 $ve1{$veid}->[$field] = $ve{$veid}->[$field];
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
44 }
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
45
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
46 sleep(1);
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
47 }