Docker: added "container size" calculation

This commit is contained in:
bergware
2018-10-02 20:31:31 +02:00
parent 687e6362f2
commit c0f63ed397
3 changed files with 101 additions and 0 deletions
@@ -59,6 +59,7 @@ input.wait{width:24px;margin:0 4px;padding:0 5px;border:none;box-shadow:none;bac
<input type="button" onclick="resumeAll()" value="Resume All" style="display:none">
<input type="button" onclick="checkAll()" value="Check for Updates" id="checkAll" style="display:none">
<input type="button" onclick="updateAll()" value="Update All" id="updateAll" style="display:none">
<input type="button" onclick="sizes()" value="Container Size" style="display:none">
<script src="<?autov('/webGui/javascript/jquery.switchbutton.js')?>"></script>
<script src="<?autov('/plugins/dynamix.docker.manager/javascript/docker.js')?>"></script>
@@ -143,6 +144,9 @@ function loadlist() {
if (data[2]==1) {$('#busy').show(); setTimeout(loadlist,5000);} else if ($('#busy').is(':visible')) {$('#busy').hide(); setTimeout(loadlist,3000);}
});
}
function sizes() {
openBox('/plugins/dynamix.docker.manager/include/ContainerSize.php','Container Size',600,600);
}
var watchDocker = new NchanSubscriber('/sub/dockerload', /^((?!chrome|android).)*safari/i.test(navigator.userAgent) ? {subscriber:'longpoll'} : {});
watchDocker.on('message', function(data){
data = data.split('\n');
@@ -0,0 +1,58 @@
<?PHP
/* Copyright 2005-2018, Lime Technology
* Copyright 2012-2018, Bergware International.
*
* 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 = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once "$docroot/webGui/include/Helpers.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Benchmark</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="robots" content="noindex, nofollow">
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/default-fonts.css")?>">
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/default-popup.css")?>">
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/font-awesome.css")?>">
</head>
<style>
div.button{width:100%;text-align:center;display:none}
div.spinner{margin:0 auto;text-align:center}
div.spinner .unraid_mark{height:64px}
div.spinner .unraid_mark_2,div .unraid_mark_4{animation:mark_2 1.5s ease infinite}
div.spinner .unraid_mark_3{animation:mark_3 1.5s ease infinite}
div.spinner .unraid_mark_6,div .unraid_mark_8{animation:mark_6 1.5s ease infinite}
div.spinner .unraid_mark_7{animation:mark_7 1.5s ease infinite}
@keyframes mark_2{50% {transform:translateY(-40px)} 100% {transform:translateY(0px)}}
@keyframes mark_3{50% {transform:translateY(-62px)} 100% {transform:translateY(0px)}}
@keyframes mark_6{50% {transform:translateY(40px)} 100% {transform:translateY(0px)}}
@keyframes mark_7{50% {transform:translateY(62px)} 100% {transform: translateY(0px)}}
pre{font-family:bitstream;font-size:1.3rem}
</style>
<script type="text/javascript" src="<?autov('/webGui/javascript/dynamix.js')?>"></script>
<script>
$(function(){
$('div.spinner').html('<?=file_get_contents("$docroot/webGui/images/animated-logo.svg")?>');
$.get('/plugins/dynamix.docker.manager/include/GetContainerSize.php',function(data){
$('div.spinner').hide();
$('#data').text(data);
$('div.button').show();
});
});
</script>
<body style='margin:20px'>
<div class="spinner"></div>
<pre id="data"></pre>
<div class="button"><input type="button" value="Done" onclick="top.Shadowbox.close()"></div>
</body>
</html>
@@ -0,0 +1,39 @@
<?PHP
/* Copyright 2005-2018, Lime Technology
* Copyright 2012-2018, Bergware International.
*
* 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.
*/
?>
<?
function autoscale($value) {
$unit = ['B','kB','MB','GB','TB','PB','EB','ZB','YB'];
$size = count($unit);
$base = $value ? floor(log($value, 1000)) : 0;
if ($base>$size) $base = $size-1;
$value /= pow(1000, $base);
$decimals = $base ? ($value>=100 ? 0 : ($value>=10 ? 1 : (round($value*100)%100===0 ? 0 : 2))) : 0;
return number_format($value, $decimals, '.', $value>9999 ? ',' : '').$unit[$base];
}
function align($text, $w=13) {
if ($w>0) $text = preg_replace('/([kMGTPEZY]?B)/'," $1",$text);
return sprintf("%{$w}s",$text);
}
exec("docker ps -sa --format='{{.Names}}|{{.Size}}'",$containers);
natcasesort($containers);
echo align('Name',-30).align('Container').align('Writable').align('Log')."\n";
echo str_repeat('-',69)."\n";
foreach ($containers as $container) {
list($name,$size) = explode('|',$container);
list($writable,$dummy,$total) = explode(' ',str_replace(['(',')'],'',$size));
$log = autoscale(exec("docker logs $name 2>/dev/null|wc -c"));
echo align($name,-30).align($total).align($writable).align($log)."\n";
}
?>