# tsyuf/monitor architecture

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

- Interactive diagram: https://gitdiagram.com/tsyuf/monitor
- Repository: https://github.com/tsyuf/monitor

## Overview

##### Project type and purpose
- This is an open-source, CI/CD-backed monitoring tool. It uses GitHub Actions to schedule and run a Python-based monitoring script, collects ping data, generates visualizations (sparklines), and builds a static HTML dashboard with Quarto. The final site is deployed via GitHub Pages.

##### Main components
a. CI/CD Layer (GitHub Actions)
- Workflows:
- `.github/workflows/monitoring.yml` (scheduled runs)
- `.github/workflows/run-monitor.yml` (manual runs)
- `.github/workflows/quarto-render.yml` or embedded Quarto render steps
b. Configuration
- Environment variable `PING_TARGETS` defined in the workflows
- Quarto config files (`_quarto.yml`, `.github/workflows/monitor.qmd`, `index.qmd`)
c. Monitoring Engine
- Python script `scripts/monitor.py`
- Dependencies: `pandas`, `matplotlib`
d. Data Store
- Raw results: `data/results.json`
- Status summary: `docs/status.json`
- Sparkline images: `docs/sparkline_<target>.png`
e. Reporting / Presentation
- Quarto templates and QMD documents (`.github/workflows/monitor.qmd`, `index.qmd`)
- Generated HTML: `docs/monitoring_report.html`, `docs/index.html`
f. Hosting
- `docs/` folder as source for GitHub Pages (deployed from `gh-pages` or `main` branch)
- `.nojekyll` and `_config.yml` / `jekyll-gh-pages.yml` for static hosting configuration

##### Relationships and data flow
1. **Trigger** (Scheduler or Manual) →
2. **GitHub Actions** reads `PING_TARGETS` →
3. **scripts/monitor.py** pings each host →
4. Writes **data/results.json** →
5. Generates **docs/sparkline_*.png** and updates **docs/status.json** →
6. Commits JSON/images →
7. **Quarto Render** action/process reads QMD + JSON + images →
8. Outputs **docs/monitoring_report.html**, **docs/index.html** →
9. Commits and deploys **docs/** to **GitHub Pages**

##### Architectural patterns and principles
- **CI/CD Pipeline**: decoupled scheduling, monitoring, and rendering steps
- **Separation of Concerns**:
- Monitoring logic (Python) vs. Presentation (Quarto)
- Data storage (JSON + PNG) vs. static site generation
- **Immutable Outputs**: every run produces versioned JSON, images, and HTML committed back
- **Infrastructure-as-Code**: workflows and configs drive all actions

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Triggers"
        Trigger["Scheduler / Manual Trigger"]:::trigger
    end

    subgraph "CI/CD Workflows"
        MonitoringYml["monitoring.yml (schedule)"]:::workflow
        RunMonitorYml["run-monitor.yml (manual)"]:::workflow
        QuartoRenderYml["quatro-render.yml"]:::workflow
        DeployPagesYml["deploy-pages.yml"]:::workflow
        JekyllGHPagesYml["jekyll-gh-pages.yml"]:::workflow
    end

    Trigger -->|triggers| MonitoringYml
    Trigger -->|triggers| RunMonitorYml
    MonitoringYml --> MonitorPy
    RunMonitorYml --> MonitorPy
    QuartoRenderYml --> QuartoRender
    DeployPagesYml --> DocsDir
    JekyllGHPagesYml --> DocsDir

    MonitorPy["monitor.py"]:::code
    MonitorPy -->|"writes"| ResultsJson["data/results.json"]:::data
    MonitorPy -->|"writes"| StatusJson["docs/status.json"]:::data
    MonitorPy -->|"generates"| Sparklines["docs/sparkline_*.png"]:::data

    subgraph "Quarto Rendering"
        QuartoConfig["_quarto.yml"]:::config
        IndexQmd["index.qmd"]:::config
        QuartoRender["Quarto Render"]:::render
        QuartoRender --> QuartoConfig
        QuartoRender --> IndexQmd
        QuartoRender --> ResultsJson
        QuartoRender --> StatusJson
        QuartoRender --> Sparklines
    end

    QuartoRender -->|"outputs"| ReportHtml["docs/monitoring_report.html"]:::output
    QuartoRender -->|"outputs"| DocsIndexHtml["docs/index.html"]:::output

    subgraph "GitHub Pages Hosting"
        DocsDir["docs/"]:::hosting
        NoJekyll[".nojekyll"]:::hosting
        ConfigYml["_config.yml"]:::hosting
        DocsDir --> NoJekyll
        DocsDir --> ConfigYml
        DocsDir --> DocsIndexHtml
        DocsDir --> ReportHtml
    end

    DocsDir -->|"deployed to"| GitHubPages["GitHub Pages"]:::hosting

    classDef workflow fill:#ACE,stroke:#000;
    classDef code fill:#CCC,stroke:#333,stroke-width:1px;
    classDef data fill:#CFC,stroke:#090;
    classDef config fill:#FFC,stroke:#CC0;
    classDef render fill:#FFEA8B,stroke:#CC0;
    classDef output fill:#FFEBCC,stroke:#E67E22;
    classDef hosting fill:#CFF,stroke:#06F;
    classDef trigger fill:#DEF,stroke:#06F;

    click MonitoringYml "https://github.com/tsyuf/monitor/blob/main/.github/workflows/monitoring.yml"
    click RunMonitorYml "https://github.com/tsyuf/monitor/blob/main/.github/workflows/run-monitor.yml"
    click QuartoRenderYml "https://github.com/tsyuf/monitor/blob/main/.github/workflows/quatro-render.yml"
    click DeployPagesYml "https://github.com/tsyuf/monitor/blob/main/.github/workflows/deploy-pages.yml"
    click JekyllGHPagesYml "https://github.com/tsyuf/monitor/blob/main/.github/workflows/jekyll-gh-pages.yml"
    click QuartoConfig "https://github.com/tsyuf/monitor/blob/main/_quarto.yml"
    click IndexQmd "https://github.com/tsyuf/monitor/blob/main/index.qmd"
    click MonitorPy "https://github.com/tsyuf/monitor/blob/main/scripts/monitor.py"
    click DocsIndexHtml "https://github.com/tsyuf/monitor/blob/main/docs/index.html"
    click DocsDir "https://github.com/tsyuf/monitor/tree/main/docs/"
    click NoJekyll "https://github.com/tsyuf/monitor/blob/main/.nojekyll"
    click ConfigYml "https://github.com/tsyuf/monitor/blob/main/_config.yml"
```
