Mercurial > openvz
annotate ovz_statshow.pl @ 2:4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
author | Peter Gervai <grin@grin.hu> |
---|---|
date | Mon, 23 Mar 2009 17:00:16 +0100 |
parents | 068d0e1deb08 |
children | 4cd907a693d1 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/perl |
2 #$Id$ | |
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 | 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 |
0 | 7 |
8 use strict; | |
9 use warnings; | |
10 | |
11 use IO::File; | |
12 | |
13 | |
14 my $f_stat = "/proc/vz/vestat"; | |
15 my $stat_ver = "2.2"; | |
1
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
16 # jiffie per second ( zgrep ^CONFIG_HZ /proc/config.gz ) |
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
17 my $jiffies = 100; |
0 | 18 |
19 | |
20 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
|
21 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
|
22 my (%ve, %ve1); |
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
23 |
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
24 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
|
25 chomp $cpu_mhz; |
2
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
26 $cpu_mhz = $cpu_mhz * 1_048_576; |
1
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
27 print "Running on $cpu_mhz MHz CPU(s)\n"; |
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
28 |
0 | 29 |
30 while(1) { | |
1
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
31 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
|
32 |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
33 my $fdata; |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
34 # 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
|
35 sysread $f, $fdata, 65535; |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
36 $f->close; |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
37 |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
38 my @vestat = split /\n/, $fdata; |
1
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
39 |
2
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
40 if( $vestat[0] !~ /Version: $stat_ver/ ) { |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
41 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
|
42 } |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
43 my $debug_proc = ""; |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
44 for my $i ( 2 .. $#vestat ) { |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
45 my $l = $vestat[$i]; |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
46 #chomp $l; |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
47 $l =~ s/^\s*(.*?)\s*$/$1/; |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
48 #print "##$l##\n"; |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
49 $debug_proc .= "$l\n"; |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
50 my @d = split /\s+/, $l; |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
51 # 0veid, 1user, 2nice, 3systm, 4uptime, <- jiffy |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
52 # 5idle, (6strv), 7uptime, 8used, (9maxlat, 10totlat, 11numched) <- cycles |
0 | 53 $ve{$d[0]} = [ @d[0..11] ]; |
54 } | |
55 | |
56 for my $veid ( sort {$a<=>$b} keys %ve ) { | |
57 if( defined( $ve1{$veid} ) ) { | |
2
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
58 printf "%03d:", $veid; |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
59 for my $i ( 0..$#fields ) { |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
60 my $field = $fields[$i]; |
1
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
61 #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
|
62 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
|
63 printf "%6s(%3d)=", $fieldname[$i], $field; |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
64 |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
65 if( $val < 0 ) { |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
66 # debug |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
67 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
|
68 print "$debug_proc\n"; |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
69 } |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
70 |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
71 if( $field < 5 ) { |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
72 printf "%4d", &jiffie2ms( $val ); |
1
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
73 } else { |
2
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
74 printf "%4d", &cycle2ms( $val ); |
1
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 print "; "; |
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
77 if( $field == 7 ) { |
2
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
78 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
|
79 } |
0 | 80 } |
81 print "\n"; | |
82 } | |
1
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
83 $ve1{$veid} = $ve{$veid}; |
0 | 84 } |
1
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
85 print "\n"; |
0 | 86 sleep(1); |
87 } | |
1
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
88 |
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
89 |
2
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
90 sub cycle2ms ($) { |
4080b53fd4a2
ovz_statshow: Works but vestat seems buggy
Peter Gervai <grin@grin.hu>
parents:
1
diff
changeset
|
91 return int( (shift) / $cpu_mhz * 1000 ); |
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 |
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
94 |
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
95 sub jiffie2ms ($) { |
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
96 return int( (shift) / $jiffies * 1000 ); |
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 |