#!/usr/bin/env bash set -euo pipefail export LC_ALL=C boot_raw="$(sysctl -n kern.boottime)" boot_epoch="$(printf '%s\n' "$boot_raw" | sed -E 's/^\{ sec = ([0-9]+),.*/\1/')" if [[ ! "$boot_epoch" =~ ^[0-9]+$ ]]; then echo "BLOCKER darwin_boot_epoch_unavailable" exit 65 fi now_epoch="$(date +%s)" uptime_seconds=$((now_epoch - boot_epoch)) if (( uptime_seconds < 0 )); then echo "BLOCKER darwin_uptime_invalid" exit 65 fi uid="$(id -u)" launch_label="com.momo.ollama111-allow-proxy" if launchctl print "gui/${uid}/${launch_label}" >/dev/null 2>&1; then startup_enabled="enabled" else startup_enabled="unknown" fi if curl --max-time 2 -fsS http://127.0.0.1:11434/api/tags >/dev/null 2>&1; then startup_active="active" else startup_active="inactive" fi logical_cores="$(sysctl -n hw.logicalcpu 2>/dev/null || true)" load1="$(sysctl -n vm.loadavg 2>/dev/null | awk '{ print $2; exit }')" mem_available_percent="$(memory_pressure -Q 2>/dev/null | awk -F': ' ' /System-wide memory free percentage/ { value = $2 gsub(/%/, "", value) print value exit } ')" disk_used_percent="$(df -Pk / 2>/dev/null | awk ' NR == 2 { value = $5 gsub(/%/, "", value) print value exit } ')" if [[ ! "$logical_cores" =~ ^[0-9]+$ ]] || (( logical_cores < 1 )) || [[ ! "$load1" =~ ^[0-9]+([.][0-9]+)?$ ]] || [[ ! "$mem_available_percent" =~ ^[0-9]+([.][0-9]+)?$ ]] || [[ ! "$disk_used_percent" =~ ^[0-9]+([.][0-9]+)?$ ]]; then echo "BLOCKER darwin_perf_readback_unavailable" exit 65 fi printf 'boot_id=darwin_%s uptime_seconds=%s systemd_state=darwin_ssh startup_enabled=%s startup_active=%s\n' \ "$boot_epoch" "$uptime_seconds" "$startup_enabled" "$startup_active" printf 'perf_schema=agent99_perf_readback_v1 os=darwin cores=%s load1=%s mem_available_percent=%s disk_used_percent=%s\n' \ "$logical_cores" "$load1" "$mem_available_percent" "$disk_used_percent"