/[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

Annotation of /trunk/vz-optimize.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (hide annotations)
Mon Jan 8 22:59:26 2007 UTC (16 years ago) by dpavlin
File MIME type: text/plain
File size: 1111 byte(s)
rename of optimizer
1 dpavlin 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 dpavlin 3 my $increase_over = 0.95; # 95% of resource limit used
18    
19 dpavlin 1 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 dpavlin 3 if ( ($r->{held} / $r->{limit}) > $increase_over ) {
45 dpavlin 2 my $new_limit = int($r->{limit} * 1.1);
46     # warn "# $vmid $res $r->{limit} -> $new_limit\n";
47     print "vzctl set $vmid --${res} $new_limit\n";
48 dpavlin 1 } else {
49 dpavlin 3 warn sprintf("%s/%s failed, but not used %d%% [%d/%d %d%%]\n",
50     $vmid, $res, $increase_over * 100, $r->{held}, $r->{limit}, ($r->{held}/$r->{limit})*100
51     );
52 dpavlin 1 }
53    
54     }
55     }
56     close($bc);
57    
58     #print dump($d);

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26