# microsoft/sysmonforlinux architecture

> Architecture diagram of the GitHub repository microsoft/sysmonforlinux, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microsoft/sysmonforlinux
- Repository: https://github.com/microsoft/sysmonforlinux

## Overview

##### Main Components
a. eBPF Kernel Programs:
- Located in directories/files such as ebpfKern (contain many C files, each handling specific events across various kernel versions) and checkEBPFsizes.
- These components are responsible for hooking into kernel events (file operations, process management, networking).
b. User-Space Components and Log Viewer:
- The sysmonLogView folder (with C/C++ files) provides the log filtering and display functionality that processes events coming from syslog or directly from the monitoring tool.
- Additional utilities such as the installer (installer.c, installer.h) and diagnostic tools (e.g., diag_script.sh, outputxml.c) manage the setup and runtime analysis.
c. Packaging and Deployment:
- The package folder contains DEBIAN and SPECS scripts to build either DEB or RPM packages, ensuring proper installation of Sysmon and associated man pages.
- Docker-related files in the .container directory suggest containerized builds or testing environments.
d. Documentation & Testing:
- The doc directory contains guides and example eBPF programs, which help understand how the system works and how to integrate or extend functionality.
- Testing-related directories (perftest, test) support performance benchmarking and verification of system behavior.
e. CI/CD Pipelines:
- The .github and azure-pipelines.yml files hold configuration and workflow setups for continuous integration, ensuring builds and tests are automated.

##### Relationships and Data Flow
a. Data Capture:
- The eBPF programs (in ebpfKern) attach themselves to various kernel tracepoints or system events.
- Once an event (like process creation, file access, network connectivity) occurs, these programs capture the data in real time.
b. Event Delivery and Processing:
- Captured data is then conveyed either directly (in some cases via raw log output) or piped into syslog and further processed by user-space components.
- The main Sysmon process (which is built, installed, and managed via packaging scripts and installer code) links the kernel-collected data with user-space applications.
c. Log Viewing:
- SysmonLogView acts as a user-facing component that filters, formats, and displays the log events.
- This component may interact with configuration files to determine filtering rules.

##### Architectural Patterns and Technologies
a. Separation of Concerns:
- The architecture separates kernel-level event capture (via specialized eBPF programs) from user-space processing and log display.
b. Modularity & Extensibility:
- Individual C files in the ebpfKern directory indicate specialized modules for different types of events, which can be independently updated or extended.
c. Containerization & CI Support:
- Docker-based files (.container) and GitHub workflows (.github) aid in ensuring the build, test, and deployment environments are consistent.
d. Build System:
- The project uses CMake (CMakeLists.txt) for building the project, ensuring compatibility and ease of compiling across environments.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Kernel Layer
    subgraph "Kernel Layer"
        A["eBPF Kernel Programs"]:::kernel
        B["Event Size Checker"]:::kernel
    end

    %% User-Space Layer
    subgraph "User-Space"
        C["Installer/Daemon"]:::user
        D["Log Viewer"]:::user
    end

    %% Deployment & DevOps
    subgraph "Deployment & DevOps"
        E["Packaging & Deployment"]:::deployment
        F["CI/CD Pipelines"]:::deployment
        G["Containerization"]:::deployment
        H["Build System"]:::deployment
    end

    %% Support Layer
    subgraph "Support"
        I["Documentation"]:::support
        J["Testing & Benchmarking"]:::support
    end

    %% Relationships
    A -->|"sends_events"| C
    C -->|"processes_events"| D
    E -->|"installs_daemon"| C
    F -->|"automates_builds"| E
    H -->|"build_config"| E
    G -->|"container_builds"| E

    %% Click Events
    click A "https://github.com/microsoft/sysmonforlinux/tree/main/ebpfKern/"
    click B "https://github.com/microsoft/sysmonforlinux/blob/main/checkEBPFsizes/checkEBPFsizes.c"
    click C "https://github.com/microsoft/sysmonforlinux/blob/main/installer.c"
    click D "https://github.com/microsoft/sysmonforlinux/tree/main/sysmonLogView/"
    click E "https://github.com/microsoft/sysmonforlinux/tree/main/package/"
    click F "https://github.com/microsoft/sysmonforlinux/tree/main/.github/"
    click G "https://github.com/microsoft/sysmonforlinux/tree/main/.container/"
    click H "https://github.com/microsoft/sysmonforlinux/blob/main/CMakeLists.txt"
    click I "https://github.com/microsoft/sysmonforlinux/tree/main/doc/"
    click J "https://github.com/microsoft/sysmonforlinux/tree/main/perftest/"

    %% Styles
    classDef kernel fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef user fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef deployment fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef support fill:#ffffcc,stroke:#333,stroke-width:2px;
```
