名称: mactop
描述: |
通过 mactop 的 TOON 格式获取 Apple Silicon Mac 的实时硬件指标。
提供 CPU、RAM、GPU、功耗、温度、网络、磁盘 I/O 和 Thunderbolt 总线信息。
适用于用户需要获取 Apple Silicon Mac 的系统状态、硬件监控或性能指标时。
在无头 TOON 模式下执行 mactop 并解析其输出,以获取硬件指标。
brew install mactopmactop --format toon --headless --count 1
CPU 使用率:
mactop --format toon --headless --count 1 | grep "^cpu_usage:" | awk '{print $2}'
内存(已用/总量 GB):
mactop --format toon --headless --count 1 | grep -E "^ (Used|Total):" | awk '{printf "%.1f", $2/1073741824}'
GPU 使用率:
mactop --format toon --headless --count 1 | grep "^gpu_usage:" | awk '{print $2}'
功耗(总功耗/CPU/GPU):
mactop --format toon --headless --count 1 | grep -E "^ (TotalPower|CPUPower|GPUPower):" | awk '{print $2}'
散热状态:
mactop --format toon --headless --count 1 | grep "^thermal_state:" | awk '{print $2}'
温度:
mactop --format toon --headless --count 1 | grep "^ SocTemp:" | awk '{print $2}'
芯片信息:
mactop --format toon --headless --count 1 | grep "^ Name:" | awk '{print $2}'
网络 I/O(字节/秒):
mactop --format toon --headless --count 1 | grep -E "^( InBytesPerSec| OutBytesPerSec):" | awk '{print $2}'
Thunderbolt 总线:
mactop --format toon --headless --count 1 | grep "^ Name:" | awk '{print $2}'
| 选项 | 说明 |
|---|---|
--count N |
采样次数(默认:1) |
--interval MS |
采样间隔(毫秒,默认:1000) |
timestamp: "2026-01-25T20:00:00-07:00"
soc_metrics:
CPUPower: 0.15
GPUPower: 0.02
TotalPower: 8.5
SocTemp: 42.3
memory:
Total: 25769803776
Used: 14852408320
Available: 10917395456
cpu_usage: 5.2
gpu_usage: 1.8
thermal_state: Normal
system_info:
Name: Apple M4 Pro
CoreCount: 12
将指标格式化为易读的框体:
┌─ Apple M4 Pro ──────────────────────┐
│ CPU: 5.2% | RAM: 13.8/24.0 GB │
│ GPU: 1.8% | Power: 8.5W total │
│ Thermal: Normal | SoC: 42.3°C │
└─────────────────────────────────────┘
/usr/sbin 添加到 PATH 中which mactop