#!/usr/bin/env bash
set -u

section() {
  printf '\n[%s]\n' "$1"
}

section timestamp
date --iso-8601=seconds 2>/dev/null || date

section system
hostname
uname -a
uptime

section memory
free -h
grep -E 'MemAvailable|Cached|Dirty|Writeback|SwapTotal|SwapFree' /proc/meminfo

section pressure
for resource in cpu memory io; do
  printf '%s: ' "$resource"
  cat "/proc/pressure/$resource"
done

section vmstat
vmstat 1 5

section cpu
command -v mpstat >/dev/null 2>&1 && mpstat -P ALL 1 3 || true

section storage
command -v iostat >/dev/null 2>&1 && iostat -xz 1 3 || true

section network
ss -s
ip -s link

section cgroup
for file in cpu.max cpu.stat memory.current memory.max memory.events; do
  if [[ -r "/sys/fs/cgroup/$file" ]]; then
    printf '%s: ' "$file"
    cat "/sys/fs/cgroup/$file"
  fi
done
