|
| 1 | +# SysNetMon |
| 2 | + |
| 3 | +SysNetMon is a distributed system monitor built as an infra-focused monorepo for systems and networking roles. It combines a low-level C++ TCP server, cross-platform C++ monitoring daemons, a Python Flask dashboard with Plotly, and AWS alert delivery using S3 and SNS. |
| 4 | + |
| 5 | +The native code now targets Windows, macOS, and Linux. The socket layer uses portable `select`-based TCP handling, while metric collection switches to each platform's native APIs: `/proc` on Linux, Mach and `getifaddrs` on macOS, and Win32 or IP Helper APIs on Windows. |
| 6 | + |
| 7 | +## Architecture |
| 8 | + |
| 9 | +- `cpp/server/main.cpp`: `select`-based TCP event server that accepts 10+ agent and dashboard connections on Windows, macOS, and Linux. |
| 10 | +- `cpp/client/main.cpp`: cross-platform monitoring daemon that uses native OS metric APIs. |
| 11 | +- `python/dashboard/app.py`: Flask dashboard with REST endpoints for commands, chat overlay, and alert upload actions. |
| 12 | +- `python/dashboard/services.py`: background socket bridge to the C++ server plus AWS S3/SNS publishing through Boto3. |
| 13 | +- `cpp/include/platform.hpp`: shared socket compatibility layer for Winsock and POSIX. |
| 14 | +- `cpp/include/metrics.hpp`: per-OS CPU, memory, disk, and network collectors. |
| 15 | + |
| 16 | +The wire protocol is newline-delimited JSON over raw TCP. Agents register with the server, send periodic metrics, and dashboards subscribe to live metric, chat, snapshot, and alert events. |
| 17 | + |
| 18 | +## Features |
| 19 | + |
| 20 | +- C++ server using portable sockets and `select` for multi-client handling. |
| 21 | +- Windows, macOS, and Linux metric collectors for CPU, memory, disk, and network throughput. |
| 22 | +- Server-side commands such as `/alert CPU>80%`, `/alert MEMORY>70%`, `/listalerts`, and `/clients`. |
| 23 | +- Chat overlay shared through the same socket event stream. |
| 24 | +- Plotly charts for CPU, memory, and network activity across hosts. |
| 25 | +- Automatic AWS uploads for alert events to S3 and optional SNS notification fan-out. |
| 26 | +- EC2-friendly deployment path with Docker and a simple root Makefile. |
| 27 | + |
| 28 | +## Native Build |
| 29 | + |
| 30 | +### CMake on Windows, macOS, or Linux |
| 31 | + |
| 32 | +```bash |
| 33 | +cmake -S . -B build |
| 34 | +cmake --build build --config Release |
| 35 | +``` |
| 36 | + |
| 37 | +The output binaries are: |
| 38 | + |
| 39 | +- `build/sysnetmon-server` on Linux and macOS |
| 40 | +- `build/Release/sysnetmon-server.exe` on multi-config Windows generators |
| 41 | +- `build/sysnetmon-agent` on Linux and macOS |
| 42 | +- `build/Release/sysnetmon-agent.exe` on multi-config Windows generators |
| 43 | + |
| 44 | +## Quick Start Scripts |
| 45 | + |
| 46 | +- Windows PowerShell: `./scripts/run-local.ps1` |
| 47 | +- macOS or Linux: `./scripts/run-local.sh` |
| 48 | + |
| 49 | +These scripts build native binaries, set up the dashboard Python environment, launch the server plus multiple agents, and start Flask. |
| 50 | + |
| 51 | +Stop everything with: |
| 52 | + |
| 53 | +- Windows PowerShell: `./scripts/stop-local.ps1` |
| 54 | +- macOS or Linux: `./scripts/stop-local.sh` |
| 55 | + |
| 56 | +### Makefile on Linux or macOS |
| 57 | + |
| 58 | +1. Build the native binaries: |
| 59 | + |
| 60 | +```bash |
| 61 | +make server client |
| 62 | +``` |
| 63 | + |
| 64 | +2. Start the C++ server: |
| 65 | + |
| 66 | +```bash |
| 67 | +./bin/sysnetmon-server 9090 |
| 68 | +``` |
| 69 | + |
| 70 | +3. Start one or more monitoring agents on the same machine: |
| 71 | + |
| 72 | +```bash |
| 73 | +./bin/sysnetmon-agent 127.0.0.1 9090 agent-1 3 |
| 74 | +./bin/sysnetmon-agent 127.0.0.1 9090 agent-2 3 |
| 75 | +./bin/sysnetmon-agent 127.0.0.1 9090 agent-3 3 |
| 76 | +``` |
| 77 | + |
| 78 | +To run an agent as a background daemon on Linux: |
| 79 | + |
| 80 | +```bash |
| 81 | +./bin/sysnetmon-agent 127.0.0.1 9090 edge-node-1 5 --daemon |
| 82 | +``` |
| 83 | + |
| 84 | +4. Install and launch the Flask dashboard: |
| 85 | + |
| 86 | +```bash |
| 87 | +cd python/dashboard |
| 88 | +python -m venv .venv |
| 89 | +source .venv/bin/activate |
| 90 | +pip install -r requirements.txt |
| 91 | +flask --app app run --host=0.0.0.0 --port=5000 |
| 92 | +``` |
| 93 | + |
| 94 | +5. Open `http://localhost:5000`, add a rule like `/alert CPU>10%`, and watch the alert feed and AWS status panel. |
| 95 | + |
| 96 | +## Run the Server and Agents |
| 97 | + |
| 98 | +Linux or macOS: |
| 99 | + |
| 100 | +```bash |
| 101 | +./build/sysnetmon-server 9090 |
| 102 | +./build/sysnetmon-agent 127.0.0.1 9090 agent-1 3 |
| 103 | +./build/sysnetmon-agent 127.0.0.1 9090 agent-2 3 |
| 104 | +``` |
| 105 | + |
| 106 | +Windows PowerShell: |
| 107 | + |
| 108 | +```powershell |
| 109 | +.\build\Release\sysnetmon-server.exe 9090 |
| 110 | +.\build\Release\sysnetmon-agent.exe 127.0.0.1 9090 agent-1 3 |
| 111 | +.\build\Release\sysnetmon-agent.exe 127.0.0.1 9090 agent-2 3 |
| 112 | +``` |
| 113 | + |
| 114 | +Agents still support `--daemon` on Unix-like systems. On Windows, run them as standard background processes or services. |
| 115 | + |
| 116 | +## Dashboard Run |
| 117 | + |
| 118 | +```bash |
| 119 | +cd python/dashboard |
| 120 | +python -m venv .venv |
| 121 | +pip install -r requirements.txt |
| 122 | +flask --app app run --host=0.0.0.0 --port=5000 |
| 123 | +``` |
| 124 | + |
| 125 | +Open `http://localhost:5000`, add a rule like `/alert CPU>10%`, and watch the alert feed and AWS status panel. |
| 126 | + |
| 127 | +## Docker Run |
| 128 | + |
| 129 | +```bash |
| 130 | +docker compose up --build |
| 131 | +``` |
| 132 | + |
| 133 | +This launches the C++ server on port `9090` and the dashboard on port `5000`. |
| 134 | + |
| 135 | +## CI Matrix |
| 136 | + |
| 137 | +GitHub Actions workflow `.github/workflows/ci.yml` validates the repo on: |
| 138 | + |
| 139 | +- Windows |
| 140 | +- macOS |
| 141 | +- Linux |
| 142 | + |
| 143 | +CI builds `sysnetmon-server` and `sysnetmon-agent` with CMake on each OS, and runs Flask dashboard dependency plus import checks. |
| 144 | + |
| 145 | +## AWS Configuration |
| 146 | + |
| 147 | +Set any of the following environment variables before starting the dashboard or Docker stack: |
| 148 | + |
| 149 | +- `AWS_REGION=ap-south-1` |
| 150 | +- `ALERT_S3_BUCKET=sysnetmon-alert-bucket` |
| 151 | +- `ALERT_S3_PREFIX=alerts/` |
| 152 | +- `ALERT_SNS_TOPIC_ARN=arn:aws:sns:ap-south-1:123456789012:sysnetmon-alerts` |
| 153 | + |
| 154 | +When an alert event arrives, the dashboard uploads the JSON payload to S3 and optionally publishes the same payload to SNS. |
| 155 | + |
| 156 | +## EC2 / VPC Deployment Notes |
| 157 | + |
| 158 | +1. Launch an Ubuntu EC2 instance inside your VPC. |
| 159 | +2. Open inbound security group rules for TCP `9090` from agent subnets and TCP `5000` from your admin IP. |
| 160 | +3. Install Docker or build natively with `g++` and Python 3.12. |
| 161 | +4. Run the C++ server on the EC2 host and point dashboard and clients to the EC2 private IP. |
| 162 | +5. Attach an IAM role with `s3:PutObject` and `sns:Publish` permissions if using AWS uploads. |
| 163 | + |
| 164 | +## Demo Checklist for GitHub |
| 165 | + |
| 166 | +- Show the server accepting multiple localhost agents. |
| 167 | +- Show the dashboard updating charts live. |
| 168 | +- Send `/alert CPU>10%` from the UI and trigger an alert. |
| 169 | +- Show the latest alert object in S3 or the SNS notification receipt. |
| 170 | +- Include a short demo video in the repository README or release notes. |
| 171 | + |
| 172 | +## Cross-Platform Notes |
| 173 | + |
| 174 | +- Linux uses `/proc` and `statvfs`. |
| 175 | +- macOS uses Mach host statistics, `sysctl`, `getifaddrs`, and `statvfs`. |
| 176 | +- Windows uses `GetSystemTimes`, `GlobalMemoryStatusEx`, `GetDiskFreeSpaceEx`, and `GetIfTable`. |
| 177 | +- The TCP wire protocol and Flask dashboard are unchanged across platforms. |
| 178 | + |
| 179 | +## Why This Fits Systems / Networking Roles |
| 180 | + |
| 181 | +The project demonstrates socket programming, Linux internals, multi-client event handling, cloud integration, live monitoring, and service-style deployment. That combination maps cleanly to entry-level infrastructure, networking, and system engineering expectations. |
0 commit comments