diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ovz_statshow.pl	Mon Mar 23 13:26:48 2009 +0100
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+#$Id$
+#(C)Peter Gervai, 2009
+#
+
+use strict;
+use warnings;
+
+use IO::File;
+
+
+my $f_stat = "/proc/vz/vestat";
+my $stat_ver = "2.2";
+
+my $f = new IO::File "< $f_stat" or die $!;
+my $l = <$f>;
+if( $l !~ /Version: $stat_ver/ ) {
+    die "Unknown file version $l, required $stat_ver";
+}
+
+$l = <$f>; # headers
+
+my @fields = (1,2,3,4,5,7,8);
+my %ve, %ve1;
+
+while(1) {
+    while( <$f> ) {
+        chomp;
+        my @d = split;
+        # 0veid, 1user, 2nice, 3systm, 4uptime, 5idle, (6strv)
+        # 7uptime, 8used, (9maxlat, 10totlat, 11numched)
+        $ve{$d[0]} = [ @d[0..11] ];
+    }
+    
+    for my $veid ( sort {$a<=>$b} keys %ve ) {
+        if( defined( $ve1{$veid} ) ) {
+            print "$veid: ";
+            for my $field ( @fields ) {
+                print "$field=", $ve{$veid}->[$field] - $ve1{$veid}->[$field];
+            }
+            print "\n";
+        }
+        $ve1{$veid}->[$field] = $ve{$veid}->[$field];
+    }
+    
+    sleep(1);
+}