Handle node_get_cpu_stats() output change
--- classes/libvirt.php | 39 +++++++++++++++++++++++---------------- lang/en.php | 2 +- pages/info.php | 30 ++++++++---------------------- 3 files changed, 32 insertions(+), 39 deletions(-)
diff --git a/classes/libvirt.php b/classes/libvirt.php index e8fce08..46da82b 100644 --- a/classes/libvirt.php +++ b/classes/libvirt.php @@ -1601,20 +1601,27 @@ $tmp = libvirt_node_get_info($this->conn); return ($tmp) ? $tmp : $this->_set_last_error(); } - + function node_get_cpu_stats() { - $tmp = libvirt_node_get_cpu_stats($this->conn); - return ($tmp) ? $tmp : $this->_set_last_error(); - } - - function node_get_mem_stats() { - $tmp = libvirt_node_get_mem_stats($this->conn); - return ($tmp) ? $tmp : $this->_set_last_error(); - } - - function connect_get_sysinfo() { - $tmp = libvirt_connect_get_sysinfo($this->conn); - return ($tmp) ? $tmp : $this->_set_last_error(); - } - } -?> + $tmp = libvirt_node_get_cpu_stats($this->conn); + 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() { + $tmp = libvirt_node_get_mem_stats($this->conn); + return ($tmp) ? $tmp : $this->_set_last_error(); + } + + function connect_get_sysinfo() { + $tmp = libvirt_connect_get_sysinfo($this->conn); + return ($tmp) ? $tmp : $this->_set_last_error(); + } + } +?> \ No newline at end of file diff --git a/lang/en.php b/lang/en.php index 931f92c..dbd8fde 100644 --- a/lang/en.php +++ b/lang/en.php @@ -301,7 +301,7 @@ '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', diff --git a/pages/info.php b/pages/info.php index ac20183..b02b72d 100644 --- a/pages/info.php +++ b/pages/info.php @@ -125,34 +125,20 @@ </div>
<div class="section"><?php echo $lang->get('cpu_stats'); ?></div> -<?php +<?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 +<?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>
On 08/06/2012 07:34 PM, Olivier Doucet wrote:
Handle node_get_cpu_stats() output change
classes/libvirt.php | 39 +++++++++++++++++++++++---------------- lang/en.php | 2 +- pages/info.php | 30 ++++++++---------------------- 3 files changed, 32 insertions(+), 39 deletions(-)
diff --git a/classes/libvirt.php b/classes/libvirt.php index e8fce08..46da82b 100644 --- a/classes/libvirt.php +++ b/classes/libvirt.php @@ -1601,20 +1601,27 @@ $tmp = libvirt_node_get_info($this->conn); return ($tmp) ? $tmp : $this->_set_last_error(); }
Olivier, this is returning the "trailing whitespace" error on the commit hooks. Please avoid using trailing whitespaces... I do not manage the server so I can't disable the hooks, the git is the same as for libvirt (upstream project) and this is prohibiting "trailing whitespaces" and "new lines at EOF" so please don't use it.
Thanks, Michal
php-virt-control@lists.fedorahosted.org