#!/usr/bin/env bash
set -euo pipefail

read -rp "Jumlah top proses yang ditampilkan [10]: " TOP_LIMIT
read -rp "Tampilkan port aktif? [Y/n]: " SHOW_PORTS
TOP_LIMIT="${TOP_LIMIT:-10}"
SHOW_PORTS="${SHOW_PORTS:-Y}"

echo "=== Uptime ==="
uptime
echo
echo "=== Disk ==="
df -h
echo
echo "=== RAM ==="
free -h
echo
echo "=== Top proses ==="
ps aux --sort=-%mem | head -n "$TOP_LIMIT"
if [[ "$SHOW_PORTS" =~ ^[Yy]$ ]]; then
  echo
  echo "=== Port aktif ==="
  ss -tulpn
fi
echo
echo "=== Service gagal ==="
systemctl --failed || true
