From bb2f9b2b3a3efb20025b0dd8b069beb66ed52709 Mon Sep 17 00:00:00 2001 From: weishen Date: Wed, 15 Apr 2026 12:20:00 +0800 Subject: [PATCH] Add: Prometheus+Grafana+NodeExporter monitoring deployment guide for MacMini --- ...Prometheus-Grafana-NodeExporter-MacMini.md | 434 ++++++++++++++++++ ...´ 11 个神级 AI å¼€æºå¹³æ›¿ï¼ŒGitHub æ€ç–¯äº†ã€‚.md | 0 2 files changed, 434 insertions(+) create mode 100644 openclaw/yunhan/infrastructure/Prometheus-Grafana-NodeExporter-MacMini.md create mode 100644 raw/2025 å¹´ 11 个神级 AI å¼€æºå¹³æ›¿ï¼ŒGitHub æ€ç–¯äº†ã€‚.md diff --git a/openclaw/yunhan/infrastructure/Prometheus-Grafana-NodeExporter-MacMini.md b/openclaw/yunhan/infrastructure/Prometheus-Grafana-NodeExporter-MacMini.md new file mode 100644 index 00000000..c6998515 --- /dev/null +++ b/openclaw/yunhan/infrastructure/Prometheus-Grafana-NodeExporter-MacMini.md @@ -0,0 +1,434 @@ +# Prometheus + Grafana + Node Exporter 监控部署方案 + +> 部署日期:2026-04-15 +> 架构:Ubuntu2 (Prometheus + Grafana) + MacMini M4 (Node Exporter 原生安装) + +--- + +## 整体架构 + +``` +┌─────────────────────────────────────────────────────────────────┠+│ 本地网络 (LAN) │ +│ │ +│ ┌──────────────┠┌──────────────────┠│ +│ │ MacMini │ │ Ubuntu2 │ │ +│ │ M4 Chip │◄───── æŠ“å– â”€â”€â”€â”€â”€â”€â”€â–º │ (Prometheus │ │ +│ │ │ 192.168.3.189 │ + Grafana) │ │ +│ │ Node Exp. │ :9100 │ 192.168.3.45 │ │ +│ │ (原生) │ │ │ │ +│ │ │ │ :9090 Prometheus│ │ +│ │ │ │ :3000 Grafana │ │ +│ └──────────────┘ └──────────────────┘ │ +│ │ +│ └──► æµè§ˆå™¨è®¿é—® Dashboard ───► │ +└─────────────────────────────────────────────────────────────────┘ +``` + +--- + +## 组件说明 + +| 组件 | æœåС噍 | IP | ç«¯å£ | 版本 | +|------|--------|-----|------|------| +| Prometheus | Ubuntu2 | 192.168.3.45 | 9090 | v2.51.0 | +| Grafana | Ubuntu2 | 192.168.3.45 | 3000 | 10.4.0 | +| node-exporter | MacMini | 192.168.3.189 | 9100 | 1.11.1 | + +--- + +## 第一部分:Ubuntu2 部署 Prometheus + Grafana + +### 1.1 创建目录结构 + +```bash +# 在 Ubuntu2 上执行 +mkdir -p ~/docker/prometheus +mkdir -p ~/docker/grafana/provisioning/datasources +mkdir -p ~/docker/grafana/provisioning/dashboards +mkdir -p ~/docker/grafana/data +``` + +### 1.2 Prometheus é…ç½® + +**文件:~/docker/prometheus/docker-compose.yml** + +```yaml +version: '3.8' + +services: + prometheus: + image: prom/prometheus:v2.51.0 + container_name: prometheus + restart: unless-stopped + network_mode: host + volumes: + - ./prometheus.yml:/etc/prometheus/prometheus.yml + - prometheus-data:/prometheus + command: + - '--config.file=/etc/prometheus/prometheus.yml' + - '--storage.tsdb.path=/prometheus' + - '--web.console.libraries=/etc/prometheus/console_libraries' + - '--web.console.templates=/etc/prometheus/consoles' + - '--web.enable-lifecycle' + extra_hosts: + - "host.docker.internal:host-gateway" + +volumes: + prometheus-data: +``` + +**文件:~/docker/prometheus/prometheus.yml** + +```yaml +global: + scrape_interval: 15s + evaluation_interval: 15s + +scrape_configs: + # Prometheus 自身监控 + - job_name: 'prometheus' + static_configs: + - targets: ['localhost:9090'] + + # MacMini node-exporter + - job_name: 'macmini' + static_configs: + - targets: ['192.168.3.189:9100'] + scrape_interval: 30s +``` + +### 1.3 Grafana é…ç½® + +**文件:~/docker/grafana/docker-compose.yml** + +```yaml +version: '3.8' + +services: + grafana: + image: grafana/grafana:10.4.0 + container_name: grafana + restart: unless-stopped + ports: + - "3000:3000" + volumes: + - ./provisioning/datasources:/etc/grafana/provisioning/datasources + - ./provisioning/dashboards:/etc/grafana/provisioning/dashboards + - ./data:/var/lib/grafana + environment: + - GF_SECURITY_ADMIN_USER=admin + - GF_SECURITY_ADMIN_PASSWORD=admin123 + - GF_USERS_ALLOW_SIGN_UP=false + extra_hosts: + - "host.docker.internal:host-gateway" +``` + +**文件:~/docker/grafana/provisioning/datasources/datasource.yml** + +```yaml +apiVersion: 1 + +datasources: + - name: Prometheus + type: prometheus + access: proxy + url: http://host.docker.internal:9090 + uid: prometheus + isDefault: true + editable: false +``` + +**文件:~/docker/grafana/provisioning/dashboards/dashboard.yml** + +```yaml +apiVersion: 1 + +providers: + - name: 'default' + orgId: 1 + folder: '' + type: file + disableDeletion: false + allowUiUpdates: true + updateIntervalSeconds: 10 + options: + path: /etc/grafana/provisioning/dashboards +``` + +### 1.4 å¯åЍæœåŠ¡ + +```bash +cd ~/docker/prometheus && docker compose up -d +cd ~/docker/grafana && docker compose up -d +``` + +### 1.5 验è¯çŠ¶æ€ + +```bash +# æ£€æŸ¥å®¹å™¨çŠ¶æ€ +docker ps + +# 检查 Prometheus targets +curl http://localhost:9090/api/v1/targets + +# éªŒè¯æŒ‡æ ‡å­˜åœ¨ +curl -s http://localhost:9090/api/v1/query?query=up +``` + +--- + +## 第二部分:MacMini 部署 Node Exporter(原生安装) + +### 2.1 é‡è¦è¯´æ˜Ž + +> **é‡è¦**:在 MacMini 上必须使用原生安装,ä¸èƒ½ç”¨ Dockerï¼ +> +> **原因**:Docker Desktop for Mac è¿è¡Œåœ¨ Linux VM 中,Docker 版的 node-exporter åªèƒ½çœ‹åˆ° VM 的资æºï¼ˆçº¦ 8GB),无法看到真实的 Mac 硬件(16GB)。 +> +> ``` +> Mac Mini M4 (16GB) ↠原生 node-exporter æ‰èƒ½çœ‹åˆ°çœŸå®žç¡¬ä»¶ +> ↓ +> Linux VM (Docker) ↠Docker node-exporter åªèƒ½çœ‹åˆ° VM èµ„æº (~8GB) +> ↓ +> Docker 容器 ↠åªèƒ½çœ‹åˆ° VM çš„èµ„æº +> ``` + +### 2.2 安装 Node Exporter + +```bash +# 使用 Homebrew 安装 +/opt/homebrew/bin/brew install node_exporter + +# 验è¯å®‰è£… +node_exporter --version +``` + +### 2.3 创建å¯åŠ¨è„šæœ¬ + +**文件:~/Library/LaunchAgents/homebrew.node_exporter.plist** + +```xml + + + + + Label + homebrew.node_exporter + ProgramArguments + + /opt/homebrew/opt/node_exporter/bin/node_exporter + --web.listen-address=:9100 + + RunAtLoad + + KeepAlive + + + +``` + +### 2.4 å¯åЍæœåŠ¡ + +```bash +# åœæ­¢å¹¶ç§»é™¤æ—§çš„ Docker 版本(如果存在) +/Applications/Docker.app/Contents/Resources/bin/docker stop node-exporter +/Applications/Docker.app/Contents/Resources/bin/docker rm node-exporter + +# 加载 launchd æœåŠ¡ +launchctl load ~/Library/LaunchAgents/homebrew.node_exporter.plist + +# å¯åЍæœåŠ¡ +launchctl start homebrew.node_exporter +``` + +### 2.5 验è¯å®‰è£… + +```bash +# 检查æœåŠ¡çŠ¶æ€ +launchctl list | grep node + +# 检查进程 +ps aux | grep node_exporter | grep -v grep + +# æ£€æŸ¥ç«¯å£ +lsof -i :9100 + +# éªŒè¯æŒ‡æ ‡ï¼ˆæœ¬åœ°ï¼‰ +curl http://localhost:9100/metrics | head + +# éªŒè¯æ€»å†…存(应该显示 16GB) +curl -s http://localhost:9100/metrics | grep total_bytes +``` + +### 2.6 管ç†å‘½ä»¤ + +```bash +# æŸ¥çœ‹çŠ¶æ€ +launchctl list | grep node + +# åœæ­¢æœåŠ¡ +launchctl unload ~/Library/LaunchAgents/homebrew.node_exporter.plist + +# é‡å¯æœåŠ¡ +launchctl unload ~/Library/LaunchAgents/homebrew.node_exporter.plist +launchctl load ~/Library/LaunchAgents/homebrew.node_exporter.plist + +# 查看日志 +cat /var/log/system.log | grep node_exporter +``` + +--- + +## 第三部分:访问和使用 + +### 3.1 è®¿é—®åœ°å€ + +| æœåŠ¡ | åœ°å€ | 用户å | å¯†ç  | +|------|------|--------|------| +| Prometheus | http://192.168.3.45:9090 | - | - | +| Grafana | http://192.168.3.45:3000 | admin | admin123 | + +### 3.2 导入 Dashboard + +**官方 Dashboard(推è)** + +1. 打开 Grafana: http://192.168.3.45:3000 +2. 点击左侧èœå• Dashboards → + New → Import +3. 输入 Dashboard ID: 1860(Node Exporter Full) +4. 选择 Prometheus æ•°æ®æº +5. 点击 Import + +**å˜é‡è®¾ç½®ï¼ˆå®˜æ–¹ Dashboard)** + +官方 Dashboard 使用å˜é‡ $node å’Œ $job,需è¦åœ¨ Grafana 中设置: + +1. 打开 Dashboard → 点击å³ä¸Šè§’ Dashboard settings(齿轮图标) +2. 选择 Variables +3. 添加/编辑å˜é‡ï¼š + - node: label_values(node_memory_total_bytes, instance) 或手动输入 192.168.3.189:9100 + - job: label_values(node_memory_total_bytes, job) 或手动输入 macmini + +--- + +## 第四部分:è¿ç»´ç®¡ç† + +### 4.1 é‡å¯æœåŠ¡ + +```bash +# Ubuntu2 - Prometheus +cd ~/docker/prometheus && docker compose restart + +# Ubuntu2 - Grafana +cd ~/docker/grafana && docker compose restart + +# MacMini - Node Exporter +launchctl unload ~/Library/LaunchAgents/homebrew.node_exporter.plist +launchctl load ~/Library/LaunchAgents/homebrew.node_exporter.plist +``` + +### 4.2 æ›´æ–° Prometheus é…ç½®åŽé‡è½½ + +```bash +# 热é‡è½½ï¼ˆæ— éœ€é‡å¯ Prometheus) +curl -X POST http://localhost:9090/-/reload +``` + +### 4.3 常è§é—®é¢˜æŽ’查 + +**问题:Grafana 显示 "Datasource not found"** +- 原因:Dashboard 中的 datasource UID 与实际ä¸åŒ¹é… +- 解决:检查 datasource.yml 中的 uid 是å¦ä¸Ž Dashboard ä¸­çš„åŒ¹é… + +**问题:Prometheus æ— æ³•æŠ“å– MacMini 指标** +- 检查网络连通性:curl http://192.168.3.189:9100/metrics +- 检查 Prometheus targets:curl http://localhost:9090/api/v1/targets + +**问题:Mac mini 内存显示 7.6GB è€Œä¸æ˜¯ 16GB** +- 原因:使用了 Docker 版 node-exporter +- 解决:改用原生安装(è§ç¬¬äºŒéƒ¨åˆ†ï¼‰ + +--- + +## 第五部分:技术备注 + +### 5.1 macOS 与 Linux 指标差异 + +Node Exporter 在 macOS 上的指标å称与 Linux 略有ä¸åŒï¼š + +| æè¿° | Linux | macOS | +|------|-------|-------| +| 总内存 | node_memory_MemTotal_bytes | node_memory_total_bytes | +| å¯ç”¨å†…å­˜ | node_memory_MemAvailable_bytes | node_memory_free_bytes | +| CPU | node_cpu_seconds_total | node_cpu_seconds_total (相åŒ) | +| è´Ÿè½½ | node_load1 | node_load1 (相åŒ) | +| ç£ç›˜ | node_disk_* | node_disk_* (相åŒ) | +| 网络 | node_network_* | node_network_* (相åŒ) | + +### 5.2 Docker Desktop for Mac 网络说明 + +network_mode: host 在 Docker Desktop for Mac 上的行为: + +| 环境 | host 模å¼ç»‘定到 | +|------|----------------| +| Linux 宿主机 | å®¿ä¸»æœºçš„ç½‘ç»œæŽ¥å£ (正常) | +| Docker Desktop (Mac/Win) | Linux VM çš„ç½‘ç»œæŽ¥å£ (异常) | + +因此在 MacMini 上使用 Docker 版会绑定到 VM 网络,导致外部无法访问。 + +### 5.3 指标数é‡å¯¹æ¯” + +| å®‰è£…æ–¹å¼ | node_* 指标数 | 内存显示 | +|----------|--------------|----------| +| Docker 版 | ~1348 | ~7.6GB (VM) | +| 原生版 | ~1966 | 16GB (真实) | + +### 5.4 ç›‘æŽ§æ•°æ®æµå‘ + +``` +MacMini 原生 Node Exporter (:9100) + ↓ HTTP (LAN) +Ubuntu2 Prometheus (:9090) + ↓ 查询 +Grafana (:3000) ↠æµè§ˆå™¨è®¿é—® +``` + +--- + +## æ–‡ä»¶æ¸…å• + +### Ubuntu2 文件结构 +``` +~/docker/ +├── prometheus/ +│ ├── docker-compose.yml +│ └── prometheus.yml +└── grafana/ + ├── docker-compose.yml + ├── data/ + └── provisioning/ + ├── datasources/ + │ └── datasource.yml + └── dashboards/ + ├── dashboard.yml + └── node-exporter.json (å¯é€‰) +``` + +### MacMini 文件结构 +``` +~/Library/LaunchAgents/ +└── homebrew.node_exporter.plist +``` + +--- + +## 相关链接 + +- Prometheus: https://prometheus.io/ +- Grafana: https://grafana.com/ +- Node Exporter: https://prometheus.io/docs/guides/node-exporter/ +- 官方 Dashboard: https://grafana.com/grafana/dashboards/1860-node-exporter-full/ + +--- + +*æœ€åŽæ›´æ–°ï¼š2026-04-15 by 云瀚 🌊* diff --git a/raw/2025 å¹´ 11 个神级 AI å¼€æºå¹³æ›¿ï¼ŒGitHub æ€ç–¯äº†ã€‚.md b/raw/2025 å¹´ 11 个神级 AI å¼€æºå¹³æ›¿ï¼ŒGitHub æ€ç–¯äº†ã€‚.md new file mode 100644 index 00000000..e69de29b