Fix: Change Libvirt::node_get_cpu_stats() output
authorOlivier Doucet <odoucet@php.net>
Tue, 7 Aug 2012 10:48:04 +0000 (12:48 +0200)
committerMichal Novotny <minovotn@redhat.com>
Tue, 7 Aug 2012 10:50:03 +0000 (12:50 +0200)
Handle node_get_cpu_stats() output change

Signed-off-by: Olivier Doucet <odoucet@php.net>

classes/libvirt.php
lang/en.php
pages/info.php

index e0a3d6f..28b40f7 100644 (file)
 
                function node_get_cpu_stats() {
                        $tmp = libvirt_node_get_cpu_stats($this->conn);
-                       return ($tmp) ? $tmp : $this->_set_last_error();
+                       if (!$tmp) return $this->_set_last_error();
+
+                       // tmp has two array, collected at 1sec delay. Make a diff
+                       $newvalues = array();
+                       foreach ($tmp[0] as $key => $elem) {
+                               $newvalues[$key] = $tmp[1][$key] - $elem;
+                       }
+                       return $newvalues;
                }
 
                function node_get_mem_stats() {
index 096e513..6fc30d1 100644 (file)
                                        'password_mismatch' => 'Password mismatch',
                                        'screenshot-settings-auto-release' => 'Send automatic mouse pointer release event',
                                        'screenshot-delay' => 'Delay has been changed to %d second(s)',
-                                       'cpu_stats' => 'Node CPU stats',
+                                       'cpu_stats' => 'Node CPU stats (one second average)',
                                        'mem_stats' => 'Node memory stats',
                                        'system_information' => 'System information',
                                        'date-format' => 'Y-m-d H:i:s',
index ac20183..9db6306 100644 (file)
 <div class="section"><?php echo $lang->get('cpu_stats'); ?></div>
 <?php
 $tmp = $lv->node_get_cpu_stats();
-foreach ($tmp as $id => $data) {
-    echo '<div class="label">'.$lang->get('run').' #'.$id.'</div>';
-    echo '<div class="value">';
-    foreach ($data as $key => $val) {
-        if ($key != 'time')
-            echo '<div class="label">'.$key.'</div><div class="value" style="text-align: right">'.$val.'</div>';
-        else
-            echo '<div class="label">'.$key.'</div><div class="value" style="text-align: right">'.@Date($lang->get('date-format'), $val).'</div>';
-    }
-    echo '</div><br />';
+if (is_array($tmp)) foreach ($tmp as $name => $value) {
+    echo '<div class="label">'.$name.'</div>';
+    echo '<div class="value">'.$value.'</div><div class="nl">';
 }
 ?>
 <div style="clear:both"></div>
 <div class="section"><?php echo $lang->get('mem_stats'); ?></div>
 <?php
 $tmp = $lv->node_get_mem_stats();
-foreach ($tmp as $id => $data) {
-    echo '<div class="label">'.$lang->get('run').' #'.$id.'</div>';
-    echo '<div class="value">';
-    foreach ($data as $key => $val) {
-        if ($key != 'time')
-            echo '<div class="label">'.$key.'</div><div class="value" style="text-align: right">'.$val.'</div>';
-        else
-            echo '<div class="label">'.$key.'</div><div class="value" style="text-align: right">'.@Date($lang->get('date-format'), $val).'</div>';
-    }
-    echo '</div><br />';
+if (is_array($tmp)) foreach ($tmp as $name => $value) {
+    echo '<div class="label">'.$name.'</div>';
+    echo '<div class="value">'.$value.'</div><div class="nl">';
 }
 ?>
 <div style="clear:both"></div>