comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:efb595e3b0a2
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";
14
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
23 my @fields = (1,2,3,4,5,7,8);
24 my %ve, %ve1;
25
26 while(1) {
27 while( <$f> ) {
28 chomp;
29 my @d = split;
30 # 0veid, 1user, 2nice, 3systm, 4uptime, 5idle, (6strv)
31 # 7uptime, 8used, (9maxlat, 10totlat, 11numched)
32 $ve{$d[0]} = [ @d[0..11] ];
33 }
34
35 for my $veid ( sort {$a<=>$b} keys %ve ) {
36 if( defined( $ve1{$veid} ) ) {
37 print "$veid: ";
38 for my $field ( @fields ) {
39 print "$field=", $ve{$veid}->[$field] - $ve1{$veid}->[$field];
40 }
41 print "\n";
42 }
43 $ve1{$veid}->[$field] = $ve{$veid}->[$field];
44 }
45
46 sleep(1);
47 }