# achyuthnamburi/endpoint-process_monitor- architecture

> Architecture diagram of the GitHub repository achyuthnamburi/endpoint-process_monitor-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/achyuthnamburi/endpoint-process_monitor-
- Repository: https://github.com/achyuthnamburi/endpoint-process_monitor-

## Overview

#### 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: [`src/main.cpp`](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/main.cpp) (Monitor daemon), [`ml/anomaly_detector.py`](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/ml/anomaly_detector.py) (Anomaly detector), [`src/process_reader.cpp`](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/process_reader.cpp) (Process reader), [`src/network_tracker.cpp`](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/network_tracker.cpp) (Network tracker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_native["Native monitor"]
  node_build["Make build"]
  node_monitor["Monitor daemon<br/>C++ executable<br/>[main.cpp]"]
  node_process_reader["Process reader<br/>collector<br/>[process_reader.cpp]"]
  node_process_api["Process reader API<br/>C++ header<br/>[process_reader.h]"]
  node_network_tracker["Network tracker<br/>collector"]
  node_network_api["Network tracker API<br/>C++ header<br/>[network_tracker.h]"]
  node_json_writer["JSON Lines writer<br/>serializer<br/>[json_writer.cpp]"]
  node_writer_api["Writer API<br/>C++ header<br/>[json_writer.h]"]
end

subgraph group_storage["File contracts"]
  node_metrics_log["Metrics stream<br/>JSON Lines log"]
  node_alerts_log["Alerts log<br/>append log"]
  node_log_dir["Logs directory<br/>storage root<br/>[.gitkeep]"]
end

subgraph group_ml["Python ML"]
  node_detector["Anomaly detector<br/>Python sidecar"]
  node_ml_requirements["ML dependencies<br/>Python requirements<br/>[requirements.txt]"]
  node_trainer["Offline trainer<br/>Python training job<br/>[train.py]"]
end

node_proc_process{{"Process /proc data<br/>Linux kernel interface"}}
node_proc_sockets{{"Socket tables<br/>Linux kernel interface"}}

node_build -->|"builds"| node_monitor
node_monitor -->|"samples"| node_process_reader
node_monitor -->|"samples"| node_network_tracker
node_process_reader -.->|"implements"| node_process_api
node_network_tracker -.->|"implements"| node_network_api
node_process_reader -->|"reads PID metrics"| node_proc_process
node_network_tracker -->|"reads socket state"| node_proc_sockets
node_monitor -->|"sends merged snapshot"| node_json_writer
node_json_writer -.->|"implements"| node_writer_api
node_json_writer -->|"appends JSON Lines"| node_metrics_log
node_metrics_log -->|"polled/read telemetry"| node_detector
node_detector -->|"appends anomalies"| node_alerts_log
node_ml_requirements -.->|"provides Isolation Forest"| node_detector
node_metrics_log -->|"historical telemetry"| node_trainer
node_trainer -.->|"baseline preparation"| node_detector
node_log_dir -.->|"contains"| node_metrics_log
node_log_dir -.->|"contains"| node_alerts_log

click node_build "https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/Makefile"
click node_monitor "https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/main.cpp"
click node_process_reader "https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/process_reader.cpp"
click node_process_api "https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/process_reader.h"
click node_network_tracker "https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/network_tracker.cpp"
click node_network_api "https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/network_tracker.h"
click node_json_writer "https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/json_writer.cpp"
click node_writer_api "https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/json_writer.h"
click node_log_dir "https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/logs/.gitkeep"
click node_detector "https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/ml/anomaly_detector.py"
click node_ml_requirements "https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/ml/requirements.txt"
click node_trainer "https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/ml/train.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_build,node_monitor,node_process_reader,node_process_api,node_network_tracker,node_network_api,node_json_writer,node_writer_api toneBlue
class node_metrics_log,node_alerts_log,node_log_dir toneAmber
class node_detector,node_ml_requirements,node_trainer toneMint
class node_proc_process,node_proc_sockets toneNeutral
```

## Components

### Native monitor

- [Make build](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/Makefile): build · Builds the C++ monitor daemon. · `Makefile`
- [Monitor daemon](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/main.cpp): C++ executable · Owns CLI modes, sampling loop, and output selection. · `src/main.cpp`
- [Process reader](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/process_reader.cpp): collector · Enumerates PIDs and reads per-process resource metrics. · `src/process_reader.cpp`
- [Process reader API](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/process_reader.h): C++ header · `src/process_reader.h`
- [Network tracker](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/network_tracker.cpp): collector · Attributes sockets and connections to processes. · `src/network_tracker.cpp`
- [Network tracker API](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/network_tracker.h): C++ header · `src/network_tracker.h`
- [JSON Lines writer](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/json_writer.cpp): serializer · Merges observations into append-oriented telemetry. · `src/json_writer.cpp`
- [Writer API](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/src/json_writer.h): C++ header · `src/json_writer.h`

### File contracts

- **Metrics stream**: JSON Lines log · Durable replayable boundary between native collection and detection.
- **Alerts log**: append log
- [Logs directory](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/logs/.gitkeep): storage root · `logs/.gitkeep`

### Python ML

- [Anomaly detector](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/ml/anomaly_detector.py): Python sidecar · Builds seven features and applies Isolation Forest inference. · `ml/anomaly_detector.py`
- [ML dependencies](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/ml/requirements.txt): Python requirements · Provides scikit-learn runtime dependency. · `ml/requirements.txt`
- [Offline trainer](https://github.com/achyuthnamburi/endpoint-process_monitor-/blob/main/ml/train.py): Python training job · Prepares a baseline from historical telemetry. · `ml/train.py`

### Other components

- **Process /proc data**: Linux kernel interface · PID state can disappear or become inaccessible during sampling.
- **Socket tables**: Linux kernel interface

## Connections

- 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
