mirror of
https://github.com/unraid/webgui.git
synced 2026-05-22 22:30:20 -05:00
50 lines
1.6 KiB
PHP
Executable File
50 lines
1.6 KiB
PHP
Executable File
#!/usr/bin/php -q
|
|
<?PHP
|
|
/* Copyright 2005-2025, Lime Technology
|
|
* Copyright 2012-2025, 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 ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
|
|
|
|
require_once "$docroot/webGui/include/Helpers.php";
|
|
require_once "$docroot/webGui/include/publish.php";
|
|
|
|
$noDockerStats = false;
|
|
$noDockerStatsTime = null;
|
|
$exitAfterTimeout = 120;
|
|
|
|
while (true) {
|
|
$output = shell_exec("docker stats --no-stream --format='{{.ID}};{{.CPUPerc}};{{.MemUsage}}' 2>&1");
|
|
|
|
if ( ! $noDockerStats ) {
|
|
// publish and exit the script if no listeners after the timeout
|
|
publish("dockerload", $output,true,$exitAfterTimeout);
|
|
}
|
|
if ( $output === null ) {
|
|
// Don't continually publish messages if no stats are available -> only publish the first time
|
|
$noDockerStats = true;
|
|
|
|
if ( ! $noDockerStatsTime ) {
|
|
$noDockerStatsTime = time();
|
|
}
|
|
|
|
// handle if no containers are running and user navigates to another page.
|
|
// publish requires a second publish attempt with no listeners in order to exit the script after the timeout has elapsed
|
|
if ( (time() - $noDockerStatsTime) > $exitAfterTimeout ) {
|
|
$noDockerStats = false;
|
|
$noDockerStatsTime = null;
|
|
}
|
|
sleep(10);
|
|
} else {
|
|
$noDockerStats = false;
|
|
sleep(1);
|
|
}
|
|
}
|