#!/usr/bin/perl -w use strict; use Data::Dump qw/dump/; my $watch_current = 'held'; my $watch_max = 'limit'; # tune optimizer my $increase_over = 0.95; # 95% of resource $watch used my $increase_limit = 1.1; my $increase_barrier = 1.2; ($watch_current,$watch_max) = ('maxheld','barrier'); my $debug = 0; my $proc='/proc/user_beancounters'; $proc='./user_beancounters' if (! -e $proc); open(my $bc, '<', $proc) || die "can't open $proc: $!"; my @cols; my $vmid; my $d; warn "increasing $proc if $watch_current > $watch_max * $increase_over\n"; while(<$bc>) { chomp; next if (/^Version/); $vmid = $1 if (s/^\s+(\d+):\s+//); s/^\s+//; my @d = split(/\s+/,$_); if ($#d == 6 && $d[0] =~ m/^\w+$/) { @cols = splice(@d,1); # warn "## found cols: ", dump(@cols), "\n"; next; } my $res = $d[0]; foreach my $i ( 1 .. $#cols ) { $d->{ $vmid }->{ $res }->{ $cols[$i] } = $d[$i]; } my $r = $d->{ $vmid }->{ $res }; if ($r->{failcnt} > 0) { if ( ($r->{ $watch_current } / $r->{ $watch_max }) > $increase_over ) { my $new_limit = int( $r->{ $watch_max } * $increase_limit ); my $new_barr = int( $r->{ $watch_max } * $increase_barrier ); warn "# $vmid $res $r->{ $watch_max } -> $new_limit:$new_barr\n"; my $cmd = "vzctl set $vmid --${res} $new_limit:$new_barr --save"; warn $cmd,$/; system $cmd if (! $debug); } else { warn sprintf("%s/%s failed, but not used %d%% [%d/%d %d%%]\n", $vmid, $res, $increase_over * 100, $r->{ $watch_current }, $r->{ $watch_max }, ($r->{ $watch_current }/$r->{ $watch_max })*100 ); } } } close($bc); #print dump($d);