Last active
May 9, 2026 13:17
-
-
Save dcolley/87fce3b8802802b9bb1a07349612faac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # dgx-monitor.sh — DGX Spark cluster watcher | |
| # Usage: ./dgxmon spark1 spark2 localhost spark3 ... | |
| set -euo pipefail | |
| HOSTS=("$@") | |
| SESSION="dgx-monitor" | |
| REFRESH_MS=2000 | |
| USER="${DGX_USER:-$(whoami)}" | |
| if [[ ${#HOSTS[@]} -eq 0 ]]; then | |
| echo "Usage: $0 host1 host2 ... (use 'localhost' for current machine)" | |
| exit 1 | |
| fi | |
| # Kill existing session if present | |
| tmux kill-session -t "$SESSION" 2>/dev/null || true | |
| # Function to decide command for a host | |
| get_command() { | |
| local host="$1" | |
| # Treat these as local | |
| if [[ "$host" == "localhost" || \ | |
| "$host" == "127.0.0.1" || \ | |
| "$host" == "$(hostname)" || \ | |
| "$host" == "$(hostname -s)" ]]; then | |
| echo "nv-monitor -i ${REFRESH_MS}" | |
| else | |
| echo "ssh -t ${USER}@${host} 'nv-monitor -i ${REFRESH_MS}'" | |
| fi | |
| } | |
| # Create session with the first host | |
| first_cmd=$(get_command "${HOSTS[0]}") | |
| tmux new-session -d -s "$SESSION" -x "$(tput cols)" -y "$(tput lines)" "$first_cmd" | |
| # Add remaining hosts as split panes | |
| for host in "${HOSTS[@]:1}"; do | |
| cmd=$(get_command "$host") | |
| tmux split-window -t "$SESSION" "$cmd" | |
| tmux select-layout -t "$SESSION" tiled | |
| done | |
| # Select first pane and attach | |
| tmux select-pane -t "$SESSION:0.0" | |
| tmux attach-session -t "$SESSION" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment