--- misc/xenconsole/ajaxdata.php 2012/12/01 16:17:13 1890 +++ misc/xenconsole/ajaxdata.php 2012/12/02 14:56:06 1891 @@ -37,7 +37,6 @@ $vms_array = $xenserver->VM__get_all_records(); - header("Content-Type: text/xml"); echo ""; echo ""; @@ -46,7 +45,7 @@ echo ""; // List all machines -foreach($vms_array as $vm) { +foreach($vms_array as $vmref => $vm) { if ($vm["is_a_template"] != 0 || $vm["is_control_domain"] != 0) { continue; } @@ -55,18 +54,26 @@ $name = $vm["name_label"]; $uuid = $vm["uuid"]; $state = $vm["power_state"] ; + $cpus = $vm["VCPUs_max"]; $network = ""; $url = ""; $session = ""; $os = ""; + $cpuavg = 0.0; if ( $vm["power_state"] == "Running" ) { if ($vm["guest_metrics"] != "OpaqueRef:NULL") {//guest tools installed $guest_metrics = $xenserver->VM_guest_metrics__get_record( $vm["guest_metrics"] ); $network = implode( ",", $guest_metrics["networks"]) ; $os = $guest_metrics["os_version"]["name"]; } + $cpusum = 0.0; + for ($i=0; $i<$cpus; $i++) { + $cpusum += $xenserver->VM__query_data_source($vmref, "cpu" . $i); + } + $cpuavg = round ( ($cpusum/$cpus) * 100); + foreach($vm["consoles"] as $conref) { $con = $xenserver->console__get_record( $conref ); @@ -88,6 +95,7 @@ echo "{$url}"; echo "{$session}"; echo "{$os}"; + echo "{$cpuavg}"; echo ""; }