# paduartesre/psm architecture

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

- Interactive diagram: https://gitdiagram.com/paduartesre/psm
- Repository: https://github.com/paduartesre/psm

## Overview

##### Project type and purpose
- This is an observability/monitoring toolkit (PSM – Proact System Monitor) implemented in Bash/Shell scripts.
- It gathers metrics (CPU, memory, database metrics, logs, link status), imports them into a PostgreSQL database, and surfaces them in Grafana (with Apache as a likely reverse‐proxy/web server).

##### File structure
- Top level:
- install-psm.sh, create-db-psm.sql → installation and database‐creation scripts
- base/ → metric‐collection scripts (cpu_metrics.sh, so_metrics.sh, dbmetrics-get-files.sh, etc.)
- scripts/ → data‐insertion, VPN checks, memory traps, PSM‐specific insert scripts
- parser/ → parsing logic (test.txt suggests parsing or pattern files)
- results-link.sh → likely post‐processing or link generation for Grafana dashboards
- No application code in a compiled language—pure shell utilities plus SQL.

##### README for additional insights
- Installation sequence: install script, SQL to create DB, configure credentials, schedule cron jobs.
- External dependencies: PostgreSQL, Grafana, Apache, Linux environment.

a. Main components
- Monitored Nodes (Servers)
- Cron scheduler on each node
- Collection scripts (base/)
- Parsing & insertion scripts (parser/, scripts/)
- Central PostgreSQL database
- Grafana (dashboard front end) behind Apache
b. Relationships & data flow
1. Cron → invokes base/*.sh on each monitored node
2. base/*.sh → fetch raw data (e.g., logs, metrics) from local or remote sources
3. parser/*.sh or scripts/*.sh → transform/parse data into insert statements
4. scripts/insert*.sh → write metrics into PostgreSQL via DB connection
c. Architectural patterns & principles
- Modular script grouping: collection vs. insertion
- Cron‐driven, push‐based metric ingestion
- Separation of concerns: data collection, transformation, storage, visualization
d. Key technologies
- Bash/Shell scripting, cron, SSH/scp or native file read for data gathering
- PostgreSQL (metrics storage)
- SQL scripts for schema/DB setup
- Grafana dashboards (possibly served via Apache HTTPD)

##### Detail‐level recommendations
- Cron schedules or indicate “cron.d/*.cron” on the scheduler symbol
- SQL schema initialization step (install-psm.sh → create-db-psm.sql)
- External dependencies (Grafana, Apache) and their version/config relationships
- If using SSH or file-transfer to remote servers, show that edge with a “Secure channel” notation

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Scheduler Layer
    subgraph "Monitored Nodes"
        direction TB
        Cron["Cron Scheduler\n(cron.d/*.cron)"]:::scheduler
    end

    %% Collection Layer
    subgraph "Base Collectors" 
        direction TB
        CPU["CPU Metrics Collector"]:::collectors
        SO["SO Metrics Collector"]:::collectors
        DBFILES["DB Files Collector"]:::collectors
        REPLICA["Replication Server Collector"]:::collectors
        PGLOG["PostgreSQL Log Extractor"]:::collectors
        DBTRAP["DB Emissions Trap Collector"]:::collectors
        GETFILE["Generic File Fetch Utility"]:::collectors
        DBCONN["DB Connection Test"]:::collectors
    end

    %% Parsing & Insertion Layer
    subgraph "Parsing & Insertion"
        direction TB
        PARSER["Parsing Patterns (test.txt)"]:::parser
        INSERTWRAP["Generic Insert Wrapper"]:::parser
        INSERTPSM["PSM Insert Logic"]:::parser
        MEMGET["Memory Metrics Transform"]:::parser
        TRAPGET["Memory Trap Parser"]:::parser
        TRAPPSM["PSM Trap Insertion"]:::parser
        VPNCHK["VPN Status Checker"]:::parser
    end

    %% Database Layer
    subgraph "PostgreSQL Database"
        direction TB
        DB["PostgreSQL (PSM)"]:::db
    end

    %% Visualization Layer
    subgraph "Visualization"
        direction TB
        GRAFANA["Grafana Dashboard"]:::frontend
        APACHE["Apache Reverse Proxy"]:::frontend
    end

    %% Install/Setup
    subgraph "Installation & Setup"
        direction TB
        INSTALL["install-psm.sh"]:::setup
        CREATEDB["create-db-psm.sql"]:::setup
    end

    %% Dashboard Link
    LINK["Grafana Link Generator"]:::parser

    %% Connections
    Cron -->|"triggers"| CPU
    Cron --> SO
    Cron --> DBFILES
    Cron --> REPLICA
    Cron --> PGLOG
    Cron --> DBTRAP
    Cron --> GETFILE
    Cron --> DBCONN

    CPU --> PARSER
    SO --> PARSER
    DBFILES --> PARSER
    REPLICA --> PARSER
    PGLOG --> PARSER
    DBTRAP --> PARSER
    GETFILE --> PARSER
    DBCONN --> PARSER

    PARSER --> INSERTWRAP
    INSERTWRAP --> INSERTPSM
    MEMGET --> INSERTPSM
    TRAPGET --> TRAPPSM
    VPNCHK --> INSERTPSM

    INSERTPSM --> DB
    TRAPPSM --> DB

    DB --> GRAFANA
    APACHE --> GRAFANA
    GRAFANA --> LINK
    LINK --> APACHE

    INSTALL --> CREATEDB
    CREATEDB --> DB

    %% Click Events
    click INSTALL "https://github.com/paduartesre/psm/blob/master/install-psm.sh"
    click CREATEDB "https://github.com/paduartesre/psm/blob/master/create-db-psm.sql"
    click CPU "https://github.com/paduartesre/psm/blob/master/base/cpu_metrics.sh"
    click SO "https://github.com/paduartesre/psm/blob/master/base/so_metrics.sh"
    click DBFILES "https://github.com/paduartesre/psm/blob/master/base/dbmetrics-get-files.sh"
    click REPLICA "https://github.com/paduartesre/psm/blob/master/base/replicaserver-get-files.sh"
    click PGLOG "https://github.com/paduartesre/psm/blob/master/base/pg_log_extract.sh"
    click DBTRAP "https://github.com/paduartesre/psm/blob/master/base/trap-db-emissions.sh"
    click GETFILE "https://github.com/paduartesre/psm/blob/master/base/get-file.sh"
    click DBCONN "https://github.com/paduartesre/psm/blob/master/base/db_connection_test.sh"
    click PARSER "https://github.com/paduartesre/psm/blob/master/parser/test.txt"
    click INSERTWRAP "https://github.com/paduartesre/psm/blob/master/scripts/insert.sh"
    click INSERTPSM "https://github.com/paduartesre/psm/blob/master/scripts/insert-psm.sh"
    click MEMGET "https://github.com/paduartesre/psm/blob/master/scripts/memget.sh"
    click TRAPGET "https://github.com/paduartesre/psm/blob/master/scripts/trap-getmem.sh"
    click TRAPPSM "https://github.com/paduartesre/psm/blob/master/scripts/trap-psm.sh"
    click VPNCHK "https://github.com/paduartesre/psm/blob/master/scripts/checkvpn.sh"
    click LINK "https://github.com/paduartesre/psm/blob/master/results-link.sh"

    %% Styles
    classDef collectors fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef parser fill:#FFFF99,stroke:#333,stroke-width:1px
    classDef db fill:#98FB98,stroke:#333,stroke-width:1px
    classDef frontend fill:#FFA500,stroke:#333,stroke-width:1px
    classDef scheduler fill:#E6E6FA,stroke:#333,stroke-width:1px
    classDef setup fill:#D3D3D3,stroke:#333,stroke-width:1px
```
