/[vz-tools]/trunk/vz-optimize.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/vz-optimize.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 14 - (show annotations)
Wed Jan 31 21:12:47 2007 UTC (17 years, 1 month ago) by dpavlin
File MIME type: text/plain
File size: 1214 byte(s)
new limit is 10% larger than current value, and new barrier is 20% larger.
execute vzctl with --save
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Data::Dump qw/dump/;
6
7 my $proc='/proc/user_beancounters';
8 $proc='./user_beancounters' if (! -e $proc);
9
10 open(my $bc, '<', $proc) || die "can't open $proc: $!";
11
12 my @cols;
13 my $vmid;
14
15 my $d;
16
17 my $increase_over = 0.95; # 95% of resource limit used
18
19 while(<$bc>) {
20 chomp;
21 next if (/^Version/);
22
23 $vmid = $1 if (s/^\s+(\d+):\s+//);
24 s/^\s+//;
25
26 my @d = split(/\s+/,$_);
27
28 if ($#d == 6 && $d[0] =~ m/^\w+$/) {
29 @cols = splice(@d,1);
30 # warn "## found cols: ", dump(@cols), "\n";
31 next;
32 }
33
34 my $res = $d[0];
35
36 foreach my $i ( 1 .. $#cols ) {
37 $d->{ $vmid }->{ $res }->{ $cols[$i] } = $d[$i];
38 }
39
40 my $r = $d->{ $vmid }->{ $res };
41
42
43 if ($r->{failcnt} > 0) {
44 if ( ($r->{held} / $r->{limit}) > $increase_over ) {
45 my $new_limit = int($r->{limit} * 1.1);
46 my $new_barr = int($r->{limit} * 1.2);
47 warn "# $vmid $res $r->{limit} -> $new_limit:$new_barr\n";
48 my $cmd = "vzctl set $vmid --${res} $new_limit:$new_barr --save";
49 warn $cmd,$/;
50 system $cmd;
51 } else {
52 warn sprintf("%s/%s failed, but not used %d%% [%d/%d %d%%]\n",
53 $vmid, $res, $increase_over * 100, $r->{held}, $r->{limit}, ($r->{held}/$r->{limit})*100
54 );
55 }
56
57 }
58 }
59 close($bc);
60
61 #print dump($d);

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26