Changes

Jump to: navigation, search

Human readable user beancounters

3,009 bytes added, 19:18, 9 November 2008
Added patch to display VE hostname
close(BEANS);
</source>
 
Here's a quick patch which adds on VE hostname lookups. It depends on vzlist being in the path but won't break if it isn't.
 
<source lang=perl>
*** beanCounters.pl-orig Sun Nov 9 14:08:56 2008
--- beanCounters.pl Sun Nov 9 14:08:21 2008
***************
*** 9,14 ****
--- 9,17 ----
# The script can be distributed freely for everybody who finds it usable.
#
# Christian Anton <mail |_at_| christiananton.de> 2008-09-18
+ #
+ # David Osborn <ossdev -at- daoCon.com> 2008-11-09
+ # Added VE name to output
***************
*** 147,158 ****
sub print_header {
my $uid = shift;
print "#####################################################################################################################\n";
! print "BEANS FOR UID $uid\n";
print "resource held maxheld barrier limit failcnt\n";
}
# now eat your beans baby
while (<BEANS>) {
chomp($line = $_);
--- 150,193 ----
sub print_header {
my $uid = shift;
+ my $hostname = shift;
print "#####################################################################################################################\n";
! print "BEANS FOR UID $uid ($hostname)\n";
print "resource held maxheld barrier limit failcnt\n";
}
+ sub get_hostname {
+ my $uid = shift;
+ my @vzout;
+
+ # already retrieved list
+ if (defined %hostnames) {
+ if (defined $hostnames{$uid}) {
+ return $hostnames{$uid};
+ } else {
+ return 'not found';
+ }
+ # try to retrieve the list
+ } elsif ( eval(@vzout = `vzlist -H -o veid,hostname`) ) {
+ $hostnames{0} = 'HN';
+ while (@vzout) {
+ my $line = shift @vzout;
+ my ($tuid,$hostname) = $line =~ /^\s+(\d+)\s+(\S+)/;
+ $hostnames{$tuid} = $hostname;
+ }
+ return $hostnames{$uid};
+ } else {
+ # something's wrong
+ return 'unknown';
+ }
+
+ }
+
+
+ # Hash used to store uid to hostname lookups
+ my %hostnames;
+
# now eat your beans baby
while (<BEANS>) {
chomp($line = $_);
***************
*** 166,172 ****
$uid = $line;
$line =~ s/^(\s+)(\d+):/$1/;
$uid =~ s/^(\s+)(\d+):.*$/$2/;
! &print_header($uid);
&work_line($line);
} else {
&work_line($line);
--- 201,207 ----
$uid = $line;
$line =~ s/^(\s+)(\d+):/$1/;
$uid =~ s/^(\s+)(\d+):.*$/$2/;
! &print_header($uid, get_hostname($uid));
&work_line($line);
} else {
&work_line($line);
</source>
1
edit

Navigation menu