結論先說
- Homebrew 一條命令裝好並託管
node_exporter:brew install node_exporter後用brew services常駐,預設在9100端口暴露/metrics。 - macOS 原生版不直接暴露溫度與
memory_pressure:Darwin 版自帶負載、內存頁、磁盤和網絡指標,但缺少芯片傳感器與壓力等級。 - 用
--collector.textfile.directory補齊缺失指標:定時將memory_pressure、sysctl vm.swapusage與pmset -g therm寫成.prom文件即可告警。 - 切勿把
:9100裸露在不可信網絡:在參數或 PF 防火牆中把監聽收窄到127.0.0.1:9100或僅放行監控伺服器。 - 看清內存瓶頸後能更好分配本地與雲端算力:重度重構交由雲端配額、本地留足測試內存,可看 Claude Code 訂閱專題 與 Claude Max 5x iOS 自助充值。

圖:本站根據 Prometheus Node Exporter 官方指南 整理的示意圖
本文根據 Prometheus 官方 Node Exporter 指南與 Homebrew 安裝文檔整理,資料核對於 2026-12-03。配圖為本站整理的示意圖,不是介面截圖。本站(bigolab.com)由益陽市赫山區必高科技有限公司獨立運營,是獨立第三方服務商,不是 Prometheus、Apple 或 Anthropic 官方網站。
適用於誰
- 在 16GB/24GB Mac mini 上跑 Claude Code 與容器,需盯防內存爆倉和 Swap 抖動的工程師。
- 想把多台 Mac mini 接入 Prometheus + Grafana 統一監控負載、磁盤與熱節流的運維人員。
- 發現 macOS 版
node_exporter缺少hwmon溫度指標,需補齊蘋果芯片指標的開發者。
一、macOS node_exporter 原生指標與補充採集對照
先分清哪些指標開箱即有、哪些需要藉助系統命令行轉寫成 Prometheus 格式:
| 監控維度 | 原生支持 | 推薦補齊數據源 | 告警參考 |
|---|---|---|---|
| CPU 負載 | 支持(node_load1、node_cpu_seconds_total) | 原生即可,對照總核數 | 15 分鐘負載超核數 |
| 內存餘量 | 支持(node_memory_*) | memory_pressure 算餘量 | 空閒低於 15% 預警 |
| Swap 用量 | 僅部分可推導 | sysctl vm.swapusage | 並發陡增應限流 |
| 熱節流 | macOS 原生暫缺 | pmset -g therm / macmon | CPU_Speed_Limit < 100 |
| APFS 空間 | 支持(node_filesystem_avail_bytes) | 留意本地快照佔用的塊 | 數據卷餘量 < 20GB |
將 memory_pressure 與 pmset -g therm 寫入 textfile 無需關 SIP,輕量穩定。

圖:本站根據 Homebrew 安裝與服務文檔 整理的示意圖
二、Homebrew 部署 node_exporter 與擴展采集腳本
先安裝 node_exporter、配置監聽地址與 textfile 目錄,再定時採集內存壓力與熱限速狀態:
# 1. 安裝 node_exporter(如尚未裝 Homebrew,先按 docs.brew.sh 官方腳本安裝)
brew install node_exporter
# 2. 創建 textfile 指標目錄,並調整 plist 僅監聽本機或內網 IP(示例監聽 127.0.0.1)
mkdir -p /opt/homebrew/var/node_exporter/textfile
cat <<'EOF' > /opt/homebrew/etc/node_exporter.args
--web.listen-address=127.0.0.1:9100
--collector.textfile.directory=/opt/homebrew/var/node_exporter/textfile
EOF
# 3. 如需讓 Homebrew service 載入自定義參數,檢查並編輯對應 Formula plist 後重啟
brew services start node_exporter
# 4. 編寫 macOS 內存壓力、Swap 與熱節流採集腳本
cat <<'EOF' > /opt/homebrew/bin/collect-mac-metrics.sh
#!/bin/zsh
OUT_DIR="/opt/homebrew/var/node_exporter/textfile"
TMP_FILE="${OUT_DIR}/mac_extra.prom.$$"
DEST_FILE="${OUT_DIR}/mac_extra.prom"
FREE_PCT=$(memory_pressure | awk -F': ' '/System-wide memory free percentage/{gsub(/%/,"",$2); print $2+0}')
SWAP_USED_MB=$(sysctl -n vm.swapusage | awk -F'used = ' '{print $2}' | awk '{gsub(/M/,"",$1); print $1+0}')
SPEED_LIMIT=$(pmset -g therm | awk -F'= ' '/CPU_Speed_Limit/{print $2+0; exit}')
[[ -z "$SPEED_LIMIT" ]] && SPEED_LIMIT=100
cat > "$TMP_FILE" <<PROM
# HELP mac_memory_free_percentage System-wide memory free percentage from memory_pressure
# TYPE mac_memory_free_percentage gauge
mac_memory_free_percentage ${FREE_PCT:-0}
# HELP mac_swap_used_megabytes Current macOS swap used in MB
# TYPE mac_swap_used_megabytes gauge
mac_swap_used_megabytes ${SWAP_USED_MB:-0}
# HELP mac_cpu_speed_limit_percent Thermal CPU speed limit percentage from pmset
# TYPE mac_cpu_speed_limit_percent gauge
mac_cpu_speed_limit_percent ${SPEED_LIMIT}
PROM
mv "$TMP_FILE" "$DEST_FILE"
EOF
chmod +x /opt/homebrew/bin/collect-mac-metrics.sh
# 5. 先跑一次腳本並驗證 9100 端口指標輸出
/opt/homebrew/bin/collect-mac-metrics.sh
curl -s http://127.0.0.1:9100/metrics | grep -E "mac_memory_free|mac_swap_used|mac_cpu_speed_limit"
人工核對要點:
- 查
homebrew.mxcl.node_exporter.plist確認傳入 textfile 目錄,改後brew services restart node_exporter。 - 腳本先寫臨時文件再
mv替換mac_extra.prom,防抓取半截數據。 - 配
LaunchAgent每 30–60 秒刷新;需更細芯片溫度可評估macmon。
訂閱與開通提示:接入熱節流與內存監控後,日常研發可選 Claude Pro iOS 自助充值,高並發推薦 Claude Max 5x iOS 自助充值 或 Claude Max 20x iOS 自助充值;驗證支持見 Claude KYC 協助服務 與 全部商品。全站以商品頁實時標價為準,標價不含稅,開具國內增值稅發票另付 6% 稅費;單獨申請自定義明細電子收據免費,企業批量採購支持簽訂正式中文服務合同並對公結算。
常見問題
問:裝好 node_exporter 後為什麼查不到 node_hwmon_temp_celsius?
答:node_hwmon_* 屬 Linux 接口,macOS 不提供;改採 pmset -g therm 看 CPU_Speed_Limit 降頻狀態。
問:跨網段中心 Prometheus 抓取 Mac mini,怎麼放行 9100?
答:勿暴露公網。將監聽綁在內網或隧道地址,用 PF 僅放行監控機訪問 9100。
問:多代理並發時,mac_swap_used_megabytes 漲到多少算危險?
答:數百 MB 屬正常;持續升至數 GB 且 mac_memory_free_percentage 低於 10%,應限制容器配額。
問:公司批量採購 Claude 訂閱用於集群開發,怎麼開具 6% 增值稅發票?
答:可經由 AI 訂閱與帳號服務總覽、Claude Pro 充值指南 與 Claude Max 5x/20x 充值指南 選購對公結算。全站以商品頁實時標價為準,標價不含稅,開具國內增值稅發票另付 6% 稅費;單獨申請自定義明細電子收據免費。本站明示質保訂閱、不質保封號,請嚴格遵守服務商條款合規使用。
相關教學
- Ollama 怎麼強制使用 GPU 加速:ollama ps 查看顯存佔比、num_gpu 參數與指定多卡編號
- OpenClaw 多模型省錢路由實戰:巡檢走 Ollama 與 DeepSeek V4.1-Flash、代碼切 Claude 5.5
- Dify 怎麼接入 llama.cpp 本地大模型:llama-server 兼容接口、host.docker.internal 與上下文設定
- Ollama 報錯 405 與 500 怎麼排查:接口 /v1 路徑錯配、POST 請求方法及 Runner 崩潰修復
0 條評論
還沒有評論,來搶沙發~