added in 'libvirt.pm' the ability to support multiple disks and network interfaces for each virtual machine

This commit is contained in:
Jordi Sanfeliu 2015-12-04 09:26:49 +01:00
parent 15b6db7eeb
commit 601b1b91e9
2 changed files with 74 additions and 43 deletions

View File

@ -3,6 +3,9 @@ N.N.N - DD-MMM-2015
- Added the option 'cmd' in 'libvirt.pm' in order to be able to execute a - Added the option 'cmd' in 'libvirt.pm' in order to be able to execute a
custom command like 'virsh -r -c qemu:///session'. custom command like 'virsh -r -c qemu:///session'.
(suggested by Pavel Bauer, pbauer AT algotech.cz) (suggested by Pavel Bauer, pbauer AT algotech.cz)
- Added in 'libvirt.pm' the ability to support multiple disks and network
interfaces for each virtual machine.
(suggested by Pavel Bauer, pbauer AT algotech.cz)
- Fixed in 'libvirt.pm' limiting to 100 all CPU values greater than 100. - Fixed in 'libvirt.pm' limiting to 100 all CPU values greater than 100.
- Fixed in 'libvirt.pm' to hide empty groups. - Fixed in 'libvirt.pm' to hide empty groups.
(thanks to Pavel Bauer, pbauer AT algotech.cz for pointing this out) (thanks to Pavel Bauer, pbauer AT algotech.cz for pointing this out)

View File

@ -157,11 +157,27 @@ sub libvirt_update {
my $str; my $str;
my $state = ""; my $state = "";
my $vm = trim($lvl[$n] || ""); my $vm = trim($lvl[$n] || "");
my $vda = trim((split(',', $libvirt->{desc}->{$vm} || ""))[1]);
my $vmac = trim((split(',', $libvirt->{desc}->{$vm} || ""))[2]); my @vda;
my @vmac;
# convert from old configuration to new
if(ref($libvirt->{desc}->{$vm} || "") ne "HASH") {
my $val;
$val = trim((split(',', $libvirt->{desc}->{$vm} || ""))[1]);
push(@vda, $val) if $val;
$val = trim((split(',', $libvirt->{desc}->{$vm} || ""))[2]);
push(@vmac, $val) if $val;
} else {
@vda = split(',', $libvirt->{desc}->{$vm}->{disk} || "");
@vmac = split(',', $libvirt->{desc}->{$vm}->{net} || "");
}
my $vnet = ""; my $vnet = "";
if($vm && (!$vda || !$vmac)) { print "$vm = " . scalar(@vda) . "\n";
if($vm && (!scalar(@vda) || !scalar(@vmac))) {
logger("$myself: missing parameters in '$vm' virtual machine."); logger("$myself: missing parameters in '$vm' virtual machine.");
$vm = ""; # invalidates this vm $vm = ""; # invalidates this vm
} }
@ -173,6 +189,8 @@ sub libvirt_update {
} }
if($state eq "running") { if($state eq "running") {
my $t;
if(open(IN, "$libvirt->{cmd} cpu-stats $vm --total |")) { if(open(IN, "$libvirt->{cmd} cpu-stats $vm --total |")) {
my $c = 0; my $c = 0;
while(<IN>) { while(<IN>) {
@ -196,29 +214,38 @@ sub libvirt_update {
} }
close(IN); close(IN);
} }
if(open(IN, "$libvirt->{cmd} domblkstat $vm $vda |")) {
# summarizes all virtual disks stats for each 'vm'
$t = 0;
foreach (my $vd = trim(split(',', @vda))) {
if(open(IN, "$libvirt->{cmd} domblkstat $vm $vd |")) {
my $r = 0; my $r = 0;
my $w = 0; my $w = 0;
while(<IN>) { while(<IN>) {
if(/^$vda\s+rd_bytes\s+(\d+)$/) { if(/^$vd\s+rd_bytes\s+(\d+)$/) {
$r = $1; $r = $1;
} }
if(/^$vda\s+wr_bytes\s+(\d+)$/) { if(/^$vd\s+wr_bytes\s+(\d+)$/) {
$w = $1; $w = $1;
last; last;
} }
} }
close(IN); close(IN);
my $t = $r + $w; $t += ($r + $w);
}
}
$str = $e . "_dsk" . $n; $str = $e . "_dsk" . $n;
$dsk = $t - ($config->{libvirt_hist}->{$str} || 0); $dsk = $t - ($config->{libvirt_hist}->{$str} || 0);
$dsk = 0 unless $t != $dsk; $dsk = 0 unless $t != $dsk;
$dsk /= 60; $dsk /= 60;
$config->{libvirt_hist}->{$str} = $t; $config->{libvirt_hist}->{$str} = $t;
}
# summarizes all virtual network stats for each 'vm'
$t = 0;
foreach (my $vn = trim(split(',', @vmac))) {
if(open(IN, "$libvirt->{cmd} domiflist $vm |")) { if(open(IN, "$libvirt->{cmd} domiflist $vm |")) {
while(<IN>) { while(<IN>) {
if(/^(\S+)\s+.*?\s+$vmac$/) { if(/^(\S+)\s+.*?\s+$vn$/) {
$vnet = $1; $vnet = $1;
} }
} }
@ -237,14 +264,15 @@ sub libvirt_update {
} }
} }
close(IN); close(IN);
my $t = $r + $w; $t += ($r + $w);
}
}
$str = $e . "_net" . $n; $str = $e . "_net" . $n;
$net = $t - ($config->{libvirt_hist}->{$str} || 0); $net = $t - ($config->{libvirt_hist}->{$str} || 0);
$net = 0 unless $t != $net; $net = 0 unless $t != $net;
$net /= 60; $net /= 60;
$config->{libvirt_hist}->{$str} = $t; $config->{libvirt_hist}->{$str} = $t;
} }
}
$rrdata .= ":$cpu:$mem:$dsk:$net:0:0:0:0"; $rrdata .= ":$cpu:$mem:$dsk:$net:0:0:0:0";
} }
$e++; $e++;