Skip to content

Commit 8e1159d

Browse files
committed
Initial commit: cross-platform SysNetMon distributed monitor
0 parents  commit 8e1159d

22 files changed

Lines changed: 2531 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: cross-platform-ci
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
pull_request:
8+
9+
jobs:
10+
native-build:
11+
name: build-${{ matrix.os }}
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os: [ubuntu-latest, macos-latest, windows-latest]
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Configure CMake
23+
run: cmake -S . -B build
24+
25+
- name: Build Native Targets
26+
run: cmake --build build --config Release
27+
28+
- name: Validate Artifacts (Unix)
29+
if: runner.os != 'Windows'
30+
shell: bash
31+
run: |
32+
test -f build/sysnetmon-server
33+
test -f build/sysnetmon-agent
34+
35+
- name: Validate Artifacts (Windows)
36+
if: runner.os == 'Windows'
37+
shell: pwsh
38+
run: |
39+
if (!(Test-Path "build/Release/sysnetmon-server.exe") -and !(Test-Path "build/sysnetmon-server.exe")) {
40+
throw "Server artifact missing"
41+
}
42+
if (!(Test-Path "build/Release/sysnetmon-agent.exe") -and !(Test-Path "build/sysnetmon-agent.exe")) {
43+
throw "Agent artifact missing"
44+
}
45+
46+
dashboard-check:
47+
name: python-dashboard-check
48+
runs-on: ubuntu-latest
49+
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
54+
- name: Setup Python
55+
uses: actions/setup-python@v5
56+
with:
57+
python-version: "3.12"
58+
59+
- name: Install Dashboard Dependencies
60+
run: pip install -r python/dashboard/requirements.txt
61+
62+
- name: Compile Python Sources
63+
run: python -m compileall python/dashboard
64+
65+
- name: Import Flask App
66+
working-directory: python/dashboard
67+
run: python -c "from app import app; print(app.url_map)"

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
bin/
2+
__pycache__/
3+
*.pyc
4+
.venv/
5+
.env
6+
dist/
7+
build/
8+
*.o
9+
*.exe
10+
*.out
11+
build/
12+
*.pid
13+
*.log

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
project(SysNetMon VERSION 1.0.0 LANGUAGES CXX)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
set(CMAKE_CXX_EXTENSIONS OFF)
7+
8+
add_executable(sysnetmon-server cpp/server/main.cpp)
9+
target_include_directories(sysnetmon-server PRIVATE cpp/include)
10+
11+
add_executable(sysnetmon-agent cpp/client/main.cpp)
12+
target_include_directories(sysnetmon-agent PRIVATE cpp/include)
13+
14+
if(WIN32)
15+
target_link_libraries(sysnetmon-server PRIVATE ws2_32)
16+
target_link_libraries(sysnetmon-agent PRIVATE ws2_32 iphlpapi)
17+
endif()

Makefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
SHELL := /bin/sh
2+
3+
CXX ?= g++
4+
CXXFLAGS ?= -std=c++14 -O2 -Wall -Wextra -pedantic
5+
INCLUDES := -Icpp/include
6+
BIN_DIR := bin
7+
SERVER_BIN := $(BIN_DIR)/sysnetmon-server
8+
CLIENT_BIN := $(BIN_DIR)/sysnetmon-agent
9+
10+
.PHONY: all server client clean dashboard-install dashboard-run run-server run-client docker-build docker-up docker-down cmake-build
11+
12+
all: server client
13+
14+
$(BIN_DIR):
15+
mkdir -p $(BIN_DIR)
16+
17+
server: $(SERVER_BIN)
18+
19+
client: $(CLIENT_BIN)
20+
21+
$(SERVER_BIN): cpp/server/main.cpp cpp/include/common.hpp | $(BIN_DIR)
22+
$(CXX) $(CXXFLAGS) $(INCLUDES) $< -o $@
23+
24+
$(CLIENT_BIN): cpp/client/main.cpp cpp/include/common.hpp cpp/include/metrics.hpp | $(BIN_DIR)
25+
$(CXX) $(CXXFLAGS) $(INCLUDES) $< -o $@
26+
27+
dashboard-install:
28+
pip install -r python/dashboard/requirements.txt
29+
30+
dashboard-run:
31+
cd python/dashboard && flask --app app run --host=0.0.0.0 --port=5000
32+
33+
run-server: server
34+
./$(SERVER_BIN) 9090
35+
36+
run-client: client
37+
./$(CLIENT_BIN) 127.0.0.1 9090 agent-1 5
38+
39+
docker-build:
40+
docker compose build
41+
42+
docker-up:
43+
docker compose up --build
44+
45+
docker-down:
46+
docker compose down
47+
48+
cmake-build:
49+
cmake -S . -B build
50+
cmake --build build --config Release
51+
52+
clean:
53+
rm -rf $(BIN_DIR) build

README.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
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

Comments
 (0)