--- misc/xenconsole/ajaxdata.php 2012/11/30 17:56:07 1885 +++ misc/xenconsole/ajaxdata.php 2012/12/10 12:20:57 1896 @@ -27,14 +27,34 @@ /* 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"]; + +$cpus = $host["cpu_info"]["cpu_count"]; +$cpusum = 0.0; +for ($i=0; $i<$cpus; $i++) { + $cpusum += $xenserver->host__query_data_source($hosts_array[0], "cpu" . $i); +} +$cpuavg = round ( ($cpusum/$cpus) * 100); header("Content-Type: text/xml"); echo ""; +echo ""; +echo "{$mem_total}"; +echo "{$mem_free}"; +echo "{$cpuavg}"; +echo ""; + + +$vms_array = $xenserver->VM__get_all_records(); // 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,16 +63,32 @@ $name = $vm["name_label"]; $uuid = $vm["uuid"]; $state = $vm["power_state"] ; + $cpus = $vm["VCPUs_max"]; $network = ""; $url = ""; $session = ""; + $os = ""; + $cpuavg = 0.0; + $curmem = 0; + $maxmem = 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"]) ; + $tmpos = explode('|', $guest_metrics["os_version"]["name"]); + $os = $tmpos[0]; } + $cpusum = 0.0; + for ($i=0; $i<$cpus; $i++) { + $cpusum += $xenserver->VM__query_data_source($vmref, "cpu" . $i); + } + $cpuavg = round ( ($cpusum/$cpus) * 100); + $maxmem = round($xenserver->VM__query_data_source($vmref, "memory") / (1024*1024) ); + $free = round( $xenserver->VM__query_data_source($vmref, "memory_internal_free") / 1024 ); + $curmem = $maxmem - $free; foreach($vm["consoles"] as $conref) { $con = $xenserver->console__get_record( $conref ); @@ -73,6 +109,10 @@ echo "{$network}"; echo "{$url}"; echo "{$session}"; + echo "{$os}"; + echo "{$cpuavg}"; + echo "{$curmem}"; + echo "{$maxmem}"; echo ""; }