mirror of
https://github.com/unraid/webgui.git
synced 2026-05-04 00:39:32 -05:00
Add Stats page
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
Menu="VMs:0"
|
||||
Title="VM Usage Statisics"
|
||||
Cond="exec(\"grep -o '^SERVICE=.enable' /boot/config/domain.cfg 2>/dev/null\")"
|
||||
Nchan="vm_usage:stop"
|
||||
---
|
||||
<?PHP
|
||||
/* Copyright 2005-2024, Lime Technology
|
||||
* Copyright 2012-2024, Simon Fairweather.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
|
||||
?>
|
||||
<table id="vmstats" class="tablesorter four shift">
|
||||
<thead class='child'><tr><th class="th1">_(Name)_</th><th class="th2">_(Guest CPU)_</th><th>_(Host CPU)_</th><th>_(Memory)_</th><th>_(Disk IO)_</th><th>_(Network IO)_</th></tr></thead>
|
||||
<tbody id ="vmstatsbody" class='child'>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<script>
|
||||
var vmusage = new NchanSubscriber('/sub/vm_usage',{subscriber:'websocket'});
|
||||
vmusage.on('message', function(msg){
|
||||
var data = JSON.parse(msg);
|
||||
$('#vmstatsbody').html(data);
|
||||
});
|
||||
|
||||
$(function(){
|
||||
vmusage.start();
|
||||
});
|
||||
|
||||
window.onunload = function(){
|
||||
vmusage.stop();
|
||||
}
|
||||
</script>
|
||||
@@ -2568,8 +2568,8 @@ function get_vm_usage_stats($collectcpustats = true,$collectdiskstats = true,$co
|
||||
$rd += $data["block.$i.rd.bytes"] ;
|
||||
$wr += $data["block.$i.wr.bytes"] ;
|
||||
}
|
||||
$rdrate = ($rd - $vmusagestats[$vm]['rdp'])/1024;
|
||||
$wrrate = ($wr - $vmusagestats[$vm]['wrp'])/1024;
|
||||
$rdrate = ($rd - $vmusagestats[$vm]['rdp']);
|
||||
$wrrate = ($wr - $vmusagestats[$vm]['wrp']);
|
||||
} else $rdrate=$wrrate=0;
|
||||
|
||||
# Net
|
||||
@@ -2580,8 +2580,8 @@ function get_vm_usage_stats($collectcpustats = true,$collectdiskstats = true,$co
|
||||
$rx += $data["net.$i.rx.bytes"] ;
|
||||
$tx += $data["net.$i.tx.bytes"] ;
|
||||
}
|
||||
$rxrate = round(($rx - $vmusagestats[$vm]['rxp'])/1024,0);
|
||||
$txrate = round(($tx - $vmusagestats[$vm]['txp'])/1024,0);
|
||||
$rxrate = round(($rx - $vmusagestats[$vm]['rxp']),0);
|
||||
$txrate = round(($tx - $vmusagestats[$vm]['txp']),0);
|
||||
} else $rxrate=$txrate=0;
|
||||
|
||||
$vmusagestats[$vm] = [
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/php -q
|
||||
<?PHP
|
||||
/* Copyright 2005-2024, Lime Technology
|
||||
* Copyright 2024-2024, Simon Fairweather.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
$docroot = '/usr/local/emhttp';
|
||||
$varroot = '/var/local/emhttp';
|
||||
$md5_old = -1;
|
||||
|
||||
require_once "$docroot/webGui/include/Helpers.php";
|
||||
require_once "$docroot/webGui/include/publish.php";
|
||||
require_once "$docroot/plugins/dynamix.vm.manager/include/libvirt_helpers.php";
|
||||
global $vmusagestats;
|
||||
extract(parse_plugin_cfg('dynamix',true));
|
||||
get_vm_usage_stats();
|
||||
sleep(1);
|
||||
|
||||
|
||||
// add translations
|
||||
$_SERVER['REQUEST_URI'] = 'dashboard';
|
||||
$login_locale = _var($display,'locale');
|
||||
require_once "$docroot/webGui/include/Translations.php";
|
||||
|
||||
// remember current language
|
||||
$locale_init = $locale;
|
||||
|
||||
function update_translation($locale) {
|
||||
global $docroot,$language;
|
||||
$language = [];
|
||||
if ($locale) {
|
||||
$text = "$docroot/languages/$locale/translations.txt";
|
||||
if (file_exists($text)) {
|
||||
$store = "$docroot/languages/$locale/translations.dot";
|
||||
if (!file_exists($store)) file_put_contents($store,serialize(parse_lang_file($text)));
|
||||
$language = unserialize(file_get_contents($store));
|
||||
}
|
||||
$text = "$docroot/languages/$locale/dashboard.txt";
|
||||
if (file_exists($text)) {
|
||||
$store = "$docroot/languages/$locale/dashboard.dot";
|
||||
if (!file_exists($store)) file_put_contents($store,serialize(parse_lang_file($text)));
|
||||
$language = array_merge($language,unserialize(file_get_contents($store)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
|
||||
extract(parse_plugin_cfg('dynamix',true));
|
||||
if (_var($display,'locale') != $locale_init) {
|
||||
$locale_init = _var($display,'locale');
|
||||
update_translation($locale_init);
|
||||
}
|
||||
|
||||
get_vm_usage_stats();
|
||||
$echo = [];
|
||||
$echo = [];
|
||||
$ts = $time1 - $time0;
|
||||
$echodata = "";
|
||||
$running = 0;
|
||||
foreach ($vmusagestats as $vm => $vmdata) {
|
||||
|
||||
if ($vmdata['state'] == 1) {
|
||||
$running++;
|
||||
$echodata .= "<tr><td>$vm</td>" ;
|
||||
#<td>".$vmdata['cpuguest']."%</td><td>".$vmdata['cpuhost']."%</td><td>";
|
||||
$echodata .= "<td class='advanced'><span>".$vmdata['cpuguest']."%</span><div class='usage-disk mm'><span style='width:50'></span><span></span></div></td>";
|
||||
$echodata .= "<td class='advanced'><span>".$vmdata['cpuhost']."%</span><div class='usage-disk mm'><span style='width:50'></span><span></span></div></td><td>";
|
||||
$echodata .= my_scale($vmdata['mem'],$unit)."$unit / ".my_scale($vmdata['maxmem'],$unit)."$unit</td><td>";
|
||||
$echodata .= _("Read").": ".my_scale($vmdata['rxrate'],$unit)."$unit/s<br>"._("Write").": ".my_scale($vmdata['txrate'],$unit)."$unit/s</td><td>";
|
||||
$echodata .= _("RX").": ".my_scale($vmdata['rdrate'],$unit)."$unit/s<br>"._("TX").": ".my_scale($vmdata['wrrate'],$unit)."$unit/s</td></tr>";
|
||||
}
|
||||
$echo = $echodata ;
|
||||
}
|
||||
if ($running < 1) $echo = "<tr><td></td><td></td><td>"._("No VMs Running")."</td></tr>";
|
||||
|
||||
$echo = json_encode($echo);
|
||||
$md5_new = md5($echo,true);
|
||||
if ($md5_new !== $md5_old) {
|
||||
$md5_old = publish('vm_usage',$echo)!==false ? $md5_new : -1;
|
||||
$time0 = $time1;
|
||||
}
|
||||
|
||||
sleep(3);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user