Docker: added cpu load and memory load display

This commit is contained in:
bergware
2018-05-29 14:02:30 +02:00
parent a81508cffe
commit 17088573e7
3 changed files with 27 additions and 5 deletions

View File

@@ -17,6 +17,9 @@ Markdown="false"
* all copies or substantial portions of the Software.
*/
?>
<?
if (!exec("pgrep docker_load")) exec("$docroot/plugins/dynamix.docker.manager/scripts/docker_load >/dev/null 2>&1 &");
?>
<link type="text/css" rel="stylesheet" href="<?autov('/webGui/styles/jquery.ui.css')?>">
<link type="text/css" rel="stylesheet" href="<?autov('/webGui/styles/jquery.switchbutton.css')?>">
<style>
@@ -35,6 +38,7 @@ img.paused{opacity:0.6}
.switch-button-label.off{color:inherit}
th.five{width:5%}
th.eight{width:8%}
th.load{width:100px}
tbody > tr.sortable:hover{cursor:move}
</style>
<div id="dialog-confirm" style="display:none;" title="Dialog Title"></div>
@@ -42,8 +46,8 @@ tbody > tr.sortable:hover{cursor:move}
<span class="status" style="margin-top:-44px"><span><input type="checkbox" class="advancedview"></span></span>
<div class="spinner fixed"></div>
<table id="docker_containers" class="tablesorter shift">
<thead><tr><th><a href="#" style="cursor:hand;margin-left:12px" onclick="resetSorting()" title="Reset sorting"><i class="fa fa-th-list"></i></a></th><th>Application</th><th>Version</th><th>Network</th><th>Port Mappings <small>(App to Host)</small></th><th>Volume Mappings <small>(App to Host)</small></th><th class="eight">Autostart</th><th class="five">Log</th></tr></thead>
<tbody id="docker_list"><tr><td colspan='8'><div class="spinner"></div></td></tr></tbody>
<thead><tr><th><a href="#" style="cursor:hand;margin-left:12px" onclick="resetSorting()" title="Reset sorting"><i class="fa fa-th-list"></i></a></th><th>Application</th><th>Version</th><th>Network</th><th>Port Mappings <small>(App to Host)</small></th><th>Volume Mappings <small>(App to Host)</small></th><th class="load">CPU load</th><th class="load">Memory load</th><th class="eight">Autostart</th><th class="five">Log</th></tr></thead>
<tbody id="docker_list"><tr><td colspan='10'><div class="spinner"></div></td></tr></tbody>
</table>
<input type="button" onclick="addContainer()" value="Add Container" style="display:none">
<input type="button" onclick="startAll()" value="Start all Containers" style="display:none">
@@ -112,6 +116,15 @@ function loadlist(update) {
if (!update) $('input#updateAll').hide();
});
}
var watchDocker = new NchanSubscriber('/sub/dockerload', /^((?!chrome|android).)*safari/i.test(navigator.userAgent) ? {subscriber:'longpoll'} : {});
watchDocker.on('message', function(data) {
data = data.split('\n');
for (var i=0,row; row=data[i]; i++) {
var id = row.split(' ');
$('#cpu-'+id[0]).css('width',id[1]).text(id[1].replace('.','<?=$display['number'][0]?>'));
$('#mem-'+id[0]).css('width',id[2]).text(id[2].replace('.','<?=$display['number'][0]?>'));
}
});
$(function() {
$('.advancedview').switchButton({labels_placement:'left', on_label:'Advanced View', off_label:'Basic View', checked:$.cookie('docker_listview_mode')=='advanced'});
$('.advancedview').change(function() {
@@ -121,5 +134,6 @@ $(function() {
listview();
});
$.post('/plugins/dynamix.docker.manager/include/DockerUpdate.php',{},function(u){loadlist(u);});
watchDocker.start();
});
</script>

View File

@@ -39,7 +39,6 @@ $docker = ['var docker=[];'];
$null = '0.0.0.0';
$menu = [];
$n = 0;
foreach ($containers as $ct) {
$name = $ct['Name'];
$id = $ct['Id'];
@@ -49,10 +48,11 @@ foreach ($containers as $ct) {
$is_autostart = $info['autostart'] ? 'true':'false';
$updateStatus = $info['updated']=='true'||$info['updated']=='undef' ? 'true':'false';
$template = $info['template'];
$shell = $info['shell'];
$webGui = html_entity_decode($info['url']);
$support = html_entity_decode($info['Support']);
$project = html_entity_decode($info['Project']);
$menu[] = sprintf("addDockerContainerContext('%s','%s','%s',%s,%s,%s,%s,'%s','%s','%s','%s');", addslashes($name), addslashes($ct['ImageId']), addslashes($template), $running, $paused, $updateStatus, $is_autostart, addslashes($webGui), $id, addslashes($support), addslashes($project));
$menu[] = sprintf("addDockerContainerContext('%s','%s','%s',%s,%s,%s,%s,'%s','%s','%s','%s','%s');", addslashes($name), addslashes($ct['ImageId']), addslashes($template), $running, $paused, $updateStatus, $is_autostart, addslashes($webGui), $shell, $id, addslashes($support), addslashes($project));
$docker[] = "docker.push({name:'$name',id:'$id',state:$running,pause:$paused,update:'$updateStatus'});";
$shape = $running ? ($paused ? 'pause' : 'play') : 'square';
$status = $running ? ($paused ? 'paused' : 'started') : 'stopped';
@@ -100,6 +100,8 @@ foreach ($containers as $ct) {
echo "</td><td>{$ct['NetworkMode']}</td>";
echo "<td style='white-space:nowrap'><span class='docker_readmore'>".implode('<br>',$ports)."</span></td>";
echo "<td style='word-break:break-all'><span class='docker_readmore'>".implode('<br>',$paths)."</span></td>";
echo "<td><div class='usage-disk sys'><span id='cpu-$id' style='width:0'>-</span></div></td>";
echo "<td><div class='usage-disk sys'><span id='mem-$id' style='width:0'>-</span></div></td>";
echo "<td><input type='checkbox' class='autostart' container='".htmlspecialchars($name)."'".($info['autostart'] ? ' checked':'')."></td>";
echo "<td><a class='log' onclick=\"containerLogs('".addslashes(htmlspecialchars($name))."','$id',false,false)\"><img class='basic' src='/plugins/dynamix/icons/log.png'><div class='advanced'>";
echo htmlspecialchars(str_replace('Up','Uptime',$ct['Status']))."</div><div class='advanced' style='margin-top:4px'>Created ".htmlspecialchars($ct['Created'])."</div></a></td></tr>";
@@ -115,7 +117,7 @@ foreach ($images as $image) {
echo "</div></div></td>";
echo "<td><i>(orphan image)</i><div style='width:160px;'>Image ID: $id</div>";
echo "<div style='width:160px'>".implode('<br>',array_map('htmlspecialchars',$image['Tags']))."</div></td>";
echo "<td colspan='5'></td>";
echo "<td colspan='7'></td>";
echo "<td><div class='advanced' style='width:124px'>Created ".htmlspecialchars($image['Created'])."</div></td></tr>";
}
echo "\0".implode($menu).implode($docker);

View File

@@ -0,0 +1,6 @@
#!/bin/bash
while :; do
curl --data "$(docker stats --no-stream --format='{{.Container}} {{.CPUPerc}} {{.MemPerc}}')" --unix-socket /var/run/nginx.socket http://localhost/pub/dockerload?buffer_length=0 >/dev/null 2>&1
sleep 1
done &