# mkroli/docker-health-monitor architecture

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

- Interactive diagram: https://gitdiagram.com/mkroli/docker-health-monitor
- Repository: https://github.com/mkroli/docker-health-monitor

## Overview

##### Main Components
- Application Entry Point: Represented by src/main.rs, which initializes the program.
- CLI & Configuration: Depicted by the src/cli.rs, which is responsible for command-line argument parsing and reading environment variables.
- Docker Communication: Handled by modules such as src/container_health.rs, outlining the interactions with Docker (using Unix socket or HTTP).
- Health Monitoring & Restart Logic: Implemented in modules like src/monitor.rs and src/meter_attributes.rs that likely control periodic checks and decide on container restarts.
- Metrics Exporter: The src/metrics.rs module creates and serves Prometheus-exportable metrics.
- Logging: src/logging.rs for any logging/observability setup.
- Ancillary Components: Indicate the use of build automation / CI workflows (.github/workflows) and dependency management through Cargo.toml.

##### Relationships and Interactions
- How configuration is passed to the monitoring component – which in turn interacts with the Docker API (via container_health) to perform health checks.
- Flow where monitor results are fed into the Metrics Exporter, making the metrics available on the Prometheus endpoint.
- Interactions for error and diagnostic logging.
- External integrations: the connection to the Docker daemon and the endpoint to be scraped by Prometheus.

##### Use Architectural Patterns & Design Principles
- Clearly separate concerns into distinct modules/components: CLI, Monitoring, Docker Communication, Metrics, and Logging.
- Feedback loop where health checks are performed, and if issues are detected, the restart mechanism is triggered.
- Modular design, which enhances testability and maintainability.

##### Incorporate Relevant Technologies
- Rust as the primary language (project management via Cargo).
- Docker (Unix socket and HTTP interfaces).
- Prometheus for metrics scraping.
- GitHub Actions for CI/CD integration as evidenced by the .github directory.
- That the project is intended to be used within Docker environments, as suggested by the provided docker-compose example in the README.

##### Specific Elements
- Clear labels for components such as “CLI & Config Parser”, “Docker Communication”, “Health Monitor & Restart Logic”, “Prometheus Metrics Exporter”, and “Logging”.
- How the CLI feeds configuration to the main application workflow.
- How the Monitor component communicates with the Docker API to check health.
- Path of metrics data flow from the monitor to the Prometheus endpoint.
- The restart trigger back to Docker for containers failing health checks.
- Annotations to indicate using environment variables and command-line options.

- External Systems: Docker Daemon and Prometheus.
- Core Application: divided into CLI/Configuration, Monitoring (with the health check and restart logic), Metrics Exporter, and Logging.
- Build/CI/CD (optional): Represented by the GitHub workflows.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    X["Docker Daemon"]:::external
    Y["Prometheus"]:::external

    %% Core Application
    subgraph "Core Application"
        A["Application Entry Point"]:::app
        B["CLI & Config Parser"]:::internal
        C1["Health Monitor"]:::internal
        C2["Meter Attributes"]:::internal
        D["Docker Communication"]:::internal
        E["Metrics Exporter"]:::internal
        F["Logging"]:::internal
    end

    %% CI/CD & Build System
    subgraph "CI/CD & Build System"
        G["CI Workflows"]:::ci
        H1["Cargo.toml"]:::dep
        H2["Cargo.lock"]:::dep
    end

    %% Relationships within the Core Application
    A -->|"init_config"| B
    B -->|"parse_config"| C1
    C1 -->|"compute_attr"| C2
    C1 -->|"perform_checks"| D
    C1 -->|"export_metrics"| E
    %% Logging connections from key modules
    A -->|"log_event"| F
    B -->|"log_event"| F
    C1 -->|"log_event"| F
    C2 -->|"log_event"| F
    D -->|"log_event"| F
    E -->|"log_event"| F

    %% External integrations
    D -->|"docker_restart"| X
    E -->|"serve_metrics"| Y

    %% Click Events
    click A "https://github.com/mkroli/docker-health-monitor/blob/main/src/main.rs"
    click B "https://github.com/mkroli/docker-health-monitor/blob/main/src/cli.rs"
    click D "https://github.com/mkroli/docker-health-monitor/blob/main/src/container_health.rs"
    click C1 "https://github.com/mkroli/docker-health-monitor/blob/main/src/monitor.rs"
    click C2 "https://github.com/mkroli/docker-health-monitor/blob/main/src/meter_attributes.rs"
    click E "https://github.com/mkroli/docker-health-monitor/blob/main/src/metrics.rs"
    click F "https://github.com/mkroli/docker-health-monitor/blob/main/src/logging.rs"
    click G "https://github.com/mkroli/docker-health-monitor/tree/main/.github/workflows"
    click H1 "https://github.com/mkroli/docker-health-monitor/blob/main/Cargo.toml"
    click H2 "https://github.com/mkroli/docker-health-monitor/blob/main/Cargo.lock"

    %% Styles
    classDef app fill:#f4a261,stroke:#000,stroke-width:2px;
    classDef internal fill:#2a9d8f,stroke:#000,stroke-width:2px;
    classDef external fill:#e76f51,stroke:#000,stroke-width:2px;
    classDef ci fill:#264653,stroke:#000,stroke-width:2px,color:#fff;
    classDef dep fill:#e9c46a,stroke:#000,stroke-width:2px;
```
