Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

GPUStatusCheck

Probe the servers listed in machines.csv over SSH and report whether GPU state looks healthy or if there are signs of a GPU "fallen off the bus" condition.

What it does

For each machine, the probe:

  1. SSHes in with a configurable username and private key (with an automatic fallback user on auth failure)
  2. Runs nvidia-smi -L and collects per-GPU telemetry (utilization, memory, temperature, power, clocks, PCIe bus id, and each card's UUID)
  3. Checks which GPUs have active nvidia-smi pmon process rows and enriches them with ps command lines
  4. Sums current GPU power draw in watts and averages GPU temperature
  5. Samples network traffic in/out and CPU busy% (two /proc/net/dev and /proc/stat readings sharing one second, physical interfaces only)
  6. Reads CPU model and core count, RAM total/used%, and root-filesystem total/used%
  7. Captures machine uptime and checks recent kernel logs for common GPU bus-off patterns
  8. Prints a summary table and optionally JSON

The probe writes nothing to the target host's disk, so it stays accurate even on machines with a full filesystem. (The optional on-host agent below is the one deliberate exception: it keeps a small, bounded spool with a free-space guard so it can never contribute to filling a disk.)

It can also run in a watch loop and send Telegram alerts when a machine changes from healthy to degraded or SSH-failed. Duplicate alerts are suppressed with a small persisted state file.

The dashboard additionally tracks every physical GPU by UUID, so a card's history follows it between machines, and announces per-card drops to a Slack channel per owner (see the sections below).

Files

  • machines.csv — headered machine inventory rows
  • machines.sample.csv — commit-safe example inventory to copy from
  • gpu_status_check.py — the CLI probe script
  • scripts/remote-probe.sh — the remote probe script, shared by the CLI and the web dashboard (single source of truth for what runs on each host)
  • .env.example — sample configuration
  • slack-channels.json — owner → Slack channel map for GPU drop announcements (gitignored; see the Slack section below)
  • slack-channels.sample.json — commit-safe example channel map to copy from

Configuration

Create a .env file in the repo root:

cp .env.example .env

You can override:

GPUCHECK_USER=ezc
GPUCHECK_FALLBACK_USER=ubuntu
GPUCHECK_KEY=~/.ssh/EZC-HydraHost
GPUCHECK_TIMEOUT=10
GPUCHECK_PROBE_TIMEOUT=60
GPUCHECK_JOBS=8
GPUCHECK_STATE_FILE=.omx/gpucheck-state.json
GPUCHECK_NOTIFY_RECOVERY=0
GPUCHECK_SSH_FAILURE_REMINDER_HOURS=6
GPUCHECK_SKIP_LOGS=0
TELEGRAM_BOT_TOKEN=123456789:AAExampleToken
TELEGRAM_CHAT_ID=-1001234567890

Machine inventory schema

The preferred machines.csv format is headered and backward compatible:

name,ip,platform,owner,commission_date,location
ezc-gc-05e,217.138.104.127,gc,ezc,2024-05-12,rack-a1

Start from the sample file:

cp machines.sample.csv machines.csv
  • name — machine label
  • ip — SSH target; use a.b.c.d:x to connect to SSH port x instead of 22
  • platform — e.g. gc, n07, edge
  • owner — responsible owner/team
  • commission_date — YYYY-MM-DD
  • location — physical location label, shown in the dashboard table and modal
  • uptime — collected at probe time and shown in the report

Older two-column files with just name,ip still work.

Telegram setup

  • Create a bot with @BotFather
  • Add the bot to the target channel or group
  • Use the bot token as TELEGRAM_BOT_TOKEN
  • Use the channel/group ID as TELEGRAM_CHAT_ID

Run

python3 gpu_status_check.py --machines machines.csv

If SSH fails with an authentication error (e.g. Permission denied), both the CLI and the dashboard retry the probe once as GPUCHECK_FALLBACK_USER (default ubuntu) — useful for hosts provisioned with only the stock cloud user. Other failures are not retried with the fallback user. The user that succeeded is recorded with the probe result and used for the dashboard's copy-SSH-command shortcut. Set GPUCHECK_FALLBACK_USER= (empty) to disable.

Transient transport errors (No route to host, connection reset/closed, and connection timed out) are retried once after a one-second pause before the machine is marked SSH-failed. Authentication fallback remains separate.

The script scans hosts in parallel. Use --jobs N or GPUCHECK_JOBS=N to tune concurrency; the default is 8. Progress is printed as hosts complete. --probe-timeout N or GPUCHECK_PROBE_TIMEOUT=N sets a hard per-host timeout for the whole SSH probe. --skip-logs or GPUCHECK_SKIP_LOGS=1 skips kernel log checks for faster live telemetry scans.

The report includes a jobs column with one character per GPU index. D means that GPU has at least one active process row, x means it is idle, and E means the probe saw GPU fallen-off-bus evidence. For example, DDDDxxxx means GPUs 0-3 are busy and GPUs 4-7 are idle. The power_w column shows total GPU power draw in watts at the check moment. The temp_c column shows average GPU temperature in Celsius at the check moment. JSON reports include the same telemetry fields, including gpu_jobs, gpu_power_w, and gpu_avg_temp_c.

Optional JSON report:

python3 gpu_status_check.py --machines machines.csv --json-out report.json

Watch mode:

python3 gpu_status_check.py --machines machines.csv --watch --interval 300

Faster live telemetry scan:

python3 gpu_status_check.py --machines machines.csv --jobs 16 --skip-logs

Web dashboard

The Node.js dashboard polls the same CSV inventory over SSH, stores history in SQLite, and serves a React dashboard with:

  • Summary tiles (machine counts by status, total fleet power, average temp)
  • A collapsible fleet history panel (total power and status counts over 24h)
  • Three display modes — a sortable machine table, a card grid whose border color shows machine status, and a GPUs view listing every physical card by UUID (type, current machine/slot/tenant, placement count, last seen) whose rows open a per-card lifecycle modal with charts, placement history, daily rollups, and job history — with free-text search plus status and GPU-type filters (type options carry live machine counts), and optional grouping by owner or location; group headers are collapsible and summarize count, ok/degraded/ssh-failed, total and average power, and average temperature; a Charts button in each group header expands 24h group history charts (total power, average temperature, average GPU utilization, and total network in/out) backed by GET /api/group-history?by=owner|location&key=<label>&hours=24; Table and Cards views can export all machines matching current filters to CSV, one row per known GPU, regardless of collapsed groups
  • A per-machine modal with metadata (including CPU model/cores, total RAM, and total disk with current usage), tabbed charts (Power, Temperature, Utilization, Network in/out, and System with CPU/RAM/disk utilization %) over the last 24 hours with pinch-to-zoom and drag-to-pan, GPU process history, and probe history; when SSH fails, the current failure remains the machine status while the latest successful probe time and its GPU, process, CPU, memory, and disk snapshot remain visible; the Network interfaces section has one-click MAC and BMC IP copy controls; clicking the machine IP copies a ready-to-use SSH command. Each node also shows the latest SSH snapshot's IOMMU group status and instantaneous IPMI chassis power (watts, when supported by the BMC). The interface table shows public IPv4 addresses observed by https://ifconfig.me/ip through each eligible interface. NAT can give multiple interfaces the same public address. The lookups are best-effort and time-limited. These readings are visible to all dashboard viewers. The GPU tooltip shows negotiated and maximum PCIe link width and speed when Linux exposes them. Machine details also show NIC link speed and cumulative RX/TX errors and drops (with changes from the previous comparable snapshot), and available BMC inlet temperature, cooling and PSU sensor readings. The IPMI Power tab under GPU history charts chassis power as live samples accumulate.
  • GPU lifecycle tracking by UUID: every telemetry row records the GPU's UUID, an identity table follows each physical card across machines/slots/tenants (sighting segments), per-GPU job rows carry the owner renting the GPU at probe time, and down events resolve the card via its last known slot; query with GET /api/gpus and GET /api/gpus/<uuid>?hours=N (identity, sightings, metric history, job history, and daily rollups). Completed UTC days of per-GPU telemetry are folded into gpu_daily_stats before retention pruning runs, so long-term per-card stats survive beyond GPUCHECK_RETENTION_DAYS
  • Built-in Telegram alerting, maintenance mode, and a health/watchdog endpoint (see sections below)

Install dependencies:

npm install

Run the API server:

npm run dev

In another terminal, run the React dev server:

npm run dev:client

Open the dev dashboard:

http://127.0.0.1:5173

Build and run the combined production-style server:

npm run build
npm start

Open the built dashboard:

http://127.0.0.1:4100

Run tests:

npm run check

npm run check runs the TypeScript and Python tests, strict type-checking, the production client build, and syntax checks for every tracked shell script. Node.js 22.12 or newer is required.

Dashboard-specific settings:

GPUCHECK_POLL_INTERVAL_SECONDS=300
GPUCHECK_MACHINES=machines.csv
GPUCHECK_DB=data/gpu-status.sqlite
GPUCHECK_PROCESS_ARGS_MAX_CHARS=512
GPUCHECK_DISABLE_STARTUP_POLL=0
GPUCHECK_RETENTION_DAYS=30
GPUCHECK_MIN_FREE_DISK_BYTES=5368709120
GPUCHECK_HOST=127.0.0.1
PORT=4100
SLACK_BOT_TOKEN=
GPUCHECK_SLACK_CHANNELS=slack-channels.json
GPUCHECK_SLACK_DRY_RUN=0

GPUCHECK_HOST controls the bind address (default 127.0.0.1). Set GPUCHECK_HOST=0.0.0.0 to expose the dashboard on all interfaces — note there is no authentication, and the dashboard can trigger SSH-backed polls and edit .env, so only do this on a trusted network (or keep it behind a VPN such as Tailscale or a reverse proxy with auth).

The dashboard keeps monitoring reads public. Mutations are disabled when no admin key is configured and require the bearer key when administration mode is enabled.

Admin access and Web agent management

Set GPUCHECK_ADMIN_API_KEY to enable mutations and the agent-management UI. Generate at least 32 random bytes outside the repository, then place the value in the production .env without committing it:

openssl rand -base64 32

Public summary, machine, GPU, history, poll-status, configuration-display, and health endpoints remain readable while locked. The following actions require Authorization: Bearer <key> and are exposed only after unlocking the current browser tab:

  • Poll now
  • CSV path and polling-interval changes
  • maintenance and expected-GPU-count changes
  • agent install/upgrade, uninstall, progress, and operation history

The browser stores the key in sessionStorage, so reloading the same tab keeps it unlocked and closing the tab removes it. Lock clears it immediately. The key is never written to SQLite or persistent localStorage.

The current HTTP deployment does not protect this key in transit. Anyone able to observe the network can capture it. Keep the warning visible and rotate the key after nginx HTTPS termination is enabled.

Agent operations target active inventory machines only. The Admin toolbar's Upgrade installed agents button upgrades every active machine whose latest probe detected an agent. The status filter also includes OK and Degraded; Select visible selects exactly the rows currently shown so they can be installed/upgraded or uninstalled together. Install is idempotent and uninstall requires a separate confirmation; jobs run asynchronously with bounded concurrency. Hosts without passwordless sudo are skipped, other machine failures do not stop the batch, and progress/history survive tab closure. A server restart marks ambiguous queued/running items interrupted instead of retrying them automatically.

The Stale SSH keys status filter shows machines whose latest SSH error reports a changed host key. Admins can clear their stored known_hosts entries in one operation; host-key checking stays enabled, and the next successful SSH connection accepts the replacement key. Use this only after verifying the machines were intentionally reinstalled.

Settings:

GPUCHECK_ADMIN_API_KEY=
GPUCHECK_AGENT_INSTALL_JOBS=4
GPUCHECK_AGENT_MAX_BATCH=250
GPUCHECK_AGENT_OPERATION_RETENTION_DAYS=30
GPUCHECK_AGENT_OUTPUT_MAX_CHARS=4000

Stored diagnostic output is sanitized, secret-redacted, and truncated. A successful install does not override monitoring state; the next live poll must report agentVersion before the UI treats the agent as present. Failed, skipped, and interrupted items can be explicitly selected into a new operation.

Production rollout must be separately approved: add the key, run npm run check, restart, verify public reads while locked, verify 401 without a key and success with it, then pilot install and uninstall on one non-critical machine. Confirm presence/absence with a live poll before a small bulk pilot. Rollback to the prior commit with its lockfile and restart; the additive operation-history tables may remain. Rotate the key after rollback or HTTPS enablement.

History older than GPUCHECK_RETENTION_DAYS (default 30) is pruned from the SQLite database after each poll so it does not grow without bound. Each machine's most recent probe result is always kept, even if it is older than the retention window. Set GPUCHECK_RETENTION_DAYS=0 to keep history forever. GPUCHECK_MIN_FREE_DISK_BYTES makes /api/health return HTTP 503 before the database fills its filesystem; the default is 5 GiB.

Production deployment and rollback

The checked-in deploy/gpustatuscheck.service is the production service template. Review its user, group, working directory, and executable paths for the target host before installing it.

npm ci
npm run check
sudo install -m 0644 deploy/gpustatuscheck.service /etc/systemd/system/gpustatuscheck.service
sudo systemctl daemon-reload
sudo systemctl restart gpustatuscheck
curl --fail --show-error http://127.0.0.1:4100/api/health

Before deployment, record git rev-parse HEAD as the rollback commit. To roll back code, check out that commit, run npm ci, npm run build, restart the service, and verify both the local and public health endpoints.

Database backup and storage recovery

Detailed history is pruned after a completed poll, but deleting SQLite rows does not immediately shrink the database file. Never run an in-place VACUUM on a nearly full filesystem: SQLite needs substantial temporary space.

Before reducing retention or compacting, create an online backup on a separate filesystem with enough free capacity, verify it, and copy it off-host:

cd /home/ezc/gpustatuscheck
backup_dir=/mnt/gpu-backups
df -h "$backup_dir"
backup_file="$backup_dir/gpu-status-$(date -u +%Y%m%dT%H%M%SZ).sqlite"
sqlite3 data/gpu-status.sqlite ".backup '$backup_file'"
sqlite3 "$backup_file" 'PRAGMA integrity_check;'
sha256sum "$backup_file"

The integrity check must print ok. Copy the backup and its recorded checksum to another host before continuing. Then set GPUCHECK_RETENTION_DAYS=30, restart the service so it reloads .env, and trigger one controlled poll:

curl --fail --show-error -X POST http://127.0.0.1:4100/api/poll-runs
sqlite3 data/gpu-status.sqlite 'PRAGMA page_size; PRAGMA page_count; PRAGMA freelist_count;'
curl --fail --show-error http://127.0.0.1:4100/api/health

Freed pages are reused by future inserts even though the file remains the same size. Physical compaction is a separate maintenance operation requiring explicit approval. At the start of that maintenance window, stop the service and every other process that can write the database; keep all writers stopped while creating the final VACUUM INTO copy, running PRAGMA integrity_check, recording its checksum, and promoting it. Copy the original database and any WAL/SHM files to the backup filesystem, verify that copy, then remove the root filesystem originals only after the backup is proven. Copy the compacted database to data/gpu-status.sqlite.next, verify it again, and rename it to data/gpu-status.sqlite. Restart writers only after the new database passes health plus representative machine, history, and GPU endpoint checks. Roll back by keeping writers stopped and restoring the verified original database.

On-host agent (optional, per machine)

The SSH poll only sees a machine every 5 minutes, and an unreachable window leaves a permanent hole in history. The optional on-host agent closes both gaps: a systemd timer samples the same telemetry as the probe every 60s plus kernel/GPU log events (Xid, NVRM, bus-off, OOM) with exact timestamps, buffering everything in a bounded local spool (/var/lib/gpucheck-agent/spool, 200 MiB / 7 day caps, sampling pauses below 1 GiB free disk). The dashboard drains the spool over the same SSH connection right after each successful probe and backfills the data — so an outage window fills itself in as soon as the host is reachable again.

The agent is optional per host and the SSH poll always keeps working. Machines without the agent behave exactly as before; any mix is fine, forever. Machine status, alerting, and GPU drop detection stay driven by the live poll only — agent data enriches charts, per-GPU history, daily rollups, and the new per-machine "Kernel events" modal section. Agent sample timestamps are historical telemetry and do not count as successful server contact; while SSH is unavailable, the dashboard shows the latest successful live-probe snapshot. Retention preserves both the latest live result and latest successful live result for each machine, even when they are older than the normal history window. The machine modal also shows the agent version, last sample ingested, last successful drain, and latest agent note so a stalled spool is distinguishable from an agent that is still reporting.

The SSH probe and agent also report each matched network interface's name, current MAC address, assigned IP addresses, and link state. The modal keeps the latest snapshot from each source separately, so agent data remains available during SSH outages. For NATed hosts, these are addresses assigned inside the machine; they do not reveal the public NAT address or identify the host across the NAT boundary. Agent version 0.1.2 added interface snapshots; version 0.1.4 also reports the BMC's IPMI LAN address when ipmitool, timeout, and local IPMI access are available directly or through non-interactive sudo. Already- installed agents need upgrading to report these fields.

Install / upgrade / remove (needs passwordless sudo on the host; hosts without it are skipped and stay SSH-poll-only):

npm run agent:install -- --only <machine-name>   # pilot one host
npm run agent:install                            # whole inventory CSV
npm run agent:install -- --uninstall --only <machine-name>

Then enable draining on the server: GPUCHECK_AGENT_DRAIN=1 in .env and restart. Machines running the agent show an "A" badge in the table. Settings:

GPUCHECK_AGENT_DRAIN=0              # master switch for draining (default off)
GPUCHECK_AGENT_DRAIN_TIMEOUT=120    # seconds per drain exec
GPUCHECK_AGENT_DRAIN_MAX_LINES=600  # samples per drain (~10h; backlogs catch up over polls)
GPUCHECK_AGENT_RETENTION_DAYS=21    # 60s samples are ~12x volume, so shorter retention;
                                    # daily per-GPU rollups still keep the long-term signal

Slack GPU drop announcements

Each poll compares a machine's expected GPU roster — every card whose most recent sighting points at that machine — against the UUIDs the probe actually reported. Cards that vanish open an incident: one Slack message per machine per event, listing every card lost in that poll. Each card's return is posted as a reply in that thread (broadcast so it also shows in the channel), followed by an all-clear once the last one is back.

Set SLACK_BOT_TOKEN (a bot token with the chat:write scope) and map owners to channels in slack-channels.json (gitignored, re-read every poll so edits need no restart):

{
  "iota":    { "channel": "C0123456789" },
  "Vast":    { "channel": "C0456789012", "mention": "@ops" },
  "cloreai": { "channel": "C0789012345" }
}

The bot must be invited to each channel (/invite @your-bot) or Slack replies channel_not_found. An owner with no entry never alerts, which is how idle or internal machines stay quiet; mention is optional and is prepended to drop messages only. Set GPUCHECK_SLACK_DRY_RUN=1 to log the messages that would be sent without contacting Slack.

Incidents are always recorded, even when there is no channel or the machine is in maintenance, so history stays complete and unmuting a machine never replays old drops. Announcement timestamps are written only after Slack confirms delivery, so a failed send retries on the next poll instead of being lost. Unreachable hosts are skipped entirely — a host that cannot be probed says nothing about its cards, so an SSH outage never fires false GPU-drop alerts.

Dashboard Telegram alerts

When TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID are set, the dashboard server sends the same transition alerts as the CLI after each scheduled poll: a message when a machine enters degraded or ssh_failed, deduplicated so an unchanged problem does not re-alert, and optional recovery notices with GPUCHECK_NOTIFY_RECOVERY=1. Dedup state lives in the SQLite database (alert_states table). If a Telegram send fails, the state is not advanced, so the alert retries on the next poll.

An SSH-failed machine also gets a reminder every six hours by default while the failure continues. Set GPUCHECK_SSH_FAILURE_REMINDER_HOURS to another positive number to change the interval, or 0 to disable reminders. Reminder timing is persisted in SQLite and advances only after Telegram confirms delivery. Maintenance machines stay muted; their reminder timer restarts after each muted poll so leaving maintenance does not trigger an overdue reminder.

If you run the dashboard continuously, you no longer need the Python watcher loop for alerting; the CLI remains useful for one-shot checks from a terminal or cron.

The dashboard also tracks each machine's expected GPU count (the highest a healthy probe has ever reported). If a later healthy probe sees fewer GPUs, the machine is marked degraded with "only N/M GPUs visible" and alerts — catching GPUs that fall off the bus without leaving kernel-log evidence. If a machine is legitimately downsized, reset the learned count:

curl -X PATCH -H 'Content-Type: application/json' \
  -d '{"expectedGpuCount": null}' http://127.0.0.1:4100/api/machines/<id>

Maintenance mode

The machine detail modal has an Enter/Exit maintenance button (also via PATCH /api/machines/<id> with {"maintenance": true}). Machines in maintenance show an "M" chip in the table and stop sending alerts; their status is still tracked silently, so leaving maintenance does not fire stale alerts — only new transitions after that point alert.

Monitor watchdog

GET /api/health reports secondsSinceLastPoll and returns HTTP 503 when no poll has completed for 3x the poll interval (minimum 15 minutes), so an external checker can detect a wedged monitor. Optionally set GPUCHECK_HEARTBEAT_URL (e.g. a healthchecks.io ping URL); the server GETs it after every successful poll, and the watchdog service alerts you if the pings stop.

The dashboard reads .env at startup, with shell environment variables taking precedence. The Config panel in the dashboard writes GPUCHECK_MACHINES and GPUCHECK_POLL_INTERVAL_SECONDS back to .env and applies those two changes to the running scheduler immediately. Saving validates that the CSV exists and parses (rejecting the save otherwise) and triggers an immediate poll of the new inventory — if a poll is already running, the new inventory is polled right after it finishes. Set GPUCHECK_ENV_FILE=/path/to/.env before starting the API server to use a different environment file.

The dashboard stores per-poll history in SQLite tables for machines, poll runs, probe results, and GPU processes. GPU process rows include nvidia-smi pmon fields plus bounded ps command-line enrichment so Python/PyTorch jobs show their script or launcher command where available.

Recommended scheduling

The cleanest approach is usually:

  • keep the script as a one-shot checker
  • run it from cron, launchd, or systemd every N minutes
  • let the script handle alert deduplication and Telegram delivery

That avoids a fragile always-on process while still giving you "autopilot" behavior.

Notes

  • The script uses ssh -o BatchMode=yes, so it will not prompt for passwords.
  • It uses StrictHostKeyChecking=accept-new to avoid first-run host-key prompts. If you prefer stricter host-key handling, change that option in the script.
  • "degraded" means either kernel/log evidence suggests a bus-off issue, or nvidia-smi returned a driver/GPU error, or zero GPUs were reported.
  • --skip-logs disables kernel/log evidence, so degradation then comes from live nvidia-smi checks only.
  • Telegram alerts are only sent when there is a state transition into a problem state unless GPUCHECK_NOTIFY_RECOVERY=1 is set, in which case recovery notices are also sent.
  • The report JSON now includes the machine metadata fields alongside probe results.
  • The live probe also captures machine uptime, so the report can show how long each host has been up at the time of the check.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages