comparison openvz_checker.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
children
comparison
equal deleted inserted replaced
3:4cd907a693d1 4:c2cff30df6dc
1 #!/usr/bin/perl
2 #$Id: openvz_checker.pl,v 1c29ac915688 2009/12/09 21:17:13 grin $
3 #(c)Peter Gervai, 2009
4 # GPLv2 / CC-BY-SA 3.0
5 #
6 # check openvz resource settings
7 # based on wiki pages
8 #
9
10 use strict;
11 use warnings;
12
13 use IO::File;
14 use Data::Dumper;
15
16 my $dir_bc = "/proc/bc";
17
18 my $CUR=0;
19 my $MAX=1;
20 my $BAR=2;
21 my $LIM=3;
22
23 # ia32...
24 my $PAGESIZE=4096;
25
26 my @allsocketbuf = qw( tcprcvbuf tcpsndbuf dgramrcvbuf othersockbuf );
27
28 opendir( DIR, $dir_bc );
29 my @veids = grep { /^\d+/ && -d "$dir_bc/$_" } readdir(DIR);
30 closedir( DIR );
31
32 my %res;
33 for my $veid ( @veids ) {
34 next if $veid == 0;
35 my $f = new IO::File "< $dir_bc/$veid/resources" or next;
36 while( <$f> ) {
37 chomp;
38 # trim spaces
39 s/^\s*(.*?)\s*$/$1/;
40 my @data = split /\s+/;
41 # held, maxheld, barrier, limit, failcnt
42 $res{$veid}{$data[0]} = [ @data[1..5] ];
43 }
44 }
45
46 ## total ram
47 my $ram = qx( free | grep Mem: ); chomp $ram;
48 $ram = (split /\s+/, $ram)[1];
49 print "RAM=$ram\n";
50 $ram *= 1024;
51
52 ## swap
53 my $swap = qx( free | grep Swap: ); chomp $swap;
54 $swap = (split /\s+/, $swap)[1];
55 print "SWAP=$swap\n";
56 $swap *= 1024;
57
58
59 my $sum;
60 ### low mem x86_32
61 # max lowram 832MB
62 my $lowram = $ram > 832000000 ? 832000000 : $ram;
63
64
65 ###############################
66 ####### system wide config
67 ###############################
68
69
70 ###############################
71 ## utiliation
72 $sum=0;
73 foreach my $veid (keys %res) {
74 my $b = $res{$veid}{'kmemsize'}->[$CUR];
75 foreach my $sb (@allsocketbuf) {
76 $b += $res{$veid}{$sb}->[$CUR];
77 }
78 $sum += $b;
79 }
80
81 print "Low memory (x86_32) Utilisation: ", &pretty($sum / (0.4 * $lowram));
82 print " ( <1 OK; <2 unsafe; >2 dangerous)\n";
83
84
85 ###############################
86 ## commitment level
87 $sum=0;
88 foreach my $veid (keys %res) {
89 my $b = $res{$veid}{'kmemsize'}->[$LIM];
90 foreach my $sb (@allsocketbuf) {
91 $b += $res{$veid}{$sb}->[$LIM];
92 }
93 $sum += $b;
94 }
95
96 print "Low memory (x86_32) Commitment: ", &pretty($sum / (0.4 * $lowram));
97 print " ( <1 OK; <1.5 acceptable; >2 not recommended)\n";
98
99
100 ############################
101 #### total ram
102 ## utilisation
103 $sum=0;
104 foreach my $veid (keys %res) {
105 my $b = $res{$veid}{'physpages'}->[$CUR] * $PAGESIZE;
106 $b += $res{$veid}{'kmemsize'}->[$CUR];
107 foreach my $sb (@allsocketbuf) {
108 $b += $res{$veid}{$sb}->[$CUR];
109 }
110 $sum += $b;
111 }
112 print "Total RAM utilisation: ", &pretty($sum / $ram);
113 print " ( <0.8 low; <1 ok; >1 impossible)\n";
114
115
116 ############################
117 #### total ram+swap
118 ## utilisation
119 $sum=0;
120 foreach my $veid (keys %res) {
121 my $b = $res{$veid}{'oomguarpages'}->[$CUR] * $PAGESIZE;
122 $b += $res{$veid}{'kmemsize'}->[$CUR];
123 foreach my $sb (@allsocketbuf) {
124 $b += $res{$veid}{$sb}->[$CUR];
125 }
126 $sum += $b;
127 }
128 print "RAM+swap utilisation: ", &pretty($sum / ($ram+$swap));
129 my $low_bound = &pretty($ram / ($ram+$swap));
130 my $hi_bound = &pretty(($ram + 0.5*$swap) / ($ram+$swap));
131 print " ( <$low_bound low; between ok; >$hi_bound bad)\n";
132
133
134 ## commitment
135 $sum=0;
136 foreach my $veid (keys %res) {
137 my $b = $res{$veid}{'oomguarpages'}->[$BAR] * $PAGESIZE;
138 $b += $res{$veid}{'kmemsize'}->[$LIM];
139 foreach my $sb (@allsocketbuf) {
140 $b += $res{$veid}{$sb}->[$LIM];
141 }
142 $sum += $b;
143 }
144 print "RAM+swap commitment: ", &pretty($sum / ($ram+$swap));
145 print " ( <0.8 low; <1 ok; >1 not recommended)\n";
146
147
148 ## allocations
149 $sum=0;
150 foreach my $veid (keys %res) {
151 my $b = $res{$veid}{'privvmpages'}->[$LIM] * $PAGESIZE;
152 $b += $res{$veid}{'kmemsize'}->[$LIM];
153 foreach my $sb (@allsocketbuf) {
154 $b += $res{$veid}{$sb}->[$LIM];
155 }
156 $sum += $b;
157 }
158 print "RAM+swap allocations: ", &pretty($sum / ($ram+$swap));
159 print " ( <1.5 low; <4 ok; >4 not recommended [oom])\n";
160
161
162 ###############################
163 ####### per VE configs
164 ###############################
165 foreach my $veid (sort { $a <=> $b } keys %res) {
166 # <numproc> should be average process num
167 &compare( $veid, $res{$veid}{'kmemsize'}->[$BAR],
168 40*1024*$res{$veid}{'numproc'}->[$CUR] + $res{$veid}{'dcachesize'}->[$LIM],
169 "kmemsize(bar)", "numproc~dcachesize", "kmemsize low for # of processes" );
170
171 &compare( $veid, $res{$veid}{'privvmpages'}->[$BAR], $res{$veid}{'vmguarpages'}->[$BAR],
172 "privvmpages","vmguarpages", "mem alloc less than guarantee" );
173
174
175 &compare( $veid, $res{$veid}{'tcpsndbuf'}->[$LIM] - $res{$veid}{'tcpsndbuf'}->[$BAR],
176 2.5*1024*$res{$veid}{'numtcpsock'}->[$LIM],
177 "tcpsndbuf(lim-bar)", "numtcpsock(lim{bytes})", "tcp may hang");
178
179
180 &compare( $veid, $res{$veid}{'othersockbuf'}->[$LIM] - $res{$veid}{'othersockbuf'}->[$BAR],
181 2.5*1024*$res{$veid}{'numothersock'}->[$LIM],
182 "othersockbuf(lim-bar)", "numothersock{bytes}", "othersock may hang");
183
184
185 &compare( $veid, $res{$veid}{'tcprcvbuf'}->[$LIM] - $res{$veid}{'tcprcvbuf'}->[$BAR],
186 2.5*1024*$res{$veid}{'numothersock'}->[$LIM],
187 "tcprcvbuf(lim-bar)","numothersock{bytes}","may slow tcp" );
188
189
190 if( $res{$veid}{'tcprcvbuf'}->[$BAR] < 65535 ) {
191 print "$veid: tcprcvbuf too low (<64k)\n";
192 }
193
194
195 if( $res{$veid}{'tcpsndbuf'}->[$BAR] < 65535 ) {
196 print "$veid: tcpsndbuf too low (<64k)\n";
197 }
198
199
200 if( $res{$veid}{'dgramrcvbuf'}->[$BAR] < 131200 ) {
201 print "$veid: dgramrcvbuf too low (<129k)\n";
202 }
203
204
205 if( $res{$veid}{'othersockbuf'}->[$BAR] < 131200 ) {
206 print "$veid: othersockbuf too low (<129k)\n";
207 }
208
209
210 # numfile < avgnumproc*32
211 # ...
212
213 if( $res{$veid}{'dcachesize'}->[$BAR] <
214 $res{$veid}{'numfile'}->[$MAX] * 384 ) {
215 print "$veid: dcachesize likely low for dentry and inode allocs\n";
216 }
217
218
219 foreach my $param (keys %{$res{$veid}}) {
220 &compare( $veid, $res{$veid}{$param}->[$LIM], $res{$veid}{$param}->[$BAR],
221 "limit", "barrier", "problem with $param" );
222 }
223 }
224
225
226
227 sub compare {
228 my ($veid, $large, $small, $ltext, $stext, $text) = @_;
229
230 if( $large < $small ) {
231 # bad...
232 print "VE $veid: $text ($ltext=$large < $stext=$small)\n";
233 }
234 return;
235 }
236
237
238
239 sub pretty($) {
240 return sprintf("%6.4f", shift);
241 }