Initial commit: Momentry Core v0.1
- Rust-based digital asset management system - Video analysis: ASR, OCR, YOLO, Face, Pose - RAG capabilities with Qdrant vector database - Multi-database support: PostgreSQL, Redis, MongoDB - Monitoring system with launchd plists - n8n workflow automation integration
This commit is contained in:
366
monitor/MONITORING.md
Normal file
366
monitor/MONITORING.md
Normal file
@@ -0,0 +1,366 @@
|
||||
# Momentry 監控系統
|
||||
|
||||
## 概述
|
||||
|
||||
Momentry 監控系統採用七層架構,涵蓋從外部服務到本地存儲的全部監控需求。
|
||||
|
||||
---
|
||||
|
||||
## 監控架構 (七層)
|
||||
|
||||
```
|
||||
Layer 1: External 監控 - DDNS、網關、互聯網連接
|
||||
Layer 2: Service 監控 - 15 個 momentry 服務
|
||||
Layer 3: Workflow 監控 - n8n Workflow 狀態
|
||||
Layer 4: Portal 監控 - WordPress 頁面與帳號
|
||||
Layer 5: Database 監控 - PostgreSQL/Redis/Qdrant/MariaDB
|
||||
Layer 6: 使用者監控 - 連線/本機使用者/異常檢測
|
||||
Layer 7: Storage 監控 - 冷溫熱分層/歸檔/檔案註冊
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 快速開始
|
||||
|
||||
### 查看監控狀態
|
||||
|
||||
```bash
|
||||
cd /Users/accusys/momentry_core_0.1/monitor
|
||||
./control/monitor_control.sh status
|
||||
```
|
||||
|
||||
### 執行全面檢查
|
||||
|
||||
```bash
|
||||
./control/monitor_control.sh check all
|
||||
```
|
||||
|
||||
### 查看特定層級
|
||||
|
||||
```bash
|
||||
./control/monitor_control.sh check service # Layer 2
|
||||
./control/monitor_control.sh check workflow # Layer 3
|
||||
./control/monitor_control.sh check portal # Layer 4
|
||||
./control/monitor_control.sh check database # Layer 5
|
||||
./control/monitor_control.sh check users # Layer 6
|
||||
./control/monitor_control.sh check storage # Layer 7
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 各層監控說明
|
||||
|
||||
### Layer 1: External 監控
|
||||
|
||||
監控外部依賴服務的可用性。
|
||||
|
||||
**監控項目**:
|
||||
- DDNS 域名解析 (momentry.ddns.net)
|
||||
- 網關連通性
|
||||
- 外部 API 連接
|
||||
|
||||
**腳本**: `service/external_monitor.sh`
|
||||
|
||||
### Layer 2: Service 監控
|
||||
|
||||
監控 15 個 momentry 服務的運行狀態。
|
||||
|
||||
**監控項目**:
|
||||
| 服務 | Port | 狀態檢查 |
|
||||
|------|------|----------|
|
||||
| PostgreSQL | 5432 | pg_isready |
|
||||
| Redis | 6379 | redis-cli ping |
|
||||
| MariaDB | 3306 | mysql ping |
|
||||
| n8n | 5678 | HTTP GET |
|
||||
| Caddy | 443 | HTTPS |
|
||||
| Gitea | 3000 | HTTP |
|
||||
| SFTPGo | 2222 | SSH |
|
||||
| Ollama | 11434 | API |
|
||||
| Qdrant | 6333 | API |
|
||||
| PHP-FPM | - | Process |
|
||||
| RustDesk | 21116 | Port |
|
||||
| MongoDB | 27017 | Mongo ping |
|
||||
|
||||
**腳本**: `service/health_check.sh`
|
||||
|
||||
### Layer 3: n8n Workflow 監控
|
||||
|
||||
監控 n8n Workflow 的執行狀態和閒置分析。
|
||||
|
||||
**監控項目**:
|
||||
- Workflow 數量與狀態
|
||||
- 執行次數與結果
|
||||
- 閒置 Workflow 識別
|
||||
- 改善建議生成
|
||||
|
||||
**閒置定義**: 無排程 AND 無 API 觸發 AND 超過 30 天未執行
|
||||
|
||||
**腳本**:
|
||||
- `workflow/n8n_workflow_monitor.sh`
|
||||
- `workflow/idle_analyzer.sh`
|
||||
|
||||
### Layer 4: WordPress Portal 監控
|
||||
|
||||
監控 WordPress 頁面可訪問性和內部帳號。
|
||||
|
||||
**監控項目**:
|
||||
- 首頁/登入頁可訪問性
|
||||
- 響應時間
|
||||
- 用戶列表與角色
|
||||
- 新增/刪除用戶
|
||||
|
||||
**腳本**:
|
||||
- `portal/page_monitor.sh`
|
||||
- `portal/account_monitor.sh`
|
||||
|
||||
### Layer 5: Database 監控
|
||||
|
||||
監控所有資料庫的健康狀態和性能指標。
|
||||
|
||||
**PostgreSQL**:
|
||||
- 表數量、行數、大小
|
||||
- 死元組、慢查詢
|
||||
- 表結構變更
|
||||
|
||||
**Redis**:
|
||||
- 連線數、內存使用
|
||||
- 命中率、操作數
|
||||
- 客戶端列表
|
||||
|
||||
**Qdrant**:
|
||||
- Collection 列表
|
||||
- Points 數、向量維度
|
||||
- 磁盤使用
|
||||
|
||||
**MariaDB**:
|
||||
- 連線數、緩衝池
|
||||
- WordPress 表結構
|
||||
|
||||
**腳本**:
|
||||
- `database/postgres_monitor.sh`
|
||||
- `database/redis_monitor.sh`
|
||||
- `database/qdrant_monitor.sh`
|
||||
- `database/mariadb_monitor.sh`
|
||||
|
||||
### Layer 6: 使用者監控
|
||||
|
||||
監控連線使用者和本機使用者的活動。
|
||||
|
||||
**連線使用者**:
|
||||
- SSH 登入與命令
|
||||
- Web 服務登入 (n8n, Gitea, WP)
|
||||
- 資料庫連線
|
||||
- SFTP 傳輸
|
||||
|
||||
**本機使用者**:
|
||||
- 系統登入
|
||||
- sudo 使用記錄
|
||||
- 服務帳戶活動
|
||||
- 異常檢測
|
||||
|
||||
**腳本**:
|
||||
- `users/session_tracker.sh`
|
||||
- `users/login_monitor.sh`
|
||||
- `users/sudo_tracker.sh`
|
||||
- `users/anomaly_detector.sh`
|
||||
|
||||
### Layer 7: Storage 架構
|
||||
|
||||
管理數據的冷溫熱分層和歸檔策略。
|
||||
|
||||
**目錄結構**:
|
||||
```
|
||||
/Users/accusys/momentry/
|
||||
├── var/ # 服務數據 (熱)
|
||||
├── etc/ # 配置 (溫)
|
||||
├── log/ # 日誌 (溫)
|
||||
├── data/ # 用戶數據
|
||||
│ ├── family/ # 家庭集群
|
||||
│ ├── work/ # 工作集群
|
||||
│ ├── wordpress/ # WP 隔離
|
||||
│ └── shared/ # 共享
|
||||
├── backup/ # 備份
|
||||
│ ├── daily/ # 每日備份 (保留 30 天)
|
||||
│ ├── weekly/ # 每週備份 (保留 12 週)
|
||||
│ ├── monthly/ # 每月備份 (保留 12 個月)
|
||||
│ └── archive/ # 歸檔 (保留 12 個月+)
|
||||
└── tmp/ # 臨時
|
||||
```
|
||||
|
||||
**分層標準**:
|
||||
| 等級 | 條件 | 存放 |
|
||||
|------|------|------|
|
||||
| 熱 | 7天內訪問 > 10次 | NVMe |
|
||||
| 溫 | 30天內訪問 > 1次 | RAID |
|
||||
| 冷 | 90天未訪問 | Object Storage |
|
||||
|
||||
**備份溫冷分層**:
|
||||
| 等級 | 保留時間 | 用途 |
|
||||
|------|---------|------|
|
||||
| daily | 7天 | 快速恢復 |
|
||||
| weekly | 30天 | 標準恢復 |
|
||||
| monthly | 365天 | 長期歸檔 |
|
||||
| archive | >365天 | 法規遵循 |
|
||||
|
||||
**腳本**:
|
||||
- `storage/storage_manager.sh` - 存儲管理
|
||||
- `storage/backup_monitor.sh` - 備份監控與溫冷轉移
|
||||
- `storage/migration_engine.sh` - 數據遷移
|
||||
- `storage/file_registry.py` - 檔案註冊
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
### 主配置
|
||||
|
||||
編輯 `config/monitor_config.yaml`:
|
||||
|
||||
```yaml
|
||||
monitoring:
|
||||
enabled: true
|
||||
check_interval: 300 # 秒
|
||||
|
||||
service:
|
||||
enabled: true
|
||||
services:
|
||||
- postgresql
|
||||
- redis
|
||||
- mariadb
|
||||
- n8n
|
||||
- caddy
|
||||
- gitea
|
||||
- sftpgo
|
||||
- ollama
|
||||
- qdrant
|
||||
- php
|
||||
- rustdesk
|
||||
|
||||
workflow:
|
||||
enabled: true
|
||||
idle_threshold_days: 30
|
||||
|
||||
portal:
|
||||
enabled: true
|
||||
|
||||
database:
|
||||
enabled: true
|
||||
|
||||
users:
|
||||
enabled: true
|
||||
|
||||
storage:
|
||||
enabled: false # 獨立實現
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 數據庫表
|
||||
|
||||
監控數據存儲在 PostgreSQL `momentry` 資料庫。
|
||||
|
||||
**主要表**:
|
||||
- `monitor_services` - 服務健康狀態
|
||||
- `monitor_workflows` - n8n Workflow 監控
|
||||
- `monitor_databases` - 資料庫指標
|
||||
- `monitor_sessions` - 使用者會話
|
||||
- `monitor_logins` - 登入歷史
|
||||
- `monitor_anomalies` - 異常檢測
|
||||
- `file_registry` - 檔案註冊
|
||||
|
||||
**創建表**: `database/schema.sql`
|
||||
|
||||
---
|
||||
|
||||
## 報警規則
|
||||
|
||||
| 層級 | 異常類型 | 等級 | 處理 |
|
||||
|------|----------|------|------|
|
||||
| Service | 服務宕機 | Critical | 記錄 |
|
||||
| Service | 響應過慢 | Warning | 記錄 |
|
||||
| Workflow | 閒置 > 30天 | Info | 記錄 |
|
||||
| Workflow | 連續失敗 | Critical | 記錄 |
|
||||
| Portal | 頁面不可訪問 | Critical | 記錄 |
|
||||
| Database | 表結構變更 | Critical | 記錄 |
|
||||
| Database | 連線過載 | Warning | 記錄 |
|
||||
| Users | 暴力破解 | Critical | 記錄 |
|
||||
| Users | 異常登入 | Warning | 記錄 |
|
||||
|
||||
**異常處理**: 僅記錄到資料庫,後續分析
|
||||
|
||||
---
|
||||
|
||||
## 維護
|
||||
|
||||
### 手動執行監控
|
||||
|
||||
```bash
|
||||
# 單次檢查
|
||||
./control/monitor_control.sh check service
|
||||
|
||||
# 持續監控 (每 5 分鐘)
|
||||
./control/monitor_control.sh monitor
|
||||
```
|
||||
|
||||
### 查看歷史
|
||||
|
||||
```bash
|
||||
# 查看服務狀態
|
||||
psql -U accusys -h localhost -d momentry -c "SELECT * FROM monitor_services ORDER BY checked_at DESC LIMIT 10;"
|
||||
|
||||
# 查看異常
|
||||
psql -U accusys -h localhost -d momentry -c "SELECT * FROM monitor_anomalies WHERE detected_at > NOW() - INTERVAL '24 hours';"
|
||||
```
|
||||
|
||||
### 清理歷史數據
|
||||
|
||||
```bash
|
||||
# 保留 30 天
|
||||
psql -U accusys -h localhost -d momentry -c "DELETE FROM monitor_services WHERE checked_at < NOW() - INTERVAL '30 days';"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 文件結構
|
||||
|
||||
```
|
||||
monitor/
|
||||
├── MONITORING.md # 本文件
|
||||
├── config/
|
||||
│ └── monitor_config.yaml # 配置文件
|
||||
├── control/
|
||||
│ └── monitor_control.sh # 控制腳本
|
||||
├── service/
|
||||
│ ├── health_check.sh # 服務健康檢查
|
||||
│ └── external_monitor.sh # 外部監控
|
||||
├── workflow/
|
||||
│ ├── n8n_workflow_monitor.sh
|
||||
│ └── idle_analyzer.sh
|
||||
├── portal/
|
||||
│ ├── page_monitor.sh
|
||||
│ └── account_monitor.sh
|
||||
├── database/
|
||||
│ ├── schema.sql # 數據庫表
|
||||
│ ├── postgres_monitor.sh
|
||||
│ ├── redis_monitor.sh
|
||||
│ ├── qdrant_monitor.sh
|
||||
│ └── mariadb_monitor.sh
|
||||
├── users/
|
||||
│ ├── session_tracker.sh
|
||||
│ ├── login_monitor.sh
|
||||
│ ├── sudo_tracker.sh
|
||||
│ └── anomaly_detector.sh
|
||||
├── storage/
|
||||
│ ├── storage_manager.sh
|
||||
│ └── migration_engine.sh
|
||||
└── docs/
|
||||
└── TROUBLESHOOTING.md
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 相關文檔
|
||||
|
||||
- [Storage 架構設計規範](./storage/STORAGE_SPEC.md)
|
||||
- [WordPress 監控](./wordpress/MONITORING.md)
|
||||
- [異常檢測規則](./users/ANOMALY_RULES.md)
|
||||
Reference in New Issue
Block a user