インフラ監視再設計
全体概要、システム構成、アプリ・スクリプト関係図
1. はじめに
MeshConsole におけるインフラ監視機能は、サーバーホスト自身の状態監視に加え、軽量エージェントを通じてリモートノード(エッジサーバーなど)の稼働状態、リソース使用率、Docker コンテナ、セキュリティ状態を一元管理する中核機能です。
本設計書は、既存の監視アーキテクチャの課題を解消し、よりリアルタイムで堅牢、かつスケーラブルなインフラ監視システムを再構築するための全体指針を示します。
2. 再設計の主要目標とアプローチ
リアルタイム性
SSE + 即時実行
ポーリングによる最大10秒の遅延を解消し、SSE (Server-Sent Events) を用いてコンソールからの Docker コマンドをミリ秒単位でエージェントに配信・実行します。
堅牢性と回復性
接続障害への適応
ネットワーク一時切断時にエージェントが自動で指数バックオフ再接続を行い、コンソール側はハートビート監視で迅速にオフライン状態を検知・記録します。
データ効率化
メトリクス Pruning
SQLite データベースの肥大化を防ぐため、秒単位/分単位のデータ蓄積に対して、自動 Pruning およびロールアップ(集約)処理を導入します。
3. システム関係図 (Architecture Relationships)
MeshConsole サーバー(Console)、各ノードに常駐するエージェント(Agent)、およびデータベースや関連スクリプトの関係性とデータフローは以下の通りです。
graph TB
subgraph "MeshConsole Server (Central Station)"
FE["Frontend (Vue 3 / Vite)"]
BE["Backend API (Node.js/Express)"]
DB[("SQLite Database
(better-sqlite3)")] AC["Agent Channel Service
(SSE Connection Map)"] AS["Alerting Engine
(Rule Checker)"] end subgraph "Remote Node" AG["Node Agent (agent.js)"] SI["systeminformation"] DK["dockerode (Docker API)"] SU["selfUpdate.js (Agent Updater)"] SVC["meshconsole-agent.service
(systemd)"] end subgraph "External Integration" NC["Notification Channels
(Slack / Email / Teams / Webhook)"] end %% Data Flow FE -- "API requests / UI actions" --> BE BE -- "Read / Write" --> DB %% Agent to Server Communication AG -- "1. Post Metrics & Status
(POST /api/agent/nodes/:id/metrics)" --> BE AG -- "2. Post Docker Stats & Cache
(POST /api/agent/nodes/:id/docker)" --> BE AG -- "4. Report Exec Results
(POST /api/agent/nodes/:id/docker/results)" --> BE %% Realtime Communication AG -- "3. Open Stream for Instant Command
(GET /api/agent/nodes/:id/stream)" --> BE BE -- "Register SSE Session" --> AC AC -- "Push Command Event" --> AG %% Internal Services BE -- "Trigger Rules" --> AS AS -- "Check Metrics & Status" --> DB AS -- "Notify Alerts" --> NC %% Agent internal AG --> SI AG --> DK SVC --> AG BE -- "Trigger Agent Auto Update" --> AG AG --> SU SU -- "Restart service" --> SVC %% Styling style FE fill:#06b6d4,stroke:#374151,stroke-width:1px,color:#fff style BE fill:#3b82f6,stroke:#374151,stroke-width:1px,color:#fff style DB fill:#1f2937,stroke:#374151,stroke-width:1px,color:#fff style AG fill:#8b5cf6,stroke:#374151,stroke-width:1px,color:#fff style NC fill:#10b981,stroke:#374151,stroke-width:1px,color:#fff
(better-sqlite3)")] AC["Agent Channel Service
(SSE Connection Map)"] AS["Alerting Engine
(Rule Checker)"] end subgraph "Remote Node" AG["Node Agent (agent.js)"] SI["systeminformation"] DK["dockerode (Docker API)"] SU["selfUpdate.js (Agent Updater)"] SVC["meshconsole-agent.service
(systemd)"] end subgraph "External Integration" NC["Notification Channels
(Slack / Email / Teams / Webhook)"] end %% Data Flow FE -- "API requests / UI actions" --> BE BE -- "Read / Write" --> DB %% Agent to Server Communication AG -- "1. Post Metrics & Status
(POST /api/agent/nodes/:id/metrics)" --> BE AG -- "2. Post Docker Stats & Cache
(POST /api/agent/nodes/:id/docker)" --> BE AG -- "4. Report Exec Results
(POST /api/agent/nodes/:id/docker/results)" --> BE %% Realtime Communication AG -- "3. Open Stream for Instant Command
(GET /api/agent/nodes/:id/stream)" --> BE BE -- "Register SSE Session" --> AC AC -- "Push Command Event" --> AG %% Internal Services BE -- "Trigger Rules" --> AS AS -- "Check Metrics & Status" --> DB AS -- "Notify Alerts" --> NC %% Agent internal AG --> SI AG --> DK SVC --> AG BE -- "Trigger Agent Auto Update" --> AG AG --> SU SU -- "Restart service" --> SVC %% Styling style FE fill:#06b6d4,stroke:#374151,stroke-width:1px,color:#fff style BE fill:#3b82f6,stroke:#374151,stroke-width:1px,color:#fff style DB fill:#1f2937,stroke:#374151,stroke-width:1px,color:#fff style AG fill:#8b5cf6,stroke:#374151,stroke-width:1px,color:#fff style NC fill:#10b981,stroke:#374151,stroke-width:1px,color:#fff
4. 各コンポーネントの役割
| コンポーネント | 主な技術/ファイル | 再設計における役割と変更点 |
|---|---|---|
| Frontend | Vue 3, Pinia, Custom API client | リアルタイムに変動するノードリソースやコンテナ状態を Vue 3 Composition API で検知。 SSE 接続状態や Docker 操作のリアルタイム進捗フィードバックを強化。 |
| Backend API | Express, SQLite, SSE |
エージェントとフロントエンドの仲介。
API キーでのエージェント認証、SSE 接続の管理(AgentChannel)、Docker コマンドのキュー制御、アラート検知エンジンの統合。
|
| Database | SQLite (better-sqlite3) | メタデータ・時系列メトリクス・Docker状態キャッシュ・コマンドログの保存。 インデックス最適化、時系列データの Pruning 処理の見直し。 |
| Node Agent | Node.js, systeminformation, dockerode | 対象サーバーのシステムリソース、Docker コンテナ、Fail2ban/SSH 等の監視データを定期収集して送信。 SSE によるコマンド即時受信、自動アップデートに対応。 |
| Scripts & systemd | Bash, systemd service |
エージェントのワンライナーインストール、サービス常駐化(meshconsole-agent.service)、自動アップデート時の自己再起動制御。
|