#!/usr/bin/env bash
# Install sysstat (iostat / sar / pidstat) on existing servers. Used by
# the AI Monitor's health-check context to surface iowait + per-disk
# utilization, which lets the diagnosis distinguish "user workload is
# CPU-bound" from "everyone's blocked on disk I/O because a backup is
# rsyncing".
#
# Idempotent: dnf install is a no-op when the package is already present.

set -euo pipefail

if command -v iostat >/dev/null 2>&1; then
    echo "✓ sysstat (iostat) already installed"
    exit 0
fi

echo "Installing sysstat..."
dnf install -y sysstat
if command -v iostat >/dev/null 2>&1; then
    echo "✓ sysstat installed; iostat available at $(command -v iostat)"
else
    echo "⚠ sysstat install reported success but iostat is still missing"
    exit 1
fi
