annotate ovz_statshow.pl @ 4:c2cff30df6dc

Add openvz_checker.pl (24:1c29ac915688) form local repo * check ovz setting consistency
author Peter Gervai <grin@grin.hu>
date Thu, 17 Oct 2013 08:49:10 +0200
parents 4cd907a693d1
children
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
2
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
4 # email: grin.grin.hu
0
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
5 #
2
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
6 # Released under GPL v2 or later and CC-BY-SA-3.0
3
4cd907a693d1 ovz_statshow: some comment for people using it from the outside world
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
7 #
4cd907a693d1 ovz_statshow: some comment for people using it from the outside world
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
8 # Lists openvz VE usage statistics.
4cd907a693d1 ovz_statshow: some comment for people using it from the outside world
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
9 #
0
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 use strict;
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
12 use warnings;
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
13
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
14 use IO::File;
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
15
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 my $f_stat = "/proc/vz/vestat";
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
18 my $stat_ver = "2.2";
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
19 # jiffie per second ( zgrep ^CONFIG_HZ /proc/config.gz )
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
20 my $jiffies = 100;
0
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
21
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);
2
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
24 my @fieldname = qw( user nice sys up idle up_c used_c );
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
25 my (%ve, %ve1);
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
26
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
27 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
28 chomp $cpu_mhz;
2
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
29 $cpu_mhz = $cpu_mhz * 1_048_576;
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
30 print "Running on $cpu_mhz MHz CPU(s)\n";
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
31
0
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
32
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
33 while(1) {
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
34 my $f = new IO::File "< $f_stat" or die $!;
2
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
35
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
36 my $fdata;
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
37 # have to read one chunk at once :-/ length is arbitrary
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
38 sysread $f, $fdata, 65535;
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
39 $f->close;
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
40
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
41 my @vestat = split /\n/, $fdata;
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
42
2
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
43 if( $vestat[0] !~ /Version: $stat_ver/ ) {
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
44 die "Unknown file version $vestat[0], required $stat_ver";
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
45 }
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
46 my $debug_proc = "";
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
47 for my $i ( 2 .. $#vestat ) {
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
48 my $l = $vestat[$i];
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
49 #chomp $l;
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
50 $l =~ s/^\s*(.*?)\s*$/$1/;
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
51 #print "##$l##\n";
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
52 $debug_proc .= "$l\n";
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
53 my @d = split /\s+/, $l;
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
54 # 0veid, 1user, 2nice, 3systm, 4uptime, <- jiffy
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
55 # 5idle, (6strv), 7uptime, 8used, (9maxlat, 10totlat, 11numched) <- cycles
0
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
56 $ve{$d[0]} = [ @d[0..11] ];
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
57 }
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 for my $veid ( sort {$a<=>$b} keys %ve ) {
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
60 if( defined( $ve1{$veid} ) ) {
2
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
61 printf "%03d:", $veid;
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
62 for my $i ( 0..$#fields ) {
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
63 my $field = $fields[$i];
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
64 #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
65 my $val = $ve{$veid}->[$field] - $ve1{$veid}->[$field];
2
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
66 printf "%6s(%3d)=", $fieldname[$i], $field;
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
67
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
68 if( $val < 0 ) {
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
69 # debug
3
4cd907a693d1 ovz_statshow: some comment for people using it from the outside world
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
70 print "NEGATIVE VALUE!!\n";
2
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
71 print "\n#", $ve{$veid}->[$field], ' ', $ve1{$veid}->[$field], "#$_#\n";
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
72 print "$debug_proc\n";
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
73 }
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
74
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
75 if( $field < 5 ) {
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
76 printf "%4d", &jiffie2ms( $val );
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
77 } else {
2
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
78 printf "%4d", &cycle2ms( $val );
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
79 }
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
80 print "; ";
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
81 if( $field == 7 ) {
2
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
82 printf "<%4d> ", &cycle2ms( $val - ($ve{$veid}->[5] - $ve1{$veid}->[5]) );
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
83 }
0
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
84 }
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
85 print "\n";
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
86 }
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
87 $ve1{$veid} = $ve{$veid};
0
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
88 }
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
89 print "\n";
0
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
90 sleep(1);
efb595e3b0a2 ovz_statshow v0.0
Peter Gervai <grin@grin.hu>
parents:
diff changeset
91 }
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
92
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
93
2
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
94 sub cycle2ms ($) {
4080b53fd4a2 ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
95 return int( (shift) / $cpu_mhz * 1000 );
1
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
96 }
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
97
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
98
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
99 sub jiffie2ms ($) {
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
100 return int( (shift) / $jiffies * 1000 );
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
101 }
068d0e1deb08 ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
102