slurmwatch 0.1.0__tar.gz
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.
- slurmwatch-0.1.0/.github/workflows/ci.yml +51 -0
- slurmwatch-0.1.0/.github/workflows/release.yml +50 -0
- slurmwatch-0.1.0/.gitignore +14 -0
- slurmwatch-0.1.0/.pre-commit-config.yaml +18 -0
- slurmwatch-0.1.0/LICENSE +21 -0
- slurmwatch-0.1.0/MANIFEST.in +3 -0
- slurmwatch-0.1.0/PKG-INFO +217 -0
- slurmwatch-0.1.0/README.md +177 -0
- slurmwatch-0.1.0/assets/demo.gif +0 -0
- slurmwatch-0.1.0/assets/demo.tape +31 -0
- slurmwatch-0.1.0/assets/render_demo.py +217 -0
- slurmwatch-0.1.0/pyproject.toml +105 -0
- slurmwatch-0.1.0/setup.cfg +4 -0
- slurmwatch-0.1.0/src/slurmwatch/__init__.py +36 -0
- slurmwatch-0.1.0/src/slurmwatch/__main__.py +4 -0
- slurmwatch-0.1.0/src/slurmwatch/_version.py +10 -0
- slurmwatch-0.1.0/src/slurmwatch/cli.py +428 -0
- slurmwatch-0.1.0/src/slurmwatch/collector.py +779 -0
- slurmwatch-0.1.0/src/slurmwatch/config.py +66 -0
- slurmwatch-0.1.0/src/slurmwatch/exceptions.py +33 -0
- slurmwatch-0.1.0/src/slurmwatch/model.py +185 -0
- slurmwatch-0.1.0/src/slurmwatch/py.typed +0 -0
- slurmwatch-0.1.0/src/slurmwatch/slurm.py +705 -0
- slurmwatch-0.1.0/src/slurmwatch/tui.py +718 -0
- slurmwatch-0.1.0/src/slurmwatch.egg-info/PKG-INFO +217 -0
- slurmwatch-0.1.0/src/slurmwatch.egg-info/SOURCES.txt +36 -0
- slurmwatch-0.1.0/src/slurmwatch.egg-info/dependency_links.txt +1 -0
- slurmwatch-0.1.0/src/slurmwatch.egg-info/entry_points.txt +2 -0
- slurmwatch-0.1.0/src/slurmwatch.egg-info/requires.txt +14 -0
- slurmwatch-0.1.0/src/slurmwatch.egg-info/scm_file_list.json +32 -0
- slurmwatch-0.1.0/src/slurmwatch.egg-info/scm_version.json +8 -0
- slurmwatch-0.1.0/src/slurmwatch.egg-info/top_level.txt +1 -0
- slurmwatch-0.1.0/tests/__init__.py +0 -0
- slurmwatch-0.1.0/tests/conftest.py +58 -0
- slurmwatch-0.1.0/tests/test_cli.py +304 -0
- slurmwatch-0.1.0/tests/test_collector.py +643 -0
- slurmwatch-0.1.0/tests/test_slurm.py +432 -0
- slurmwatch-0.1.0/tests/test_tui.py +423 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint-test:
|
|
11
|
+
name: Lint & Test (py${{ matrix.python-version }})
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
strategy:
|
|
14
|
+
fail-fast: false
|
|
15
|
+
matrix:
|
|
16
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: ${{ matrix.python-version }}
|
|
24
|
+
allow-prereleases: true
|
|
25
|
+
|
|
26
|
+
- name: Install build deps
|
|
27
|
+
run: |
|
|
28
|
+
python -m pip install --upgrade pip
|
|
29
|
+
pip install "setuptools>=77" wheel setuptools-scm
|
|
30
|
+
|
|
31
|
+
- name: Install package + dev deps
|
|
32
|
+
run: |
|
|
33
|
+
pip install -e ".[dev]"
|
|
34
|
+
|
|
35
|
+
- name: Lint with ruff
|
|
36
|
+
run: ruff check .
|
|
37
|
+
|
|
38
|
+
- name: Check formatting with ruff
|
|
39
|
+
run: ruff format --check .
|
|
40
|
+
|
|
41
|
+
- name: Type check with mypy
|
|
42
|
+
run: mypy src/ tests/
|
|
43
|
+
|
|
44
|
+
- name: Test with pytest
|
|
45
|
+
run: python -m pytest --cov=slurmwatch --cov-report=xml --cov-report=term --cov-fail-under=60
|
|
46
|
+
|
|
47
|
+
- name: Upload coverage to Codecov
|
|
48
|
+
uses: codecov/codecov-action@v4
|
|
49
|
+
with:
|
|
50
|
+
file: ./coverage.xml
|
|
51
|
+
fail_ci_if_error: false
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
id-token: write
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build-and-publish:
|
|
14
|
+
name: Build & Publish to PyPI
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
with:
|
|
20
|
+
# setuptools-scm needs full history + tags to derive the version.
|
|
21
|
+
fetch-depth: 0
|
|
22
|
+
|
|
23
|
+
- uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: "3.12"
|
|
26
|
+
|
|
27
|
+
- name: Build wheel and sdist
|
|
28
|
+
run: |
|
|
29
|
+
pip install build setuptools-scm
|
|
30
|
+
python -m build
|
|
31
|
+
|
|
32
|
+
- name: Verify tag matches built version
|
|
33
|
+
run: |
|
|
34
|
+
TAG_VERSION="${GITHUB_REF_NAME#v}"
|
|
35
|
+
PKG_VERSION=$(python -m setuptools_scm)
|
|
36
|
+
echo "Tag version: $TAG_VERSION"
|
|
37
|
+
echo "Package version: $PKG_VERSION"
|
|
38
|
+
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
|
|
39
|
+
echo "Tag version ($TAG_VERSION) != package version ($PKG_VERSION)"
|
|
40
|
+
exit 1
|
|
41
|
+
fi
|
|
42
|
+
echo "Version match OK"
|
|
43
|
+
|
|
44
|
+
- name: Check artifacts with twine
|
|
45
|
+
run: |
|
|
46
|
+
pip install twine
|
|
47
|
+
twine check dist/*
|
|
48
|
+
|
|
49
|
+
- name: Publish to PyPI (Trusted Publishing)
|
|
50
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
|
+
# Keep in step with the ruff release CI resolves, or the hook's --fix
|
|
4
|
+
# and CI's check will disagree about import sorting.
|
|
5
|
+
rev: v0.15.20
|
|
6
|
+
hooks:
|
|
7
|
+
- id: ruff
|
|
8
|
+
args: [--fix]
|
|
9
|
+
- id: ruff-format
|
|
10
|
+
|
|
11
|
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
12
|
+
rev: v2.1.0
|
|
13
|
+
hooks:
|
|
14
|
+
- id: mypy
|
|
15
|
+
additional_dependencies:
|
|
16
|
+
- textual>=0.53,<9
|
|
17
|
+
- pynvml>=11.5,<12
|
|
18
|
+
- types-python-dateutil
|
slurmwatch-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Youzhi
|
|
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,217 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: slurmwatch
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Live, process-isolated node-local hardware telemetry for active Slurm jobs
|
|
5
|
+
Author-email: Youzhi Yu <yuyouzhi666@icloud.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/PursuitOfDataScience/slurmwatch
|
|
8
|
+
Project-URL: Repository, https://github.com/PursuitOfDataScience/slurmwatch.git
|
|
9
|
+
Project-URL: Documentation, https://github.com/PursuitOfDataScience/slurmwatch#readme
|
|
10
|
+
Project-URL: Issues, https://github.com/PursuitOfDataScience/slurmwatch/issues
|
|
11
|
+
Keywords: slurm,hpc,monitoring,gpu,tui
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering
|
|
21
|
+
Classifier: Topic :: System :: Monitoring
|
|
22
|
+
Classifier: Topic :: System :: Hardware
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: textual<9,>=0.53
|
|
28
|
+
Provides-Extra: nvidia
|
|
29
|
+
Requires-Dist: pynvml<12,>=11.5; extra == "nvidia"
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
34
|
+
Requires-Dist: ruff>=0.3; extra == "dev"
|
|
35
|
+
Requires-Dist: mypy>=1.8; extra == "dev"
|
|
36
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
37
|
+
Requires-Dist: twine>=4.0; extra == "dev"
|
|
38
|
+
Requires-Dist: setuptools-scm>=8; extra == "dev"
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
<h1 align="center">slurmwatch</h1>
|
|
42
|
+
|
|
43
|
+
<p align="center">
|
|
44
|
+
<strong>See exactly what your Slurm job is doing to the hardware — live, per process, in one screen.</strong><br>
|
|
45
|
+
CPU, memory, and per-GPU telemetry for a running job, with an allocation-efficiency verdict that tells you when you're wasting cores or GPUs.
|
|
46
|
+
</p>
|
|
47
|
+
|
|
48
|
+
<p align="center">
|
|
49
|
+
<a href="https://github.com/PursuitOfDataScience/slurmwatch/actions/workflows/ci.yml"><img src="https://github.com/PursuitOfDataScience/slurmwatch/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
50
|
+
<a href="https://pypi.org/project/slurmwatch/"><img src="https://img.shields.io/pypi/v/slurmwatch.svg" alt="PyPI"></a>
|
|
51
|
+
<img src="https://img.shields.io/badge/python-3.10%2B-blue.svg" alt="Python 3.10+">
|
|
52
|
+
<img src="https://img.shields.io/badge/license-MIT-green.svg" alt="MIT License">
|
|
53
|
+
<a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/badge/lint-ruff-261230.svg" alt="Ruff"></a>
|
|
54
|
+
</p>
|
|
55
|
+
|
|
56
|
+
<p align="center">
|
|
57
|
+
<img src="https://raw.githubusercontent.com/PursuitOfDataScience/slurmwatch/main/assets/demo.gif" width="860" alt="slurmwatch live TUI dashboard: per-process CPU, memory, and GPU telemetry for a Slurm job, with an allocation-efficiency verdict flagging an idle GPU and a memory warning">
|
|
58
|
+
</p>
|
|
59
|
+
|
|
60
|
+
<p align="center"><em>A real allocation, caught in the act: CPU healthy, memory climbing into the OOM warning band, one A100 pinned at 92% while the second sits idle — and a verdict that says so.</em></p>
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Why slurmwatch?
|
|
65
|
+
|
|
66
|
+
You asked Slurm for 16 cores and 2 GPUs. Are you *using* them? On a shared cluster, the difference between a busy allocation and a half-idle one is real money and real queue time — but the usual tools make you SSH around, juggle `nvidia-smi` and `/proc`, and mentally subtract page cache from memory to guess.
|
|
67
|
+
|
|
68
|
+
slurmwatch answers the question directly:
|
|
69
|
+
|
|
70
|
+
- 🎯 **Allocation-efficiency verdict** — a plain-language readout (`GOOD` / `UNDERUSED` / `IDLE` / `WARNING`) for CPU, memory, and GPU, so you know at a glance whether to downsize your request.
|
|
71
|
+
- 🔬 **Per-process GPU attribution** — reads the job's PIDs from its cgroup and asks NVML which of *your* processes are on each GPU, so a neighbor's job on a shared node never inflates your numbers.
|
|
72
|
+
- 🧠 **Honest memory** — working-set (RSS minus reclaimable cache) with a configurable OOM guard, so you see real pressure before the kernel kills you.
|
|
73
|
+
- 🛰️ **Works from anywhere** — on the compute node you get full live telemetry; from a login node, `slurmwatch <jobid>` auto-falls back to Slurm's own accounting and still prints memory + CPU for any of your running jobs.
|
|
74
|
+
- ⚙️ **Zero config** — just `slurmwatch <jobid>`. Auto-discovers your jobs, auto-detects cgroup v1/v2, auto-detects whether it's on the node. No flags to memorize.
|
|
75
|
+
|
|
76
|
+
## Install
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install "slurmwatch[nvidia]" # with NVIDIA GPU monitoring
|
|
80
|
+
pip install slurmwatch # CPU + memory only
|
|
81
|
+
|
|
82
|
+
# isolated, if you prefer:
|
|
83
|
+
pipx install "slurmwatch[nvidia]"
|
|
84
|
+
uv tool install "slurmwatch[nvidia]"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Requires **Python 3.10+** and **Linux with cgroup v1 or v2**. GPU monitoring is NVIDIA-only (via `pynvml`).
|
|
88
|
+
|
|
89
|
+
## Quick start
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
slurmwatch # auto-discover and attach to your running job
|
|
93
|
+
slurmwatch 12345 # attach to a specific job (array: 12345_3, het: 12345+1)
|
|
94
|
+
slurmwatch --demo # try the live TUI right now — no Slurm needed
|
|
95
|
+
slurmwatch 12345 --once --json # one machine-readable snapshot, then exit
|
|
96
|
+
slurmwatch 12345 --log run.jsonl # headless logging (JSON Lines or CSV)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
> **Tip:** for full live telemetry, run on the node executing the job:
|
|
100
|
+
> `srun --jobid 12345 --overlap slurmwatch 12345`
|
|
101
|
+
|
|
102
|
+
## Usage
|
|
103
|
+
|
|
104
|
+
### On the compute node vs. anywhere else
|
|
105
|
+
|
|
106
|
+
- **On the node** (`srun --overlap`, or a batch step) → full live telemetry: per-GPU utilization, per-process attribution, working-set memory, sparklines.
|
|
107
|
+
- **From a login node** → slurmwatch can't reach the job's cgroups, so it **automatically** queries Slurm (`sstat`) and prints a usage summary instead — no flag needed:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
$ slurmwatch 51397890 # from a login node
|
|
111
|
+
Job 51397890 gpu RUNNING on midway3-0602
|
|
112
|
+
Memory peak 174.6 GiB / 200.0 GiB (87%)
|
|
113
|
+
CPU 3:29:03 CPU-time ~2.9 of 4 cores (avg since start)
|
|
114
|
+
GPU 3 allocated — run slurmwatch on the compute node for live GPU utilization
|
|
115
|
+
source: sstat (remote; run on the node for working-set & live GPU util)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
(GPU *utilization* isn't available remotely — Slurm accounting tracks GPU count, not per-device util. Everything else is.)
|
|
119
|
+
|
|
120
|
+
### Command-line options
|
|
121
|
+
|
|
122
|
+
| Option | Description |
|
|
123
|
+
|--------|-------------|
|
|
124
|
+
| `job_id` | Job to monitor (optional; auto-discovers your running jobs). Array tasks (`12345_3`) and het components (`12345+1`) resolve to the right cgroup. |
|
|
125
|
+
| `--once` | Take one snapshot, print to stdout, exit |
|
|
126
|
+
| `--log FILE` | Run headless, appending snapshots to FILE |
|
|
127
|
+
| `--append` | With `--log`, append instead of overwriting |
|
|
128
|
+
| `--format {json,csv}` | Output format for `--once`/`--log` (default: `--log` infers from extension, else JSON; `--once` prints CSV) |
|
|
129
|
+
| `--json` | Shorthand for `--format json` |
|
|
130
|
+
| `--interval SECONDS` | Polling interval (default 0.5 TUI / 1.0 headless; must be > 0) |
|
|
131
|
+
| `--ascii` | ASCII-only glyphs (no Unicode blocks) |
|
|
132
|
+
| `--demo` | Simulated data — no Slurm needed |
|
|
133
|
+
| `--verbose` | Verbose diagnostics on stderr |
|
|
134
|
+
| `--version` | Print version and exit |
|
|
135
|
+
|
|
136
|
+
Exit codes: `0` success · `1` runtime failure (job not found / wrong node / Slurm error) · `2` bad configuration. Errors go to stderr so `--once`/`--log` output stays clean for pipelines.
|
|
137
|
+
|
|
138
|
+
### Interactive TUI keys
|
|
139
|
+
|
|
140
|
+
| Key | Action | | Key | Action |
|
|
141
|
+
|-----|--------|-|-----|--------|
|
|
142
|
+
| `c` | Focus CPU | | `↑` / `↓` | Scroll |
|
|
143
|
+
| `m` | Focus Memory | | `PgUp` / `PgDn` | Page scroll |
|
|
144
|
+
| `g` | Focus GPU | | `q` / `Esc` | Quit |
|
|
145
|
+
| `v` | Focus Verdict | | | |
|
|
146
|
+
|
|
147
|
+
With no `job_id` and several running jobs, a picker appears — arrow keys + `Enter` (or click).
|
|
148
|
+
|
|
149
|
+
### Environment variables
|
|
150
|
+
|
|
151
|
+
| Variable | Default | Description |
|
|
152
|
+
|----------|---------|-------------|
|
|
153
|
+
| `SLURMWATCH_MOCK` | — | `1` enables demo/simulation mode (no Slurm needed) |
|
|
154
|
+
| `SLURMWATCH_POLL_INTERVAL` | `0.5` | TUI polling interval (seconds; min 0.05) |
|
|
155
|
+
| `SLURMWATCH_HEADLESS_INTERVAL` | `1.0` | Headless polling interval (seconds; min 0.05) |
|
|
156
|
+
| `SLURMWATCH_OOM_WARN` | `0.85` | Memory warning threshold (fraction of limit) |
|
|
157
|
+
| `SLURMWATCH_OOM_CRIT` | `0.90` | Memory critical threshold (fraction of limit) |
|
|
158
|
+
| `SLURMWATCH_HISTORY_SECONDS` | `60` | Sparkline history length (seconds) |
|
|
159
|
+
| `SLURMWATCH_CPU_UNDERUSE` | `0.5` | Flag CPU underuse below this many effective cores |
|
|
160
|
+
| `SLURMWATCH_GPU_IDLE_PCT` | `5.0` | Per-process GPU util (%) below which a GPU counts as idle |
|
|
161
|
+
| `SLURMWATCH_ASCII` | `0` | ASCII-only output (`1`/`true`) |
|
|
162
|
+
| `SLURMWATCH_FORMAT` | — | Default `--log`/`--once` format (`json`/`csv`); explicit `--format` wins |
|
|
163
|
+
| `SLURMWATCH_CSV_DIALECT` | `excel` | Python `csv` dialect for CSV output |
|
|
164
|
+
|
|
165
|
+
## What it measures
|
|
166
|
+
|
|
167
|
+
**CPU** — utilization as a percentage of the cores allocated *on this node* (multi-node jobs are scaled to node-local limits). Reads cgroup `cpuacct`/`cpu.stat` when present, and falls back to summing `/proc/<pid>/stat` — so CPU is measured even on clusters that constrain jobs with `cpuset` only. Reports **effective cores** ("~1.2 of 16 used") and warns on underuse.
|
|
168
|
+
|
|
169
|
+
**Memory** — **working set** (RSS minus reclaimable page cache), peak (with a fallback for kernels < 5.19 that lack `memory.peak`), and a configurable **OOM guard** that flags warning/critical *before* the kernel does. Falls back to node RAM when the cgroup limit is unlimited.
|
|
170
|
+
|
|
171
|
+
**GPU** (NVIDIA) — the right devices are selected from `scontrol show job -d` (IDX list) plus CUDA UUID/MIG tokens, so it works with `ConstrainDevices` and multiple jobs per node. Per-process VRAM and SM utilization attributed to *your* PIDs, plus device-wide util, VRAM, power, temperature, and genuine throttling detection. CPU-only jobs never show other users' GPUs.
|
|
172
|
+
|
|
173
|
+
**Verdict** — the summary panel that grades whether each resource is actually being used, and flags idle GPUs, single-core workloads on big allocations, and negligible memory pressure.
|
|
174
|
+
|
|
175
|
+
## Output formats
|
|
176
|
+
|
|
177
|
+
**JSON Lines** (default for `--log`):
|
|
178
|
+
|
|
179
|
+
```json
|
|
180
|
+
{"timestamp": 1705312234.567, "job_id": "12345", "hostname": "cn001", "cpu": {...}, "memory": {...}, "gpus": [...]}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
**CSV** — rows padded to a fixed 8-GPU column layout, so every row has identical columns (loads cleanly into pandas):
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
timestamp,job_id,hostname,elapsed_seconds,cpu_cores,cpu_percent,cpu_effective_cores,...
|
|
187
|
+
1705312234.567,12345,cn001,3600,16,45.50,7.28,...
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Use as a library
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
import asyncio
|
|
194
|
+
from slurmwatch import TelemetryCollector, resolve_job_context
|
|
195
|
+
|
|
196
|
+
async def sample(job_id: str):
|
|
197
|
+
ctx = resolve_job_context(job_id)
|
|
198
|
+
collector = TelemetryCollector(ctx)
|
|
199
|
+
await collector.start()
|
|
200
|
+
try:
|
|
201
|
+
snapshot = await collector.next_snapshot()
|
|
202
|
+
print(snapshot.to_json())
|
|
203
|
+
finally:
|
|
204
|
+
await collector.stop()
|
|
205
|
+
|
|
206
|
+
asyncio.run(sample("12345"))
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Limitations
|
|
210
|
+
|
|
211
|
+
- **NVIDIA-only** GPU support (AMD/ROCm not yet supported).
|
|
212
|
+
- **Single-node** view — multi-node jobs show per-node data for the node you're on.
|
|
213
|
+
- **Live GPU utilization and working-set memory require running on the job's node**; from elsewhere you get the `sstat` summary (peak memory + CPU time + allocation) for your own jobs.
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
MIT © Youzhi Yu
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
<h1 align="center">slurmwatch</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>See exactly what your Slurm job is doing to the hardware — live, per process, in one screen.</strong><br>
|
|
5
|
+
CPU, memory, and per-GPU telemetry for a running job, with an allocation-efficiency verdict that tells you when you're wasting cores or GPUs.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://github.com/PursuitOfDataScience/slurmwatch/actions/workflows/ci.yml"><img src="https://github.com/PursuitOfDataScience/slurmwatch/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
10
|
+
<a href="https://pypi.org/project/slurmwatch/"><img src="https://img.shields.io/pypi/v/slurmwatch.svg" alt="PyPI"></a>
|
|
11
|
+
<img src="https://img.shields.io/badge/python-3.10%2B-blue.svg" alt="Python 3.10+">
|
|
12
|
+
<img src="https://img.shields.io/badge/license-MIT-green.svg" alt="MIT License">
|
|
13
|
+
<a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/badge/lint-ruff-261230.svg" alt="Ruff"></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<p align="center">
|
|
17
|
+
<img src="https://raw.githubusercontent.com/PursuitOfDataScience/slurmwatch/main/assets/demo.gif" width="860" alt="slurmwatch live TUI dashboard: per-process CPU, memory, and GPU telemetry for a Slurm job, with an allocation-efficiency verdict flagging an idle GPU and a memory warning">
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
<p align="center"><em>A real allocation, caught in the act: CPU healthy, memory climbing into the OOM warning band, one A100 pinned at 92% while the second sits idle — and a verdict that says so.</em></p>
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Why slurmwatch?
|
|
25
|
+
|
|
26
|
+
You asked Slurm for 16 cores and 2 GPUs. Are you *using* them? On a shared cluster, the difference between a busy allocation and a half-idle one is real money and real queue time — but the usual tools make you SSH around, juggle `nvidia-smi` and `/proc`, and mentally subtract page cache from memory to guess.
|
|
27
|
+
|
|
28
|
+
slurmwatch answers the question directly:
|
|
29
|
+
|
|
30
|
+
- 🎯 **Allocation-efficiency verdict** — a plain-language readout (`GOOD` / `UNDERUSED` / `IDLE` / `WARNING`) for CPU, memory, and GPU, so you know at a glance whether to downsize your request.
|
|
31
|
+
- 🔬 **Per-process GPU attribution** — reads the job's PIDs from its cgroup and asks NVML which of *your* processes are on each GPU, so a neighbor's job on a shared node never inflates your numbers.
|
|
32
|
+
- 🧠 **Honest memory** — working-set (RSS minus reclaimable cache) with a configurable OOM guard, so you see real pressure before the kernel kills you.
|
|
33
|
+
- 🛰️ **Works from anywhere** — on the compute node you get full live telemetry; from a login node, `slurmwatch <jobid>` auto-falls back to Slurm's own accounting and still prints memory + CPU for any of your running jobs.
|
|
34
|
+
- ⚙️ **Zero config** — just `slurmwatch <jobid>`. Auto-discovers your jobs, auto-detects cgroup v1/v2, auto-detects whether it's on the node. No flags to memorize.
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install "slurmwatch[nvidia]" # with NVIDIA GPU monitoring
|
|
40
|
+
pip install slurmwatch # CPU + memory only
|
|
41
|
+
|
|
42
|
+
# isolated, if you prefer:
|
|
43
|
+
pipx install "slurmwatch[nvidia]"
|
|
44
|
+
uv tool install "slurmwatch[nvidia]"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Requires **Python 3.10+** and **Linux with cgroup v1 or v2**. GPU monitoring is NVIDIA-only (via `pynvml`).
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
slurmwatch # auto-discover and attach to your running job
|
|
53
|
+
slurmwatch 12345 # attach to a specific job (array: 12345_3, het: 12345+1)
|
|
54
|
+
slurmwatch --demo # try the live TUI right now — no Slurm needed
|
|
55
|
+
slurmwatch 12345 --once --json # one machine-readable snapshot, then exit
|
|
56
|
+
slurmwatch 12345 --log run.jsonl # headless logging (JSON Lines or CSV)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
> **Tip:** for full live telemetry, run on the node executing the job:
|
|
60
|
+
> `srun --jobid 12345 --overlap slurmwatch 12345`
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
### On the compute node vs. anywhere else
|
|
65
|
+
|
|
66
|
+
- **On the node** (`srun --overlap`, or a batch step) → full live telemetry: per-GPU utilization, per-process attribution, working-set memory, sparklines.
|
|
67
|
+
- **From a login node** → slurmwatch can't reach the job's cgroups, so it **automatically** queries Slurm (`sstat`) and prints a usage summary instead — no flag needed:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
$ slurmwatch 51397890 # from a login node
|
|
71
|
+
Job 51397890 gpu RUNNING on midway3-0602
|
|
72
|
+
Memory peak 174.6 GiB / 200.0 GiB (87%)
|
|
73
|
+
CPU 3:29:03 CPU-time ~2.9 of 4 cores (avg since start)
|
|
74
|
+
GPU 3 allocated — run slurmwatch on the compute node for live GPU utilization
|
|
75
|
+
source: sstat (remote; run on the node for working-set & live GPU util)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
(GPU *utilization* isn't available remotely — Slurm accounting tracks GPU count, not per-device util. Everything else is.)
|
|
79
|
+
|
|
80
|
+
### Command-line options
|
|
81
|
+
|
|
82
|
+
| Option | Description |
|
|
83
|
+
|--------|-------------|
|
|
84
|
+
| `job_id` | Job to monitor (optional; auto-discovers your running jobs). Array tasks (`12345_3`) and het components (`12345+1`) resolve to the right cgroup. |
|
|
85
|
+
| `--once` | Take one snapshot, print to stdout, exit |
|
|
86
|
+
| `--log FILE` | Run headless, appending snapshots to FILE |
|
|
87
|
+
| `--append` | With `--log`, append instead of overwriting |
|
|
88
|
+
| `--format {json,csv}` | Output format for `--once`/`--log` (default: `--log` infers from extension, else JSON; `--once` prints CSV) |
|
|
89
|
+
| `--json` | Shorthand for `--format json` |
|
|
90
|
+
| `--interval SECONDS` | Polling interval (default 0.5 TUI / 1.0 headless; must be > 0) |
|
|
91
|
+
| `--ascii` | ASCII-only glyphs (no Unicode blocks) |
|
|
92
|
+
| `--demo` | Simulated data — no Slurm needed |
|
|
93
|
+
| `--verbose` | Verbose diagnostics on stderr |
|
|
94
|
+
| `--version` | Print version and exit |
|
|
95
|
+
|
|
96
|
+
Exit codes: `0` success · `1` runtime failure (job not found / wrong node / Slurm error) · `2` bad configuration. Errors go to stderr so `--once`/`--log` output stays clean for pipelines.
|
|
97
|
+
|
|
98
|
+
### Interactive TUI keys
|
|
99
|
+
|
|
100
|
+
| Key | Action | | Key | Action |
|
|
101
|
+
|-----|--------|-|-----|--------|
|
|
102
|
+
| `c` | Focus CPU | | `↑` / `↓` | Scroll |
|
|
103
|
+
| `m` | Focus Memory | | `PgUp` / `PgDn` | Page scroll |
|
|
104
|
+
| `g` | Focus GPU | | `q` / `Esc` | Quit |
|
|
105
|
+
| `v` | Focus Verdict | | | |
|
|
106
|
+
|
|
107
|
+
With no `job_id` and several running jobs, a picker appears — arrow keys + `Enter` (or click).
|
|
108
|
+
|
|
109
|
+
### Environment variables
|
|
110
|
+
|
|
111
|
+
| Variable | Default | Description |
|
|
112
|
+
|----------|---------|-------------|
|
|
113
|
+
| `SLURMWATCH_MOCK` | — | `1` enables demo/simulation mode (no Slurm needed) |
|
|
114
|
+
| `SLURMWATCH_POLL_INTERVAL` | `0.5` | TUI polling interval (seconds; min 0.05) |
|
|
115
|
+
| `SLURMWATCH_HEADLESS_INTERVAL` | `1.0` | Headless polling interval (seconds; min 0.05) |
|
|
116
|
+
| `SLURMWATCH_OOM_WARN` | `0.85` | Memory warning threshold (fraction of limit) |
|
|
117
|
+
| `SLURMWATCH_OOM_CRIT` | `0.90` | Memory critical threshold (fraction of limit) |
|
|
118
|
+
| `SLURMWATCH_HISTORY_SECONDS` | `60` | Sparkline history length (seconds) |
|
|
119
|
+
| `SLURMWATCH_CPU_UNDERUSE` | `0.5` | Flag CPU underuse below this many effective cores |
|
|
120
|
+
| `SLURMWATCH_GPU_IDLE_PCT` | `5.0` | Per-process GPU util (%) below which a GPU counts as idle |
|
|
121
|
+
| `SLURMWATCH_ASCII` | `0` | ASCII-only output (`1`/`true`) |
|
|
122
|
+
| `SLURMWATCH_FORMAT` | — | Default `--log`/`--once` format (`json`/`csv`); explicit `--format` wins |
|
|
123
|
+
| `SLURMWATCH_CSV_DIALECT` | `excel` | Python `csv` dialect for CSV output |
|
|
124
|
+
|
|
125
|
+
## What it measures
|
|
126
|
+
|
|
127
|
+
**CPU** — utilization as a percentage of the cores allocated *on this node* (multi-node jobs are scaled to node-local limits). Reads cgroup `cpuacct`/`cpu.stat` when present, and falls back to summing `/proc/<pid>/stat` — so CPU is measured even on clusters that constrain jobs with `cpuset` only. Reports **effective cores** ("~1.2 of 16 used") and warns on underuse.
|
|
128
|
+
|
|
129
|
+
**Memory** — **working set** (RSS minus reclaimable page cache), peak (with a fallback for kernels < 5.19 that lack `memory.peak`), and a configurable **OOM guard** that flags warning/critical *before* the kernel does. Falls back to node RAM when the cgroup limit is unlimited.
|
|
130
|
+
|
|
131
|
+
**GPU** (NVIDIA) — the right devices are selected from `scontrol show job -d` (IDX list) plus CUDA UUID/MIG tokens, so it works with `ConstrainDevices` and multiple jobs per node. Per-process VRAM and SM utilization attributed to *your* PIDs, plus device-wide util, VRAM, power, temperature, and genuine throttling detection. CPU-only jobs never show other users' GPUs.
|
|
132
|
+
|
|
133
|
+
**Verdict** — the summary panel that grades whether each resource is actually being used, and flags idle GPUs, single-core workloads on big allocations, and negligible memory pressure.
|
|
134
|
+
|
|
135
|
+
## Output formats
|
|
136
|
+
|
|
137
|
+
**JSON Lines** (default for `--log`):
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{"timestamp": 1705312234.567, "job_id": "12345", "hostname": "cn001", "cpu": {...}, "memory": {...}, "gpus": [...]}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**CSV** — rows padded to a fixed 8-GPU column layout, so every row has identical columns (loads cleanly into pandas):
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
timestamp,job_id,hostname,elapsed_seconds,cpu_cores,cpu_percent,cpu_effective_cores,...
|
|
147
|
+
1705312234.567,12345,cn001,3600,16,45.50,7.28,...
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Use as a library
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
import asyncio
|
|
154
|
+
from slurmwatch import TelemetryCollector, resolve_job_context
|
|
155
|
+
|
|
156
|
+
async def sample(job_id: str):
|
|
157
|
+
ctx = resolve_job_context(job_id)
|
|
158
|
+
collector = TelemetryCollector(ctx)
|
|
159
|
+
await collector.start()
|
|
160
|
+
try:
|
|
161
|
+
snapshot = await collector.next_snapshot()
|
|
162
|
+
print(snapshot.to_json())
|
|
163
|
+
finally:
|
|
164
|
+
await collector.stop()
|
|
165
|
+
|
|
166
|
+
asyncio.run(sample("12345"))
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Limitations
|
|
170
|
+
|
|
171
|
+
- **NVIDIA-only** GPU support (AMD/ROCm not yet supported).
|
|
172
|
+
- **Single-node** view — multi-node jobs show per-node data for the node you're on.
|
|
173
|
+
- **Live GPU utilization and working-set memory require running on the job's node**; from elsewhere you get the `sstat` summary (peak memory + CPU time + allocation) for your own jobs.
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
MIT © Youzhi Yu
|
|
Binary file
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# slurmwatch demo tape (alternative to assets/render_demo.py).
|
|
2
|
+
#
|
|
3
|
+
# The committed README hero (assets/demo.gif) is produced by:
|
|
4
|
+
# python assets/render_demo.py
|
|
5
|
+
#
|
|
6
|
+
# This VHS tape records the *live* TUI in mock mode instead. Render with:
|
|
7
|
+
# vhs assets/demo.tape (requires https://github.com/charmbracelet/vhs)
|
|
8
|
+
|
|
9
|
+
Output assets/demo.gif
|
|
10
|
+
Set Shell bash
|
|
11
|
+
Set FontSize 16
|
|
12
|
+
Set Width 1320
|
|
13
|
+
Set Height 760
|
|
14
|
+
Set Padding 16
|
|
15
|
+
Set Framerate 24
|
|
16
|
+
Set Theme "Catppuccin Mocha"
|
|
17
|
+
Set TypingSpeed 35ms
|
|
18
|
+
|
|
19
|
+
Type "SLURMWATCH_MOCK=1 slurmwatch"
|
|
20
|
+
Sleep 300ms
|
|
21
|
+
Enter
|
|
22
|
+
Sleep 3s
|
|
23
|
+
Type "c"
|
|
24
|
+
Sleep 1200ms
|
|
25
|
+
Type "m"
|
|
26
|
+
Sleep 1200ms
|
|
27
|
+
Type "g"
|
|
28
|
+
Sleep 1200ms
|
|
29
|
+
Type "v"
|
|
30
|
+
Sleep 1500ms
|
|
31
|
+
Type "q"
|