How achyuthnamburi/endpoint-process_monitor- works
Purpose and runtime model
Endpoint Process Monitor is a Linux userspace monitoring system. A C++ daemon samples all processes and their network activity at a configurable interval (documented default: five seconds), appends telemetry as JSON Lines, and a separate Python process performs Isolation Forest anomaly detection and writes alerts.
Primary executable control starts in src/main.cpp; ML execution starts in ml/anomaly_detector.py. Offline model/baseline preparation is represented by ml/train.py.
C++ monitor orchestration
src/main.cpp owns the daemon loop and CLI-facing monitor modes, including collection configuration, output selection, and status/process/alert queries described in the README. It coordinates the two telemetry collectors and sends each sampling snapshot across the file-based output boundary.
Paths:
• src/main.cpp
• Makefile
Process telemetry collection
The process reader is the kernel-facing collection layer. It enumerates Linux PIDs and reads process-scoped /proc/[pid]/ information to produce CPU, resident memory, and disk-I/O metrics. This makes Linux /proc a hard platform/runtime dependency and creates expected race/error boundaries: processes may exit or become inaccessible while being sampled.
Paths:
• src/process_reader.cpp
• src/process_reader.h
Per-process network attribution
The network tracker reads socket tables such as /proc/net/tcp and /proc/net/udp, then maps socket inodes back to process-owned file descriptors. Its output contributes connection counts and remote-IP/connection visibility to each process record. This layer is distinct from process metrics because socket-table parsing and PID/socket ownership mapping have different kernel data sources and permissions.
Paths:
• src/network_tracker.cpp
• src/network_tracker.h
Telemetry contract and persistence boundary
The C++ side serializes merged process and network observations as append-oriented JSON Lines. The log is the durable, replayable contract between native collection and Python detection; it permits independent startup, failure, and scaling of the two runtimes, but means detector freshness depends on file polling/reading rather than an in-memory API.
Paths:
• src/json_writer.cpp
• src/json_writer.h
• logs/.gitkeep
ML detection sidecar
ml/anomaly_detector.py consumes the metrics log, builds the documented seven-feature vector—CPU, RSS, disk read/write, connection count, CPU delta, and memory delta—and applies scikit-learn Isolation Forest. It labels -1 predictions as anomalous and appends timestamped detections to the alerts log. Detection is unsupervised, with documented contamination of 0.05, so model behavior depends on representative baseline telemetry rather than labeled incidents.
Paths:
• ml/anomaly_detector.py
• ml/requirements.txt
Training and operational flow
Normal operation is: monitor sample → /proc collectors → JSON writer → logs/metrics.json stream → Python inference → logs/alerts.log. ml/train.py provides an offline baseline-training path over collected telemetry, separating historical training from continuous detection. The system requires a C++ toolchain for the monitor and Python with scikit-learn for the detector; it has no indicated network service, database, or web-server dependency.
Paths:
• ml/train.py
• src/main.cpp
• ml/anomaly_detector.py
Main entry points: main.cpp Monitor daemon · anomaly_detector.py Anomaly detector · process_reader.cpp Process reader · network_tracker.cpp Network tracker
Components 16
Native monitor
- Make build · Builds the C++ monitor daemon.
Makefile - Monitor daemon · Owns CLI modes, sampling loop, and output selection.
src/main.cpp - Process reader · Enumerates PIDs and reads per-process resource metrics.
src/process_reader.cpp - Process reader API
src/process_reader.h - Network tracker · Attributes sockets and connections to processes.
src/network_tracker.cpp - Network tracker API
src/network_tracker.h - JSON Lines writer · Merges observations into append-oriented telemetry.
src/json_writer.cpp - Writer API
src/json_writer.h
File contracts
- Metrics stream · Durable replayable boundary between native collection and detection.
- Alerts log
- Logs directory
logs/.gitkeep
Python ML
- Anomaly detector · Builds seven features and applies Isolation Forest inference.
ml/anomaly_detector.py - ML dependencies · Provides scikit-learn runtime dependency.
ml/requirements.txt - Offline trainer · Prepares a baseline from historical telemetry.
ml/train.py
Other components
- Process /proc data · PID state can disappear or become inaccessible during sampling.
- Socket tables
Connections 17
- Make build → Monitor daemon: builds
- Monitor daemon → Process reader: samples
- Monitor daemon → Network tracker: samples
- Process reader → Process reader API: implements
- Network tracker → Network tracker API: implements
- Process reader → Process /proc data: reads PID metrics
- Network tracker → Socket tables: reads socket state
- Monitor daemon → JSON Lines writer: sends merged snapshot
- JSON Lines writer → Writer API: implements
- JSON Lines writer → Metrics stream: appends JSON Lines
- Metrics stream → Anomaly detector: polled/read telemetry
- Anomaly detector → Alerts log: appends anomalies
- ML dependencies → Anomaly detector: provides Isolation Forest
- Metrics stream → Offline trainer: historical telemetry
- Offline trainer → Anomaly detector: baseline preparation
- Logs directory → Metrics stream: contains
- Logs directory → Alerts log: contains