release: r015 compact filtered Docker inventory
This commit is contained in:
+39
-9
@@ -10,7 +10,7 @@
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 0); // Fehler werden als JSON-RPC-Error zurückgegeben, nicht als HTML
|
||||
|
||||
const MUA_VERSION = '2026.08.18.r005';
|
||||
const MUA_VERSION = '2026.08.22.r015';
|
||||
const MUA_SERVER_NAME = 'mua';
|
||||
|
||||
/**
|
||||
@@ -235,35 +235,59 @@ function compact_container_inspect(string $raw): string {
|
||||
/**
|
||||
* Container-Runtime-Zusammenfassung (docker ps + docker stats).
|
||||
*/
|
||||
function container_runtime_summary(): string {
|
||||
function container_runtime_summary(array $args = []): string {
|
||||
$state_filter = $args['state'] ?? 'all';
|
||||
$include_stats = ($args['include_stats'] ?? false) === true;
|
||||
$detail = $args['detail'] ?? 'compact';
|
||||
$allowed_states = ['all', 'running', 'stopped', 'created', 'exited'];
|
||||
if (!in_array($state_filter, $allowed_states, true)) {
|
||||
throw new InvalidArgumentException('state must be one of: ' . implode(', ', $allowed_states));
|
||||
}
|
||||
if (!in_array($detail, ['compact', 'full'], true)) {
|
||||
throw new InvalidArgumentException('detail must be compact or full');
|
||||
}
|
||||
$ps = docker_exec("ps -a --format '{{json .}}'");
|
||||
$containers = json_lines($ps);
|
||||
|
||||
// docker stats für laufende Container
|
||||
$running_ids = array_filter(array_map(function ($c) {
|
||||
return $c['ID'] ?? '';
|
||||
return (($c['State'] ?? '') === 'running') ? ($c['ID'] ?? '') : '';
|
||||
}, $containers));
|
||||
|
||||
$stats = [];
|
||||
if (!empty($running_ids)) {
|
||||
if ($include_stats && !empty($running_ids)) {
|
||||
$stats_raw = docker_exec("stats --no-stream --format '{{json .}}'");
|
||||
foreach (json_lines($stats_raw) as $s) {
|
||||
$stats[$s['ID'] ?? ''] = $s;
|
||||
}
|
||||
}
|
||||
|
||||
$state_counts = [];
|
||||
foreach ($containers as $c) {
|
||||
$state = (string)($c['State'] ?? 'unknown');
|
||||
$state_counts[$state] = ($state_counts[$state] ?? 0) + 1;
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($containers as $c) {
|
||||
$state = (string)($c['State'] ?? '');
|
||||
$matches = $state_filter === 'all'
|
||||
|| ($state_filter === 'stopped' && $state !== 'running')
|
||||
|| $state === $state_filter;
|
||||
if (!$matches) continue;
|
||||
|
||||
$id = $c['ID'] ?? '';
|
||||
$entry = [
|
||||
'id' => substr($id, 0, 12),
|
||||
'name' => $c['Names'] ?? '',
|
||||
'image' => $c['Image'] ?? '',
|
||||
'status' => $c['Status'] ?? '',
|
||||
'state' => $c['State'] ?? '',
|
||||
'ports' => $c['Ports'] ?? '',
|
||||
];
|
||||
if (isset($stats[$id])) {
|
||||
if ($detail === 'full') {
|
||||
$entry['id'] = substr($id, 0, 12);
|
||||
$entry['image'] = $c['Image'] ?? '';
|
||||
$entry['ports'] = $c['Ports'] ?? '';
|
||||
}
|
||||
if ($include_stats && isset($stats[$id])) {
|
||||
$entry['cpu_percent'] = $stats[$id]['CPUPerc'] ?? '';
|
||||
$entry['mem_usage'] = $stats[$id]['MemUsage'] ?? '';
|
||||
$entry['mem_percent'] = $stats[$id]['MemPerc'] ?? '';
|
||||
@@ -274,8 +298,14 @@ function container_runtime_summary(): string {
|
||||
}
|
||||
|
||||
return json_encode([
|
||||
'schema_version' => '1.0',
|
||||
'schema_version' => '1.1',
|
||||
'container_count' => count($result),
|
||||
'returned_count' => count($result),
|
||||
'total_count' => count($containers),
|
||||
'running_count' => $state_counts['running'] ?? 0,
|
||||
'stopped_count' => count($containers) - ($state_counts['running'] ?? 0),
|
||||
'state_counts' => $state_counts,
|
||||
'filter' => ['state' => $state_filter, 'include_stats' => $include_stats, 'detail' => $detail],
|
||||
'containers' => $result,
|
||||
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user