How sagarrajak01/smart-monitor works
1. Overall shape
- Smart Monitor is split into three runtime layers: a native C++ telemetry engine, a Node.js bridge/orchestrator, and a React dashboard.
- The main architectural boundary is between data collection/computation in the native layer and persistence/streaming/UI delivery in the JavaScript layers.
2. Telemetry source and host dependency
- The system is Linux-specific because the engine reads memory/process information from /proc procfs.
- That means the lowest layer depends directly on host kernel-exposed process metrics rather than on an external agent or API.
3. C++ engine responsibilities
- The engine/ directory contains the high-performance telemetry collector.
- Parser.* is the input boundary to procfs data, Analyzer.* is the statistical layer, and main.cpp/leaker.cpp are the executable entry points/supporting runtime pieces.
- The engine’s output is a JSON telemetry stream on stdout, which makes it a producer-only process with no direct coupling to the UI or database.
4. Statistical computation boundary
- The engine is where raw samples are turned into usable signals such as OLS slope estimation and EMA-style smoothing.
- This keeps the expensive or latency-sensitive math close to the data source, reducing work in the bridge and frontend.
5. Node.js bridge as orchestration layer
- The bridge/ folder is the central control plane.
- server.js is the top-level backend server, logic/engine.js manages the lifecycle and stream ingestion from the C++ binary, and logic/metrics.js handles derived metrics such as time-to-failure projection or similar runtime calculations.
- This layer is also where raw telemetry becomes an application-level event stream.
6. Persistence boundary
- bridge/database.js indicates a SQLite persistence layer for historical telemetry.
- The bridge sits between live samples and durable storage, so it can both replay history and retain the time-series needed for the dashboard’s hydration and longer-term analysis.
7. Real-time transport
- The bridge also exposes a Socket.IO channel to push updates to the client.
- This is the live delivery path: engine stdout → bridge parsing/metrics → Socket.IO broadcast → dashboard components.
8. React dashboard responsibilities
- The dashboard/ app is a Vite-based React UI focused on visualization rather than computation.
- services/socket.js connects to the bridge, while components like TelemetryChart, StatCard, ProcessSidebar, and LoadingScreen render the current monitoring state.
- useTheme.js and ThemeToggle.jsx show that UI state is kept local to the frontend, separate from telemetry state.
9. Client data flow
- The dashboard appears to consume both live socket events and initial/historical data from the backend so it can render immediately and then stay synchronized.
- That makes the UI a read-only consumer of backend state, not a source of telemetry.
10. Operational and deployment boundaries
- The repo is designed to run either natively or via Docker Compose.
- Dockerfile and docker-compose.yml package the full stack for a single-host deployment, while .github/workflows/ci.yml suggests automated build/validation around the three project parts.
11. Documentation and observability metadata
- Documentation/telemetry-format.md, performance.md, and the day-by-day notes capture the contract and evolution of the telemetry pipeline.
- These docs are useful architectural artifacts because they define the shape of the stream and the intended behavior of the metrics pipeline.
12. Primary architecture diagram takeaway
- The cleanest diagram is a one-way telemetry pipeline: Linux procfs feeds the C++ engine; the engine emits JSON to the Node bridge; the bridge computes/persists/broadcasts; the React dashboard renders and subscribes.
- SQLite is the durable side store, while Socket.IO is the real-time edge of the system.
Main entry points: App.jsx Dashboard app · server.js Server · engine.js Engine bridge · main.cpp Engine main
Components 19
C++ telemetry engine
Linux procfs collector and statistical processing runtime.
- Linux procfs · Kernel-exposed process and memory data read by the engine.
- Parser · Reads and normalizes raw /proc telemetry into samples.
engine/src/Parser.cpp - Analyzer · Computes derived signals such as slope and smoothing.
engine/src/Analyzer.cpp - Engine main · Executable entry point for the native telemetry process.
engine/src/main.cpp - Leaker · Supporting runtime component in the native engine package.
engine/src/leaker.cpp - JSON stream · One-way telemetry output emitted by the engine on stdout.
Node bridge
Backend orchestration, persistence, and live streaming.
- Server · Top-level Node.js server for the bridge layer.
bridge/server.js - Engine bridge · Starts the native binary and ingests its output stream.
bridge/logic/engine.js - Metrics · Builds application-level metrics and projections from telemetry.
bridge/logic/metrics.js - SQLite store · Persists historical telemetry for replay and hydration.
bridge/database.js - Socket.IO · Pushes telemetry updates to connected clients.
React dashboard
Client UI for live and historical telemetry.
- Dashboard app · Vite-based frontend shell for telemetry visualization.
dashboard/src/App.jsx - Socket client · Connects the dashboard to the backend live stream.
dashboard/src/services/socket.js - Telemetry chart · Plots live and historical telemetry signals.
dashboard/src/components/TelemetryChart.jsx - Stat cards · Shows current summary metrics and alerts.
dashboard/src/components/StatCard.jsx - Process sidebar · Displays monitored process context and selection state.
dashboard/src/components/ProcessSidebar.jsx - Theme UI · Frontend-only theme toggle and theme hook.
dashboard/src/components/ThemeToggle.jsx
Ops and docs
Deployment, packaging, and repository documentation.
- Docs · Telemetry format, performance notes, and design history.
Documentation/telemetry-format.md - Deploy stack · Docker and CI packaging for the full repository.
docker-compose.yml
Connections 24
- Linux procfs → Parser: raw samples · The engine reads Linux procfs data and parses it into structured samples.
- Parser → Analyzer: normalized telemetry · Parsed samples flow into statistical analysis.
- Analyzer → JSON stream: derived signals · Computed metrics are serialized as JSON telemetry.
- Engine main → Parser: starts · Main runtime coordinates collection and parsing.
- Engine main → Analyzer: drives · Main runtime invokes the analysis pipeline.
- Leaker → Engine main: runtime support · Support component belongs to the native engine package.
- JSON stream → Engine bridge: stdout ingest · Bridge reads the engine's JSON stream.
- Server → Engine bridge: orchestrates · Backend entrypoint delegates engine lifecycle management.
- Engine bridge → Metrics: event stream · Streamed telemetry is converted into application-level metrics.
- Engine bridge → SQLite store: persist history · Telemetry is written to the SQLite store.
- SQLite store → Server: historical data · Server can serve stored telemetry for hydration and replay.
- Engine bridge → Socket.IO: broadcast · Live updates are pushed to Socket.IO clients.
- Socket.IO → Socket client: subscribe · Dashboard listens for backend telemetry events.
- Server → Socket.IO: exposes · Server hosts the real-time transport endpoint.
- Socket client → Dashboard app: feeds UI · Client service delivers live telemetry into the React app.
- Server → Dashboard app: bootstrap data · Dashboard also consumes initial or historical backend state.
- Dashboard app → Telemetry chart: renders · Main UI renders telemetry charts.
- Dashboard app → Stat cards: renders · Main UI renders summary cards.
- Dashboard app → Process sidebar: renders · Main UI renders process context.
- Dashboard app → Theme UI: ui state · Theme controls remain local to the frontend.
- Server → Docs: contracts · Documentation defines telemetry format and expected behavior.
- Deploy stack → Engine main: packages · Docker/CI build and ship the native engine.
- Deploy stack → Server: packages · Docker/CI build and ship the bridge service.
- Deploy stack → Dashboard app: packages · Docker/CI build and ship the frontend.