--- misc/xenconsole/ajaxdata.php 2012/12/01 11:27:10 1888 +++ misc/xenconsole/ajaxdata.php 2012/12/02 14:56:06 1891 @@ -27,14 +27,25 @@ /* Establish session with Xenserver */ $xenserver = new XenApi($url, $login, $password); -$vms_array = $xenserver->VM__get_all_records(); +$hosts_array = $xenserver->host__get_all(); +$host = $xenserver->host__get_record($hosts_array[0]); +$host_metrics = $xenserver->host_metrics__get_record($host["metrics"]); + +$mem_total = $host_metrics["memory_total"]; +$mem_free = $host_metrics["memory_free"]; + +$vms_array = $xenserver->VM__get_all_records(); header("Content-Type: text/xml"); echo ""; +echo ""; +echo "{$mem_total}"; +echo "{$mem_free}"; +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; } @@ -43,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 ); @@ -76,6 +95,7 @@ echo "{$url}"; echo "{$session}"; echo "{$os}"; + echo "{$cpuavg}"; echo ""; }