상태 화면 맨 위 Podman 줄 (Windows·Mac)
- Podman ● 상태 · 버전 · 가상 머신 이름 (CPU · 메모리 · 디스크) · 컨테이너 실행 n/m - CPU 사용률(podman stats 컨테이너 합계) · 메모리(컨테이너 / 가상 머신, 캐시 포함) · 디스크 사용(system df) - 매번 새로 읽음, podman 명령을 동시에 실행 (Mac 17_podman_monitor.sh, Windows 17_podman_monitor.ps1) - WebUI 줄의 Podman·가상 머신 중복 정보 제거 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HnDmXrFqktWwYa1cuJRAVZ
This commit is contained in:
88
src/platform/windows/17_podman_monitor.ps1
Normal file
88
src/platform/windows/17_podman_monitor.ps1
Normal file
@@ -0,0 +1,88 @@
|
||||
# JJ Ollama Manager (Windows) — src/platform/windows/17_podman_monitor.ps1 : 상태 화면 맨 위 Podman 줄
|
||||
# jj_ollama_manager.ps1 가 순서대로 불러옵니다 (직접 실행하지 않음). 2026-11-05 추가
|
||||
#
|
||||
# 매번 새로 읽음 (메뉴를 그릴 때마다). podman 명령 4개를 동시에 실행
|
||||
# podman info → 가상 머신 메모리 전체·여유
|
||||
# podman stats → 컨테이너 현재 CPU·메모리 (합계)
|
||||
# podman system df → 이미지·컨테이너·볼륨 크기 (합계)
|
||||
# podman ps -a → 실행 중 / 전체 컨테이너 수
|
||||
# (가상 머신 이름·CPU·메모리·디스크 크기는 podman machine list)
|
||||
|
||||
# "666.4MB" "8.308GB" "0B" "1.2GiB" → GB 숫자
|
||||
function ConvertTo-PmGB([string]$Text) {
|
||||
if ("$Text".Trim() -notmatch '^([0-9.]+)\s*([A-Za-z]*)') { return 0.0 }
|
||||
$n = [double]::Parse($Matches[1], [Globalization.CultureInfo]::InvariantCulture)
|
||||
$u = $Matches[2].ToUpper()
|
||||
$f = 1e-9
|
||||
switch -Regex ($u) {
|
||||
'^KIB' { $f = 1024 / 1e9; break }
|
||||
'^KB' { $f = 1e-6; break }
|
||||
'^MIB' { $f = 1048576 / 1e9; break }
|
||||
'^MB' { $f = 1e-3; break }
|
||||
'^GIB' { $f = 1073741824 / 1e9; break }
|
||||
'^GB' { $f = 1; break }
|
||||
'^TIB' { $f = 1099511627776 / 1e9; break }
|
||||
'^TB' { $f = 1000; break }
|
||||
}
|
||||
return $n * $f
|
||||
}
|
||||
|
||||
function Format-PmGB([double]$v) { return ([string]::Format([Globalization.CultureInfo]::InvariantCulture, '{0:0.0}', $v)) }
|
||||
|
||||
function Get-PodmanMonitorLines {
|
||||
$L = New-Object System.Collections.Generic.List[string]
|
||||
if (-not (Test-Podman)) {
|
||||
$L.Add("${BOLD}Podman${RESET} ${GRAY}미설치 ('Open WebUI (Podman)' 메뉴에서 기동하면 설치합니다)${RESET}")
|
||||
return $L.ToArray()
|
||||
}
|
||||
$ver = Get-PodmanVersion
|
||||
$mi = Get-MachineInfo
|
||||
switch ($mi.State) {
|
||||
'none' { $L.Add("${BOLD}Podman${RESET} ${GRAY}● 가상 머신 없음 v$ver (WebUI를 기동하면 만듭니다)${RESET}"); return $L.ToArray() }
|
||||
'stopped' { $L.Add("${BOLD}Podman${RESET} ${RED}● 가상 머신 중지됨${RESET} v$ver · $($mi.Name) (CPU $($mi.Cpus) · 메모리 $($mi.Mem))"); return $L.ToArray() }
|
||||
'starting' { $L.Add("${BOLD}Podman${RESET} ${YELLOW}● 가상 머신 켜는 중${RESET} v$ver · $($mi.Name)"); return $L.ToArray() }
|
||||
}
|
||||
|
||||
# 명령 4개 + 디스크 크기를 동시에 실행 (출력은 임시 파일로)
|
||||
$dir = Join-Path $env:TEMP ('jjpm_' + [guid]::NewGuid().ToString('N').Substring(0, 8))
|
||||
New-Item -ItemType Directory -Path $dir -Force | Out-Null
|
||||
$cmds = [ordered]@{
|
||||
i = 'info --format {{.Host.MemTotal}}|{{.Host.MemFree}}'
|
||||
s = 'stats --no-stream --format {{.CPUPerc}}|{{.MemUsage}}'
|
||||
d = 'system df --format {{.Size}}'
|
||||
p = 'ps -a --format {{.State}}'
|
||||
m = 'machine list --format {{.Name}}|{{.DiskSize}}'
|
||||
}
|
||||
$procs = @()
|
||||
foreach ($k in $cmds.Keys) {
|
||||
try {
|
||||
$procs += Start-Process -FilePath $script:PodmanExe -ArgumentList $cmds[$k] -NoNewWindow -PassThru `
|
||||
-RedirectStandardOutput (Join-Path $dir "$k.txt") -RedirectStandardError (Join-Path $dir "$k.err") -ErrorAction Stop
|
||||
} catch { }
|
||||
}
|
||||
foreach ($p in $procs) { [void]$p.WaitForExit(15000) }
|
||||
$rd = { param($k) $f = Join-Path $dir "$k.txt"; if (Test-Path -LiteralPath $f) { @(Get-Content -LiteralPath $f -ErrorAction SilentlyContinue | Where-Object { "$_".Trim() }) } else { @() } }
|
||||
|
||||
$mt = 0.0; $mf = 0.0
|
||||
$i = "$(& $rd 'i' | Select-Object -First 1)" -split '\|'
|
||||
if ($i.Count -ge 2) { [void][double]::TryParse($i[0], [ref]$mt); [void][double]::TryParse($i[1], [ref]$mf) }
|
||||
$cpu = 0.0; $cmem = 0.0
|
||||
foreach ($line in (& $rd 's')) {
|
||||
$f = "$line" -split '\|'
|
||||
$c = 0.0; [void][double]::TryParse(($f[0] -replace '%', ''), [Globalization.NumberStyles]::Float, [Globalization.CultureInfo]::InvariantCulture, [ref]$c); $cpu += $c
|
||||
if ($f.Count -ge 2) { $cmem += ConvertTo-PmGB (($f[1] -split '/')[0]) }
|
||||
}
|
||||
$dsk = 0.0
|
||||
foreach ($line in (& $rd 'd')) { $dsk += ConvertTo-PmGB $line }
|
||||
$states = @(& $rd 'p')
|
||||
$run = @($states | Where-Object { "$_" -like 'running*' }).Count
|
||||
$msize = '?'
|
||||
foreach ($line in (& $rd 'm')) { $f = "$line" -split '\|'; if ($f[0].TrimEnd('*') -eq $mi.Name -and $f.Count -ge 2) { $msize = $f[1]; break } }
|
||||
Remove-Item -LiteralPath $dir -Recurse -Force -ErrorAction SilentlyContinue
|
||||
|
||||
$vm = '?'
|
||||
if ($mt -gt 0) { $vm = "$(Format-PmGB (($mt - $mf) / 1e9))/$(Format-PmGB ($mt / 1e9))GB ($([int](($mt - $mf) * 100 / $mt))%)" }
|
||||
$L.Add("${BOLD}Podman${RESET} ${GREEN}● 실행 중${RESET} v$ver · $($mi.Name) (CPU $($mi.Cpus) · 메모리 $($mi.Mem) · 디스크 $msize) · 컨테이너 실행 $run/$($states.Count)")
|
||||
$L.Add(" CPU $(Format-PmGB $cpu)% ${GRAY}(컨테이너 합계)${RESET} · 메모리 컨테이너 $(Format-PmGB $cmem)GB · 가상 머신 사용 $vm ${GRAY}(캐시 포함)${RESET} · 디스크 사용 $(Format-PmGB $dsk)GB")
|
||||
return $L.ToArray()
|
||||
}
|
||||
Reference in New Issue
Block a user