sgpu 0.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sgpu/__init__.py +3 -0
- sgpu/__main__.py +4 -0
- sgpu/cli.py +176 -0
- sgpu-0.6.0.dist-info/METADATA +128 -0
- sgpu-0.6.0.dist-info/RECORD +9 -0
- sgpu-0.6.0.dist-info/WHEEL +5 -0
- sgpu-0.6.0.dist-info/entry_points.txt +2 -0
- sgpu-0.6.0.dist-info/licenses/LICENSE +21 -0
- sgpu-0.6.0.dist-info/top_level.txt +1 -0
sgpu/__init__.py
ADDED
sgpu/__main__.py
ADDED
sgpu/cli.py
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""sgpu command-line client.
|
|
2
|
+
|
|
3
|
+
A thin cross-platform wrapper: all rendering happens inside the monitor pod,
|
|
4
|
+
this client only shells out to kubectl (fetch server-rendered text, or hand
|
|
5
|
+
the terminal to the in-pod TUI via `kubectl exec -it`).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import os
|
|
10
|
+
import shutil
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
import time
|
|
14
|
+
|
|
15
|
+
from sgpu import __version__
|
|
16
|
+
|
|
17
|
+
DEFAULT_NAMESPACE = os.environ.get("SGPU_NAMESPACE", "p-sgvr-node-02")
|
|
18
|
+
DEFAULT_POD = os.environ.get("SGPU_POD", "sangmin-gpu-monitor")
|
|
19
|
+
DEPLOY_URL = ("https://raw.githubusercontent.com/alex6095/sgpu/main/"
|
|
20
|
+
"k8s/gpu-monitor.yaml")
|
|
21
|
+
|
|
22
|
+
COMMANDS = ("top", "once", "watch", "apps", "stats", "nvitop", "pods",
|
|
23
|
+
"smi", "gpustat", "json", "health", "version")
|
|
24
|
+
|
|
25
|
+
EPILOG = """commands:
|
|
26
|
+
(none) | top interactive TUI (scroll, sort, owner filter)
|
|
27
|
+
once one-shot dashboard
|
|
28
|
+
watch [sec] simple refresh loop (for dumb terminals)
|
|
29
|
+
apps GPU process table with pod owners
|
|
30
|
+
stats [days] per-owner usage report (default 7 days)
|
|
31
|
+
nvitop raw nvitop TUI
|
|
32
|
+
pods | smi | gpustat | json | health | version
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _enable_ansi():
|
|
37
|
+
if os.name == "nt":
|
|
38
|
+
os.system("") # nudges conhost/Windows Terminal into VT mode
|
|
39
|
+
try:
|
|
40
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
41
|
+
sys.stderr.reconfigure(encoding="utf-8")
|
|
42
|
+
except (AttributeError, OSError):
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _hint_on_failure(args, stderr_text):
|
|
47
|
+
print("sgpu: cannot reach monitor pod '%s' in namespace '%s'"
|
|
48
|
+
% (args.pod, args.namespace), file=sys.stderr)
|
|
49
|
+
tail = [line for line in stderr_text.strip().splitlines()][-3:]
|
|
50
|
+
for line in tail:
|
|
51
|
+
print(line, file=sys.stderr)
|
|
52
|
+
lowered = stderr_text.lower()
|
|
53
|
+
if "notfound" in lowered or "not found" in lowered:
|
|
54
|
+
print("hint: the monitor pod is not running. Deploy it with:",
|
|
55
|
+
file=sys.stderr)
|
|
56
|
+
print(" kubectl apply -f " + DEPLOY_URL, file=sys.stderr)
|
|
57
|
+
elif "unauthorized" in lowered or "forbidden" in lowered \
|
|
58
|
+
or "credentials" in lowered:
|
|
59
|
+
print("hint: check your access: kubectl auth can-i get pods -n %s"
|
|
60
|
+
% args.namespace, file=sys.stderr)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _fetch(args, path):
|
|
64
|
+
result = subprocess.run(
|
|
65
|
+
["kubectl", "exec", "-n", args.namespace, args.pod, "--",
|
|
66
|
+
"curl", "-fsS", "http://127.0.0.1:8080" + path],
|
|
67
|
+
capture_output=True, text=True, encoding="utf-8", errors="replace")
|
|
68
|
+
if result.returncode != 0:
|
|
69
|
+
_hint_on_failure(args, result.stderr or result.stdout)
|
|
70
|
+
return None
|
|
71
|
+
return result.stdout
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _color_param(args):
|
|
75
|
+
use = (not args.no_color) and sys.stdout.isatty()
|
|
76
|
+
return "color=1" if use else "color=0"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _cols_param():
|
|
80
|
+
cols = shutil.get_terminal_size(fallback=(120, 40)).columns
|
|
81
|
+
return "cols=%d" % max(40, cols)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _print(text):
|
|
85
|
+
if text is not None:
|
|
86
|
+
sys.stdout.write(text)
|
|
87
|
+
if not text.endswith("\n"):
|
|
88
|
+
sys.stdout.write("\n")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _interactive(args, pod_command):
|
|
92
|
+
if not (sys.stdout.isatty() and sys.stdin.isatty()):
|
|
93
|
+
_print(_fetch(args, "/table?color=0&" + _cols_param()))
|
|
94
|
+
return 0
|
|
95
|
+
return subprocess.call(
|
|
96
|
+
["kubectl", "exec", "-it", "-n", args.namespace, args.pod, "--"]
|
|
97
|
+
+ pod_command)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _watch(args):
|
|
101
|
+
seconds = args.number if args.number else args.refresh
|
|
102
|
+
esc = "\x1b"
|
|
103
|
+
sys.stdout.write(esc + "[?1049h" + esc + "[?25l")
|
|
104
|
+
try:
|
|
105
|
+
while True:
|
|
106
|
+
frame = _fetch(args, "/table?%s&%s"
|
|
107
|
+
% (_color_param(args), _cols_param()))
|
|
108
|
+
if frame is None:
|
|
109
|
+
frame = "sgpu: fetch failed; retrying..."
|
|
110
|
+
sys.stdout.write(esc + "[H" + frame + "\n" + esc + "[0J")
|
|
111
|
+
sys.stdout.flush()
|
|
112
|
+
time.sleep(max(1, seconds))
|
|
113
|
+
except KeyboardInterrupt:
|
|
114
|
+
return 0
|
|
115
|
+
finally:
|
|
116
|
+
sys.stdout.write(esc + "[?25h" + esc + "[?1049l")
|
|
117
|
+
sys.stdout.flush()
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def main(argv=None):
|
|
121
|
+
parser = argparse.ArgumentParser(
|
|
122
|
+
prog="sgpu",
|
|
123
|
+
description="Simple GPU monitor for the SGVR lab MLXP cluster.",
|
|
124
|
+
epilog=EPILOG,
|
|
125
|
+
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
126
|
+
parser.add_argument("command", nargs="?", default="top",
|
|
127
|
+
choices=COMMANDS, metavar="command")
|
|
128
|
+
parser.add_argument("number", nargs="?", type=int, default=0,
|
|
129
|
+
metavar="N",
|
|
130
|
+
help="days for stats, seconds for watch")
|
|
131
|
+
parser.add_argument("-n", "--namespace", default=DEFAULT_NAMESPACE)
|
|
132
|
+
parser.add_argument("--pod", default=DEFAULT_POD)
|
|
133
|
+
parser.add_argument("-r", "--refresh", type=int, default=2,
|
|
134
|
+
help="TUI/watch refresh interval (default 2)")
|
|
135
|
+
parser.add_argument("--no-color", action="store_true")
|
|
136
|
+
parser.add_argument("-V", "--version", action="version",
|
|
137
|
+
version="sgpu " + __version__)
|
|
138
|
+
args = parser.parse_args(argv)
|
|
139
|
+
|
|
140
|
+
if shutil.which("kubectl") is None:
|
|
141
|
+
print("sgpu: kubectl not found on PATH", file=sys.stderr)
|
|
142
|
+
print("hint: install kubectl and configure the MLXP kubeconfig "
|
|
143
|
+
"(see the sgpu README)", file=sys.stderr)
|
|
144
|
+
return 127
|
|
145
|
+
|
|
146
|
+
_enable_ansi()
|
|
147
|
+
query = "%s&%s" % (_color_param(args), _cols_param())
|
|
148
|
+
|
|
149
|
+
if args.command == "top":
|
|
150
|
+
return _interactive(args, ["python3", "/opt/gpu-monitor/tui.py",
|
|
151
|
+
str(args.refresh)])
|
|
152
|
+
if args.command == "nvitop":
|
|
153
|
+
return _interactive(args, ["nvitop"])
|
|
154
|
+
if args.command == "watch":
|
|
155
|
+
return _watch(args)
|
|
156
|
+
|
|
157
|
+
paths = {
|
|
158
|
+
"once": "/table?" + query,
|
|
159
|
+
"apps": "/apps?" + query,
|
|
160
|
+
"stats": "/stats?days=%d&%s" % (args.number or 7, query),
|
|
161
|
+
"pods": "/pods",
|
|
162
|
+
"smi": "/smi",
|
|
163
|
+
"gpustat": "/gpustat",
|
|
164
|
+
"json": "/json",
|
|
165
|
+
"health": "/health",
|
|
166
|
+
"version": "/version",
|
|
167
|
+
}
|
|
168
|
+
text = _fetch(args, paths[args.command])
|
|
169
|
+
if text is None:
|
|
170
|
+
return 1
|
|
171
|
+
_print(text)
|
|
172
|
+
return 0
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
if __name__ == "__main__":
|
|
176
|
+
sys.exit(main())
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sgpu
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Summary: Simple GPU monitor for the SGVR H200 lab (MLXP) - kubectl-native dashboards, in-pod TUI, per-user usage stats
|
|
5
|
+
Author: alex6095
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/alex6095/sgpu
|
|
8
|
+
Project-URL: Repository, https://github.com/alex6095/sgpu
|
|
9
|
+
Keywords: gpu,kubernetes,monitoring,nvml,nvitop,h200
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: System :: Monitoring
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# SGPU
|
|
21
|
+
|
|
22
|
+
**SGVR GPU** / **S**imple **GPU** monitor for the lab's MLXP H200 nodes —
|
|
23
|
+
check the GPUs before you launch a pod.
|
|
24
|
+
|
|
25
|
+
- Every GPU process is attributed to its **pod and owner** (not just a PID).
|
|
26
|
+
- **In-pod TUI** (`kubectl exec -it`) — smooth like nvitop, scroll/sort/filter.
|
|
27
|
+
- **Usage stats 24/7**: per-owner GPU-hours, awards, GitHub-style activity
|
|
28
|
+
calendar, idle-allocation warnings (KST).
|
|
29
|
+
- Shared **storage (pv-01/pv-02) usage** at a glance.
|
|
30
|
+
- Monitor pod is read-only, always-on, and requests **no GPU**.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
uvx sgpu # run without installing (uv)
|
|
36
|
+
pipx install sgpu # or pipx
|
|
37
|
+
pip install sgpu # or plain pip (WSL/Ubuntu: add --user --break-system-packages)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Needs `kubectl` configured for the MLXP namespace
|
|
41
|
+
([kubectl setup](#kubectl-setup-linuxwsl)).
|
|
42
|
+
|
|
43
|
+
## Use
|
|
44
|
+
|
|
45
|
+
```text
|
|
46
|
+
sgpu interactive TUI sgpu stats [days] usage report + awards
|
|
47
|
+
sgpu once one-shot dashboard sgpu apps processes + owners
|
|
48
|
+
sgpu watch [sec] dumb-terminal loop sgpu nvitop raw nvitop
|
|
49
|
+
sgpu pods|smi|gpustat|json|health|version|--help
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
TUI keys: `j/k` scroll · `Tab` pane · `s` sort · `o` owner filter · `p` pause · `q` quit.
|
|
53
|
+
Options: `-n` namespace, `--pod`, `-r` refresh, `--no-color`. Env: `SGPU_NAMESPACE`, `SGPU_POD`.
|
|
54
|
+
|
|
55
|
+
### Zero-install (kubectl only)
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
kubectl exec -it -n p-sgvr-node-02 sangmin-gpu-monitor -- python3 /opt/gpu-monitor/tui.py
|
|
59
|
+
kubectl exec -n p-sgvr-node-02 sangmin-gpu-monitor -- curl -fsS http://127.0.0.1:8080/table
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Endpoints on `:8080`: `/table /apps /json /stats /pods /smi /topo /gpustat
|
|
63
|
+
/health /version /stats/files /stats/raw?date=` (`?color=1&cols=N&ascii=1`).
|
|
64
|
+
|
|
65
|
+
## Stats
|
|
66
|
+
|
|
67
|
+
Sampled every 15 s around the clock into raw JSONL (full fidelity — future
|
|
68
|
+
tools can recompute anything), gzipped + rolled up daily, stored on the
|
|
69
|
+
shared volume at `pv-01/sangmin/sgpu`. Retention 365 d, capped at 2 GB.
|
|
70
|
+
`sgpu stats 30` shows the leaderboard, awards, daily activity calendar and
|
|
71
|
+
KST hour heatmap. Raw export: `/stats/raw?date=YYYYMMDD`.
|
|
72
|
+
|
|
73
|
+
> The monitor pod must stay running for stats to accumulate — it is designed
|
|
74
|
+
> to (tini init, `restartPolicy: Always`, no GPU held).
|
|
75
|
+
|
|
76
|
+
## Deploy / operate
|
|
77
|
+
|
|
78
|
+
Image push works **from anywhere** via the registry's public endpoint
|
|
79
|
+
(`sgvr-registry.kr.ncr.ntruss.com`); the cluster pulls via the private
|
|
80
|
+
endpoint (`vnxb4cz3.kr.private-ncr.ntruss.com`, in-cluster only — preferred
|
|
81
|
+
per the MLXP guide). API key: NCP console → Access Management.
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
docker login sgvr-registry.kr.ncr.ntruss.com
|
|
85
|
+
docker build -f docker/Dockerfile.gpu-monitor -t sgvr-registry.kr.ncr.ntruss.com/sangmin/gpu-monitor:TAG .
|
|
86
|
+
docker push sgvr-registry.kr.ncr.ntruss.com/sangmin/gpu-monitor:TAG
|
|
87
|
+
|
|
88
|
+
kubectl delete pod sangmin-gpu-monitor -n p-sgvr-node-02 --ignore-not-found
|
|
89
|
+
kubectl apply -f k8s/gpu-monitor.yaml # pods are immutable: delete + apply
|
|
90
|
+
kubectl wait --for=condition=Ready pod/sangmin-gpu-monitor -n p-sgvr-node-02 --timeout=180s
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Optional (enables the pod-allocation view + idle stats; kubelet syncs it in
|
|
94
|
+
within a minute, no restart):
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
kubectl -n p-sgvr-node-02 create secret generic sgpu-kubeconfig --from-file=config=$HOME/.kube/config
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
> Anyone with exec access to the monitor pod can read that token — fine
|
|
101
|
+
> inside a trusting lab namespace; use your least-privileged kubeconfig.
|
|
102
|
+
|
|
103
|
+
## kubectl setup (Linux/WSL)
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
mkdir -p ~/.local/bin ~/.kube
|
|
107
|
+
V=$(curl -fsSL https://dl.k8s.io/release/stable.txt)
|
|
108
|
+
curl -fsSL -o ~/.local/bin/kubectl "https://dl.k8s.io/release/${V}/bin/linux/amd64/kubectl" && chmod +x ~/.local/bin/kubectl
|
|
109
|
+
cp /path/to/sgvr-node-02-kubeconfig.yaml ~/.kube/config && chmod 600 ~/.kube/config
|
|
110
|
+
kubectl get pods -n p-sgvr-node-02 # connectivity test
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Development
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
SGPU_MOCK=1 python3 tools/gpu-monitor/server.py # full pipeline, no GPU needed
|
|
117
|
+
SGPU_MOCK=1 python3 tools/gpu-monitor/tui.py
|
|
118
|
+
python3 -m unittest discover -s tests
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
How it works: `sgpu` (thin Python client) → `kubectl exec` → monitor pod
|
|
122
|
+
(privileged, hostPID) where server.py renders everything; process→pod
|
|
123
|
+
attribution reads `/proc/<pid>/environ` (`HOSTNAME` = pod name), owner =
|
|
124
|
+
pod-name prefix. Known limits: pods overriding `spec.hostname` and MPS show
|
|
125
|
+
as `?`.
|
|
126
|
+
|
|
127
|
+
Troubleshooting: broken terminal after a dropped TUI → `reset` · frozen TUI
|
|
128
|
+
→ rerun `sgpu` · garbled bars → Windows Terminal or `--no-color`.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
sgpu/__init__.py,sha256=02Y_EpE47WPTsR4dFog4XGjX8FXOmO-dZ5S2B6NJr1g,95
|
|
2
|
+
sgpu/__main__.py,sha256=bjHD0BX4-wzy-m8I1CUWB-liI4AI9GgpfphxdUNvm5Y,83
|
|
3
|
+
sgpu/cli.py,sha256=COy4aAjHc5HNVO0nZ5XxNQ1rmVG6kTFMXl9JeCU-XUo,6038
|
|
4
|
+
sgpu-0.6.0.dist-info/licenses/LICENSE,sha256=SSj-3-ZHkxfJbyUqBfJKSXPGh2qjSybJ0YOzM5Tl7Bw,1065
|
|
5
|
+
sgpu-0.6.0.dist-info/METADATA,sha256=6Ia-pvo6M2Onzt1NQudgeELZTcgR9mgdOhTB0urMUU0,5082
|
|
6
|
+
sgpu-0.6.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
7
|
+
sgpu-0.6.0.dist-info/entry_points.txt,sha256=8XnjqiFHDVElaiefyPH22fOCtaJMKDq6fq9NuwjUnTU,39
|
|
8
|
+
sgpu-0.6.0.dist-info/top_level.txt,sha256=8KJ5Yrh8tD377mC48ka56WkrwUqUb5pg9EXv24J4XZw,5
|
|
9
|
+
sgpu-0.6.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 alex6095
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sgpu
|