Slurm usage reporting
Read-only usage report for the research cluster dance (Chacha + Disco), not
the student cluster Carnaval. slurm_usage.py turns sacct records into CSV
files and a Markdown report: who submits, under which account, partition and
QOS, what was requested, what was allocated, what was actually consumed.
Python 3.10+ standard library only (Chacha runs Ubuntu 22.04, Python 3.10), so
it runs from the repo or from /root/provisioning without a venv. It runs
sacct, and sacctmgr show assoc when --live-assoc is given. Both commands
are read-only, and nothing is written to Slurm.
Files
| Path | Role |
|---|---|
slurm_usage.py | the extractor |
slurm_history.py | full history since service start, split per node (see Full history per node) |
history-extract.sh | read-only extraction for slurm_history.py, sent to Chacha on stdin |
tests/test_slurm_usage.py, tests/test_slurm_history.py | parsing, consolidation and per-node split tests (unittest) |
tests/fixtures/ | synthetic sacct files, regenerated by make_fixtures.py; no real users or jobs |
Validate locally
cd calc/provisioning/slurm/usage
python3 -m unittest discover -s tests -v
On Windows, any Python 3.10+ works the same way (py -m unittest discover -s tests -v), WSL is not needed. Windows ships no time-zone database, so
zoneinfo cannot load Europe/Zurich there. The tool then uses a built-in
CET/CEST rule (SwissTime), which the tests check hour by hour against
zoneinfo for 2025-2027. pip install tzdata is only needed for another
--tz. Tested with the official Python 3.10.11 for Windows, which has no tz
database: 46 tests pass and 2 POSIX-only tests are skipped. On Windows the
0700 mode has no effect, so the output directory keeps the permissions of
its parent folder.
Run offline on audit files
The audit archive from Chacha holds 05-jobs-30j.psv (sacct -X, allocation
rows), 06-jobs-et-steps-30j.psv (allocations + steps) and
04-associations.psv (headerless sacctmgr output).
umask 077
./slurm_usage.py --start 2026-10-05 --end 2026-11-05 --out-dir ~/slurm-usage \
--alloc-psv 05-jobs-30j.psv --steps-psv 06-jobs-et-steps-30j.psv \
--assoc-psv 04-associations.psv --as-of 2026-11-04T09:00:00 \
--capacity-cpus 160 --capacity-gpus 4
--as-of is the time the audit was taken. Without it, the tool uses the latest
timestamp in the data and records that guess in data_quality.csv.
A single combined sacct file (no -X) goes in with --psv. If you only
have the -X file, there is no step data, so CPU, RAM and GPU usage come out
unmeasured.
Run in production (read-only)
On Chacha (it hosts slurmdbd), as any account that can run sacct.
PrivateData=none lets a plain user see every job, so root is not needed.
umask 077
/root/provisioning/slurm/usage/slurm_usage.py --live --live-assoc \
--start 2026-10-01 --end 2026-11-01 --out-dir /root/slurm-usage \
--capacity-cpus 160 --capacity-gpus 4
The query it runs:
SLURM_TIME_FORMAT=standard sacct -a -D --array -P \
-S 2026-10-01T00:00:00 -E 2026-11-01T00:00:00 --format <fields>
The query's raw output is kept as raw-sacct.psv in the run directory, so
the run can be reproduced offline. The tool reaches the servers through the
existing calc/provisioning/deploy.sh, which copies provisioning/ to
/root/provisioning on both hosts. Run it only after this change has been
reviewed: deploy.sh also re-asserts root's rm_vscode.sh crontab line.
Access prerequisites: an SSH account on Chacha (HEVS VPN), sacct on the
PATH, and a readable slurmdbd. Disco needs nothing, because it reads the
same accounting database.
Exit code: 0 on success. 1 means at least one error row in data_quality.csv
(malformed or unparseable rows). The other rows are still written.
Outputs
Each run creates a new directory
<out-dir>/slurm-usage_<start>_<end>_<timestamp>/ with mode 0700 and never
reuses one that already exists.
| File | One row per |
|---|---|
job_attempts.csv | allocation record = execution attempt (requeue, preemption) |
jobs.csv | logical job: plain job or one array element (JobID) |
user_summary.csv, project_summary.csv, partition_summary.csv | user / Slurm account / partition |
cluster_summary.csv | metric (metric,value,unit,note) |
data_quality.csv | detected issue (level,code,scope,detail) |
field_dictionary.csv | column of every file above, with unit and definition |
manifest.json | run parameters, rules, input SHA-256, row counts |
report.md | readable summary with the limits section |
Consolidation rules
Three levels are kept apart:
- Attempt: one allocation row.
sacct -Dkeeps every attempt of a requeued or preempted job.attempt_idis<JobID>#<n>, numbered bySubmit, thenStart, thenRestarts. - Logical job: one
JobIDas printed with--array. An array element is its own job.JobIDRawis not used as a key, because the pending elements of an array (cancelled before they started) all carry the array'sJobIDRaw. - Submitted job: the array master id or the plain job id
(
original_job_id).
Steps are attached to the attempt of the same JobID whose
[Start - 120 s, End + 120 s] contains the step's Start. When several
attempts match, the step goes to the one whose start is closest. Steps of a
requeued job reuse the same JobID.batch / JobID.0 names in every attempt,
and they can end a few seconds after their allocation. A combined stream
falls back to file order. A step that matches nothing is reported as
orphan_step. On the October 2026 audit, all 20,328 steps were attached, and
the parent TotalCPU matched the sum of its steps on all 14,839 attempts.
Allocated CPU hours:
cpu_alloc_h = AllocCPUS x ElapsedRaw / 3600. Only started attempts count.
AllocCPUS counts hardware threads. With CR_CORE_MEMORY a request is
rounded up to whole cores, so a 5-CPU request is allocated 6.
Consumed CPU hours: cpu_used_h is the sum of TotalCPU over all of the
attempt's steps (.batch, .extern, .interactive, numbered srun
steps). Each step is its own cgroup, so the sum does not double-count. The
parent row is never added: in sacct output without -X it already holds
the sum, and with -X it is 00:00:00.
cpu_eff = cpu_used_h / cpu_alloc_h. Aggregates are weighted by CPU-h and
only use attempts with cpu_measure=ok. These are left out of the ratio:
not_startedrunningno_stepszero_allocation(ElapsedRaw=0)over_allocation(more than 110 % of the allocation)
cpu_measure_coverage gives the share of allocated CPU-h that the ratio
rests on.
RAM: MaxRSS is the peak of one task, sampled every 30 s
(JobAcctGatherFrequency=30).
mem_maxrss_task_mbis the largestMaxRSSover the steps. It is a lower bound of the job's peak.mem_rss_tasks_sum_mbisTRESUsageInTotmem, the sum of per-task peaks that need not coincide in time.
Maxima are never summed across steps. Steps under 60 s get
mem_measure=short_job.
GPU: counts come from the generic gres/gpu. The typed entries
(gres/gpu:nvidia_h100_nvl) only give the model and are never added to the
count. gpu_util_max_pct and gpumem_max_mb are the maxima over steps of
TRESUsageInMax gres/gpuutil and gres/gpumem. They are values sampled by
jobacct_gather, not a time series, so read them as indicative.
Shards (gres/shard, fractions of a GPU shared between jobs) are counted
apart from whole GPUs:
shard_alloc_hholds shard-hours. A GPU has 96 shards on Chacha and 80 on Disco.- A shard-only job contributes 0 to
gpu_alloc_h, togpu_alloc_shareand to the GPU load statistics. - Its
gpuutilis the load of the whole shared GPU, so it getsgpu_measure=measured_shared_gpuand is counted inshard_measured_attemptsonly. No load is attributed to individual shards or to the users sharing a GPU. gpu_alloc_shareis the share of whole-GPU capacity reserved, not the GPU utilisation.
The October 2026 audit has no shard allocation.
ReqTRES is the request as Slurm recorded it, including defaults. It is
kept separate from AllocTRES and is not the original sbatch line.
Window and attribution
sacct -S/-E selects every job that was in any state (pending, running,
finished) during the window, not only jobs submitted in it. -E is the end
date at 00:00 and is exclusive.
- The
*_in_windowcolumns clip each attempt's running interval to[start, min(end, as_of)). They add up across consecutive windows. Use them for monthly figures and capacity shares. - The columns without the suffix cover whole attempts. A job crossing a window boundary appears in both windows.
cpu_used_h_in_windowprorates consumed CPU over time, assuming even consumption.
Timestamps are local (--tz Europe/Zurich) and are converted to UTC for all
arithmetic, which handles the October DST change. A time inside the repeated
hour (02:00 to 03:00 on that day) is ambiguous in sacct output and is read
as the first occurrence.
Cross-check against sreport: over 2026-10-28 00:00 to 2026-11-04 09:00,
cpu_alloc_h_in_window gives 655,333 CPU-minutes, the Allocated value of
sreport cluster utilization for the same period. The allocated share
(cpu_alloc_share) is comparable to sreport. It measures reservation, not
efficiency.
What cannot be measured
- Energy:
AcctGatherEnergyType=(null). - Time profile of CPU, RAM or GPU within a job:
AcctGatherProfileType=(null). Only end-of-step totals and sampled maxima exist. - The simultaneous RAM peak of a multi-task job.
- GPU load per shard or per user on a shared GPU.
- SSH connections. Job counts say nothing about logins. Habilitations come
from Slurm associations (
--assoc-psv,n_users_authorized). Logins would need a separate pass overauth.logor journald, not done here. - Billing:
TRESBillingWeightsencodes the priority policy, not consumption, and is not used.
Cadence, history, retention
Proposed cadence: a monthly run on the 2nd for the previous calendar month,
so the window is closed and no job is still running at its end. Ad-hoc runs
are possible at any time with --start/--end.
Retention (sacctmgr show configuration, 2026-11-04): every Purge* is
NONE and archiving is off, so slurmdbd holds every job since the cluster
was registered on 2025-01-22. Monthly exports keep the history independent of
that setting if a purge is configured later.
Full history per node
slurm_history.py reuses the consolidation of slurm_usage.py over the whole
database and splits it by physical node:
- The node comes from
NodeList, never from the partition: the partitiondancespans both nodes. - An attempt on several nodes is reported as
multi:<a>+<b>and counted in the cluster totals only. It is never added in full to each node. - Never-started attempts have no node and count only in the cluster totals.
- Hours are split across the local calendar months in which the job ran.
- Capacity per month is CPUs × hours from service start (the first
Cluster Registered TRESevent), minus the node'sDOWN/INVALperiods fromsacctmgr list events. - Records repeated across overlapping input files are removed (
duplicates_removedin the data-quality file).
# on the workstation: one read-only command per section, nothing written on Chacha
for s in jobs assoc events sreport env; do
ssh chacha.hevs.ch bash -s -- $s < history-extract.sh > $s.out 2> $s.err
done
python3 -I slurm_history.py --psv jobs.out --assoc-psv assoc.out --events-psv events.out \
--sreport-psv sreport.out --env-file env.out --as-of <time printed in jobs.err> --out-dir <private dir>
Outputs:
historical_monthly.csv,historical_yearly.csv: one row per period and node (chacha,disco,dance), withcum_*columns. Thedancerows carry thesreportallocation for cross-checking.{chacha,disco,dance}_summary.csv.historical_job_attempts.csvandhistorical_jobs.csv, each with a node column.historical_users.csvandhistorical_projects.csv: long format with anodecolumn.dancealready includes both nodes, so never add the three.historical_coverage.csv,historical_data_quality.csv.RAPPORT_{CHACHA,DISCO,DANCE}.md: French reports that name users. Store them like the other outputs (see Confidentiality).
On the 2026-11-04 extraction, the monthly cluster allocation matches sreport within 0.1 % in every closed month.
Confidentiality and storage
The outputs name users and their jobs. Keep them on Chacha in a 0700
directory such as /root/slurm-usage, or on an admin share. Give them to the
HPC managers only, and never commit them to this repository. report.md and
the summaries are the files meant for circulation inside the CALC@HEI team.
Proposed retention: keep raw and per-job files (raw-sacct.psv,
job_attempts.csv, jobs.csv) for 13 months, which covers year-over-year
comparison. Summaries can be kept longer. Delete old runs by whole directory.
Optional automation (not installed)
Install this only after review. A systemd timer on Chacha that runs as an
unprivileged service user with read access to sacct:
# /etc/systemd/system/calc-slurm-usage.service
[Service]
Type=oneshot
User=slurm-usage
UMask=0077
ExecStart=/bin/sh -c '/root/provisioning/slurm/usage/slurm_usage.py --live --live-assoc \
--start $(date -d "last month" +%%Y-%%m-01) --end $(date +%%Y-%%m-01) \
--out-dir /var/lib/calc-slurm-usage --capacity-cpus 160 --capacity-gpus 4'
# /etc/systemd/system/calc-slurm-usage.timer
[Timer]
OnCalendar=*-*-02 06:00
Persistent=true
[Install]
WantedBy=timers.target
The script path must be readable by the service user, because /root is
not. Each run writes a new dated directory, so earlier exports are never
overwritten.
Optional, separate: Grafana and SSH audit
Neither is deployed. If wanted:
- Grafana: load the monthly
*_summary.csvinto an existing data source, or expose a few gauges through the node exporter's textfile collector (cpu_alloc_share,cpu_eff,gpu_alloc_shareper month and account). Do not scrapesacctlive at short intervals: per-job efficiency is only known once a job ends. - SSH access: read
sshd"Accepted" lines from/var/log/auth.log*on both nodes. Count distinct users per day, and keep source IPs only if the data-protection rules allow it. Report this as its own indicator next to the Slurm associations, never derived from job counts.