/[projects]/misc/xenconsole/ajaxdata.php
ViewVC logotype

Diff of /misc/xenconsole/ajaxdata.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1889 by torben, Sat Dec 1 16:12:51 2012 UTC revision 1892 by torben, Sun Dec 2 16:30:24 2012 UTC
# Line 35  $host_metrics = $xenserver->host_metrics Line 35  $host_metrics = $xenserver->host_metrics
35  $mem_total = $host_metrics["memory_total"];  $mem_total = $host_metrics["memory_total"];
36  $mem_free = $host_metrics["memory_free"];  $mem_free = $host_metrics["memory_free"];
37    
38  $vms_array = $xenserver->VM__get_all_records();  $cpus = $host["cpu_info"]["cpu_count"];
39    $cpusum = 0.0;
40    for ($i=0; $i<$cpus; $i++) {
41            $cpusum += $xenserver->host__query_data_source($hosts_array[0], "cpu" . $i);
42    }
43    $cpuavg = round (  ($cpusum/$cpus) * 100);
44    
45  header("Content-Type: text/xml");  header("Content-Type: text/xml");
46  echo "<xen>";  echo "<xen>";
47  echo "<host>";  echo "<host>";
48  echo "<memtotal>{$mem_total}</memtotal>";  echo "<memtotal>{$mem_total}</memtotal>";
49  echo "<memfree>{$mem_free}</memfree>";  echo "<memfree>{$mem_free}</memfree>";
50    echo "<cpuavg>{$cpuavg}</cpuavg>";
51  echo "</host>";  echo "</host>";
52    
53    
54    
55    $vms_array = $xenserver->VM__get_all_records();
56  // List all machines  // List all machines
57  foreach($vms_array as $vm) {  foreach($vms_array as $vmref => $vm) {
58          if ($vm["is_a_template"] != 0 || $vm["is_control_domain"] != 0) {          if ($vm["is_a_template"] != 0 || $vm["is_control_domain"] != 0) {
59                  continue;                  continue;
60          }          }
# Line 55  foreach($vms_array as $vm) { Line 63  foreach($vms_array as $vm) {
63          $name = $vm["name_label"];          $name = $vm["name_label"];
64          $uuid = $vm["uuid"];          $uuid = $vm["uuid"];
65          $state = $vm["power_state"] ;          $state = $vm["power_state"] ;
66            $cpus = $vm["VCPUs_max"];
67    
68    
69          $network = "";          $network = "";
70          $url = "";          $url = "";
71          $session = "";          $session = "";
72          $os = "";          $os = "";
73            $cpuavg = 0.0;
74          if ( $vm["power_state"] == "Running" ) {          if ( $vm["power_state"] == "Running" ) {
75                  if ($vm["guest_metrics"] != "OpaqueRef:NULL") {//guest tools installed                  if ($vm["guest_metrics"] != "OpaqueRef:NULL") {//guest tools installed
76                          $guest_metrics = $xenserver->VM_guest_metrics__get_record( $vm["guest_metrics"] );                          $guest_metrics = $xenserver->VM_guest_metrics__get_record( $vm["guest_metrics"] );
77                          $network = implode( ",",  $guest_metrics["networks"])  ;                          $network = implode( ",",  $guest_metrics["networks"])  ;
78                          $os =  $guest_metrics["os_version"]["name"];                          $os =  $guest_metrics["os_version"]["name"];
79                  }                  }
80                    $cpusum = 0.0;
81                    for ($i=0; $i<$cpus; $i++) {
82                            $cpusum += $xenserver->VM__query_data_source($vmref, "cpu" . $i);
83                    }      
84                    $cpuavg = round (  ($cpusum/$cpus) * 100);
85                    
86    
87                  foreach($vm["consoles"] as $conref) {                  foreach($vm["consoles"] as $conref) {
88                          $con = $xenserver->console__get_record( $conref );                          $con = $xenserver->console__get_record( $conref );
# Line 88  foreach($vms_array as $vm) { Line 104  foreach($vms_array as $vm) {
104          echo "<conurl>{$url}</conurl>";          echo "<conurl>{$url}</conurl>";
105          echo "<session>{$session}</session>";          echo "<session>{$session}</session>";
106          echo "<os>{$os}</os>";          echo "<os>{$os}</os>";
107            echo "<cpuavg>{$cpuavg}</cpuavg>";
108                    
109          echo "</vm>";            echo "</vm>";  
110  }  }

Legend:
Removed from v.1889  
changed lines
  Added in v.1892

  ViewVC Help
Powered by ViewVC 1.1.20