Mercurial > openvz
annotate ovz_statshow.pl @ 3:4cd907a693d1
ovz_statshow: some comment for people using it from the outside world
author | Peter Gervai <grin@grin.hu> |
---|---|
date | Mon, 23 Mar 2009 17:06:10 +0100 |
parents | 4080b53fd4a2 |
children |
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 |
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 | 10 |
11 use strict; | |
12 use warnings; | |
13 | |
14 use IO::File; | |
15 | |
16 | |
17 my $f_stat = "/proc/vz/vestat"; | |
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 | 21 |
22 | |
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 | 32 |
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 | 56 $ve{$d[0]} = [ @d[0..11] ]; |
57 } | |
58 | |
59 for my $veid ( sort {$a<=>$b} keys %ve ) { | |
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 | 84 } |
85 print "\n"; | |
86 } | |
1
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
87 $ve1{$veid} = $ve{$veid}; |
0 | 88 } |
1
068d0e1deb08
ovz_statshow: almost works now :)
Peter Gervai <grin@grin.hu>
parents:
0
diff
changeset
|
89 print "\n"; |
0 | 90 sleep(1); |
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 |