[pve-devel] r5665 - in qemu-server/pve2: . PVE
svn-commits at proxmox.com
svn-commits at proxmox.com
Wed Mar 9 12:32:53 CET 2011
Author: dietmar
Date: 2011-03-09 12:32:53 +0100 (Wed, 09 Mar 2011)
New Revision: 5665
Modified:
qemu-server/pve2/ChangeLog
qemu-server/pve2/PVE/QemuServer.pm
Log:
report sizes in bytes, list disk size
Modified: qemu-server/pve2/ChangeLog
===================================================================
--- qemu-server/pve2/ChangeLog 2011-03-09 11:13:18 UTC (rev 5664)
+++ qemu-server/pve2/ChangeLog 2011-03-09 11:32:53 UTC (rev 5665)
@@ -1,3 +1,8 @@
+2011-03-09 Proxmox Support Team <support at proxmox.com>
+
+ * PVE/QemuServer.pm (vmstatus): report sizes in bytes, list disk
+ size.
+
2011-03-04 Proxmox Support Team <support at proxmox.com>
* PVE/QemuServer.pm (config_to_command): require kvm 0.14.0
Modified: qemu-server/pve2/PVE/QemuServer.pm
===================================================================
--- qemu-server/pve2/PVE/QemuServer.pm 2011-03-09 11:13:18 UTC (rev 5664)
+++ qemu-server/pve2/PVE/QemuServer.pm 2011-03-09 11:32:53 UTC (rev 5665)
@@ -1580,12 +1580,65 @@
return $vzlist;
}
+my $storage_timeout_hash = {};
+sub disksize {
+ my ($storecfg, $conf) = @_;
+
+ my $bootdisk = $conf->{bootdisk};
+ return undef if !$bootdisk;
+ return undef if !valid_drivename($bootdisk);
+
+ return undef if !$conf->{$bootdisk};
+
+ my $drive = parse_drive($bootdisk, $conf->{$bootdisk});
+ return undef if !defined($drive);
+
+ return undef if drive_is_cdrom($drive);
+
+ my $volid = $drive->{file};
+ return undef if !$volid;
+
+ my $path;
+ my $storeid;
+ my $timeoutid;
+
+ if ($volid =~ m|^/|) {
+ $path = $timeoutid = $volid;
+ } else {
+ $storeid = $timeoutid = PVE::Storage::parse_volume_id ($volid);
+ $path = PVE::Storage::path($storecfg, $volid);
+ }
+
+ my $last_timeout = $storage_timeout_hash->{$timeoutid};
+ if ($last_timeout) {
+ if ((time() - $last_timeout) < 5) {
+ # skip storage with errors
+ return undef ;
+ }
+ delete $storage_timeout_hash->{$timeoutid};
+ }
+
+ my ($size, $format, $used);
+
+ ($size, $format, $used) = PVE::Storage::file_size_info($path, 1);
+
+ if (!defined($format)) {
+ # got timeout
+ $storage_timeout_hash->{$timeoutid} = time();
+ return undef;
+ }
+
+ return wantarray ? ($size, $used) : $size;
+}
+
my $last_proc_pid_stat;
sub vmstatus {
my $res = {};
+ my $storecfg = PVE::Storage::config();
+
my $list = vzlist();
my ($uptime) = PVE::ProcFSTools::read_proc_uptime();
@@ -1594,35 +1647,38 @@
my $conf = PVE::Cluster::cfs_read_file($cfspath) || {};
my $d = {};
- $d->{type} = 'qemu';
- $d->{nproc} = 0;
$d->{pid} = $list->{$vmid}->{pid};
+
# fixme: better status?
$d->{status} = $list->{$vmid}->{pid} ? 'running' : 'stopped';
- $d->{ip} = '-';
- # fixme: where to get disk info/usage ?
- $d->{disk} = 0;
- $d->{maxdisk} = 0;
+ if (my ($size, $used) = disksize($storecfg, $conf)) {
+ $d->{disk} = $used;
+ $d->{maxdisk} = $size;
+ } else {
+ $d->{disk} = 0;
+ $d->{maxdisk} = 0;
+ }
$d->{cpus} = ($conf->{sockets} || 1) * ($conf->{cores} || 1);
$d->{name} = $conf->{name} || "VM$vmid";
- $d->{maxmem} = $conf->{memory} ? $conf->{memory} : 0;
+ $d->{maxmem} = $conf->{memory} ? $conf->{memory}*(1024*1024) : 0;
$d->{uptime} = 0;
- $d->{pctcpu} = 0;
+ $d->{cpu} = 0;
$d->{relcpu} = 0;
$d->{mem} = 0;
$res->{$vmid} = $d;
-
}
my $cpuinfo = PVE::ProcFSTools::read_cpuinfo();
my $cpucount = $cpuinfo->{cpus} || 1;
my $ctime = gettimeofday;
+ # fixme: network traffic
+
foreach my $vmid (keys %$list) {
my $d = $res->{$vmid};
@@ -1654,7 +1710,7 @@
$last_proc_pid_stat->{$pid} = {
time => $ctime,
used => $used,
- pctcpu => 0,
+ cpu => 0,
relcpu => 0,
};
next;
@@ -1665,16 +1721,16 @@
if ($dtime > 1000) {
my $dutime = $used - $old->{used};
- $d->{pctcpu} = int((($dutime)*100)/$dtime);
- $d->{relcpu} = int (($d->{pctcpu} * $cpucount) / $vcpus);
+ $d->{cpu} = $dutime/$dtime;
+ $d->{relcpu} = ($d->{cpu} * $cpucount) / $vcpus;
$last_proc_pid_stat->{$pid} = {
time => $ctime,
used => $used,
- pctcpu => $d->{pctcpu},
+ cpu => $d->{cpu},
relcpu => $d->{relcpu},
};
} else {
- $d->{pctcpu} = $old->{pctcpu};
+ $d->{cpu} = $old->{cpu};
$d->{relcpu} = $old->{relcpu};
}
}
More information about the pve-devel
mailing list