Skip to content

Commit

Permalink
Adjust cpu usage displays to account for cpu amount setting if config…
Browse files Browse the repository at this point in the history
…ured
  • Loading branch information
austinwbest committed Nov 25, 2023
1 parent d52b060 commit 27a50dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Simple UI driven way to manage updates & notifications for containers. As this i
- Notify when a container changes state (running -> stopped)
- Nofity when an update is available
- Notify when an update is applied
- Notify when images/volumes have been pruned
- Notify if memory is > n%
- Notify if CPU is > n%

Expand All @@ -23,10 +24,10 @@ Simple UI driven way to manage updates & notifications for containers. As this i
### Features
- Setup update schedules on a container by container basis
- Setup notify only or update on a container by container basis
- Mass cleanup orphan containers
- Mass prune/remove orphan images and volumes
- Mass select containers and generate `docker run` commands
- Mass select containers and generate a docker compose for them
- Mass select containers and start/restart/stop/pull
- Mass select containers and generate a `docker-compose` for them
- Mass select containers and start/restart/stop/pull/update
- Memcached support (optional)

### Permissions
Expand Down Expand Up @@ -118,7 +119,7 @@ There is support for a simple login mechanism but i would recomment using someth
- Multiple logins, drop a line and add another `admin:password`

### Development
Firstly i **am not** a docker expert so there are likely other/better ways to do this. What i list below is just how i work on it without having to rebuilt the container for every change and a reminder for me on what i did. Since this involves messing with the contents of the container, if an update is applied these steps will need re-applied
Firstly i **am not** a docker expert so there are likely other/better ways to do this. What i list below is just how i work on it without having to rebuild the container for every change and a reminder for me on what i did. Since this involves messing with the contents of the container, if an update is applied these steps will need re-applied

Option 1:
- Fork the repo
Expand Down
14 changes: 12 additions & 2 deletions root/app/www/public/ajax/containers.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
$logo = getIcon($process['inspect']);
$control = $process['State'] == 'running' ? '<button type="button" class="btn btn-outline-success me-2" onclick="controlContainer(\'' . $nameHash . '\', \'restart\')">Restart</button> <button type="button" class="btn btn-outline-danger" onclick="controlContainer(\'' . $nameHash . '\', \'stop\')">Stop</button>' : '<button type="button" class="btn btn-outline-success" onclick="controlContainer(\'' . $nameHash . '\', \'start\')">Start</button>';

$cpuUsage = floatval(str_replace('%', '', $process['stats']['CPUPerc']));
if (intval($settings['global']['cpuAmount']) > 0) {
$cpuUsage = number_format(($cpuUsage / intval($settings['global']['cpuAmount'])), 2) . '%';
}
$pullData = $pulls[$nameHash];
$updateStatus = '<span class="text-danger">Unknown</span>';
if ($pullData) {
Expand All @@ -86,7 +90,7 @@
<td id="<?= $nameHash ?>-update" title="Last pulled: <?= date('Y-m-d H:i:s', $pullData['checked']) ?>"><?= $updateStatus ?></td>
<td id="<?= $nameHash ?>-state"><?= $process['State'] ?></td>
<td><span id="<?= $nameHash ?>-running"><?= $process['RunningFor'] ?></span><br><span id="<?= $nameHash ?>-status"><?= $process['Status'] ?></span></td>
<td id="<?= $nameHash ?>-cpu"><?= $process['stats']['CPUPerc'] ?></td>
<td id="<?= $nameHash ?>-cpu" title="<?= $process['stats']['CPUPerc'] ?>"><?= $cpuUsage ?></td>
<td id="<?= $nameHash ?>-mem"><?= $process['stats']['MemPerc'] ?></td>
<td>
<select id="containers-update-<?= $nameHash ?>" class="form-control container-updates">
Expand Down Expand Up @@ -292,13 +296,19 @@
$updateStatus = ($pullData['image'] == $pullData['container']) ? '<span class="text-success">Updated</span>' : '<span class="text-warning">Outdated</span>';
}

$cpuUsage = floatval(str_replace('%', '', $containerStats['CPUPerc']));
if (intval($settings['global']['cpuAmount']) > 0) {
$cpuUsage = number_format(($cpuUsage / intval($settings['global']['cpuAmount'])), 2) . '%';
}

$return = [
'control' => $control,
'update' => $updateStatus,
'state' => $containerProcess['State'],
'running' => $containerProcess['RunningFor'],
'status' => $containerProcess['Status'],
'cpu' => $containerStats['CPUPerc'],
'cpu' => $cpuUsage,
'cpuTitle' => $containerStats['CPUPerc'],
'mem' => $containerStats['MemPerc'],
'result' => $result
];
Expand Down
8 changes: 7 additions & 1 deletion root/app/www/public/ajax/overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
list($netUsed, $netAllowed) = explode(' / ', $process['stats']['NetIO']);
$network += bytesFromString($netUsed);
}

$cpu = number_format((($running + $stopped) * 100) / $cpu, 2);
if (intval($settings['global']['cpuAmount']) > 0) {
$cpuActual = number_format(($cpu / intval($settings['global']['cpuAmount'])), 2);
}

?>
<div class="container-fluid pt-4 px-4">
<div class="row">
Expand All @@ -86,7 +92,7 @@
<div class="bg-secondary rounded d-flex align-items-center justify-content-between p-4">
<h3>Usage</h3>
Disk: <?= byteConversion($size) ?><br>
CPU: <?= number_format((($running + $stopped) * 100) / $cpu, 2) ?>%<br>
CPU: <?= $cpu ?>%<?= ($cpuActual ? ' (' . $cpuActual . '%)' : '') ?><br>
Memory: <?= $memory ?>%<br>
Network I/O: <?= byteConversion($network) ?>
</div>
Expand Down
1 change: 1 addition & 0 deletions root/app/www/public/js/containers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function controlContainer(containerHash, action)
$('#' + containerHash + '-running').html(resultData.running);
$('#' + containerHash + '-status').html(resultData.status);
$('#' + containerHash + '-cpu').html(resultData.cpu);
$('#' + containerHash + '-cpu').prop('title', resultData.cpuTitle);
$('#' + containerHash + '-mem').html(resultData.mem);

loadingStop();
Expand Down

0 comments on commit 27a50dc

Please sign in to comment.