# mohammadalimehri/system-monitoring-script architecture

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

- Interactive diagram: https://gitdiagram.com/mohammadalimehri/system-monitoring-script
- Repository: https://github.com/mohammadalimehri/system-monitoring-script

## Overview

##### Main Components
- Script Engine: Represent the main script (system_monitor.sh) as the core component.
- System Maintenance Tasks: Components within the script for updating and upgrading packages, cleaning APT cache, and removing unnecessary packages.
- Monitoring Tools: Indicate monitoring commands (vmstat, iostat, mpstat) as subcomponents or processes that collect system performance data.
- Logging Module: A component that handles writing the monitoring logs to files.
- Package Dependency Checker: A module to check and install required packages (like sysstat and curl).
- Telegram Reporting: A component that formats and sends system reports/logs to a Telegram bot (using provided bot token and chat ID).
- Scheduling (Cron Job): Although not part of the script package itself, include a “Scheduler” component to denote its automation through cron. This illustrates the trigger that running the script every 24 hours.

##### Representing Relationships and Interactions
- Another branch for “Cache Cleanup” processes.
- A branch that verifies and installs dependencies (sysstat, curl) if needed.
- A branch that processes sending data to the “Telegram Bot API”, possibly indicating external network communication using the provided TOKEN and CHAT_ID.

##### Architectural Patterns and Design Principles
- Although the script is monolithic in nature, highlight the separation of concerns internally by showing distinct maintenance and monitoring modules.
- Modular structure within the script (even if implemented sequentially) where each task is a clear function or a block.
- Demonstrate dependency and control flow, illustrating how the system checks prerequisites (package installations) before executing monitoring and reporting.

##### Technologies and Tools to Highlight
- Bash/Shell Scripting (system_monitor.sh)
- Linux command-line utilities (apt, vmstat, iostat, mpstat)
- Telegram Bot API (sending notifications)
- Cron (for automation/scheduling)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Trigger
    CronScheduler["Cron Scheduler"]:::external

    %% Main Script
    MainScript["system_monitor.sh"]:::script

    %% Maintenance Modules
    Updates["System Updates & Upgrades"]:::maintenance
    AptCleanup["APT Cache Cleanup"]:::maintenance
    DepChecker["Package Dependency Checker"]:::maintenance

    %% Monitoring and Logging Modules
    PerfMon["Performance Monitoring"]:::monitoring
    vmstat["vmstat"]:::monitoring
    iostat["iostat"]:::monitoring
    mpstat["mpstat"]:::monitoring
    Logging["Logging Module"]:::logging

    %% Reporting Module
    TelegramReport["Telegram Report Sender"]:::external

    %% Connections
    CronScheduler -->|"triggers"| MainScript
    MainScript -->|"executes"| Updates
    MainScript -->|"executes"| AptCleanup
    MainScript -->|"checksPrerequisites"| DepChecker
    MainScript -->|"executes"| PerfMon
    MainScript -->|"formatsSendsReport"| TelegramReport

    PerfMon -->|"runs"| vmstat
    PerfMon -->|"runs"| iostat
    PerfMon -->|"runs"| mpstat
    PerfMon -->|"sendsLogs"| Logging
    Logging -->|"sendsDataTo"| TelegramReport

    %% Styling Classes
    classDef script fill:#add8e6,stroke:#00008b,stroke-width:2px;
    classDef maintenance fill:#f08080,stroke:#c05050,stroke-width:2px;
    classDef monitoring fill:#90ee90,stroke:#228b22,stroke-width:2px;
    classDef logging fill:#ffffe0,stroke:#daa520,stroke-width:2px;
    classDef external fill:#d3d3d3,stroke:#696969,stroke-width:2px;

    %% Click Events
    click MainScript "https://github.com/mohammadalimehri/system-monitoring-script/blob/master/system_monitor.sh"
    click Updates "https://github.com/mohammadalimehri/system-monitoring-script/blob/master/system_monitor.sh"
    click AptCleanup "https://github.com/mohammadalimehri/system-monitoring-script/blob/master/system_monitor.sh"
    click DepChecker "https://github.com/mohammadalimehri/system-monitoring-script/blob/master/system_monitor.sh"
    click PerfMon "https://github.com/mohammadalimehri/system-monitoring-script/blob/master/system_monitor.sh"
    click vmstat "https://github.com/mohammadalimehri/system-monitoring-script/blob/master/system_monitor.sh"
    click iostat "https://github.com/mohammadalimehri/system-monitoring-script/blob/master/system_monitor.sh"
    click mpstat "https://github.com/mohammadalimehri/system-monitoring-script/blob/master/system_monitor.sh"
    click Logging "https://github.com/mohammadalimehri/system-monitoring-script/blob/master/system_monitor.sh"
    click TelegramReport "https://github.com/mohammadalimehri/system-monitoring-script/blob/master/system_monitor.sh"
    click CronScheduler "https://github.com/mohammadalimehri/system-monitoring-script/blob/master/README.md"
```
