# sapcc/redfish-exporter architecture

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

- Interactive diagram: https://gitdiagram.com/sapcc/redfish-exporter
- Repository: https://github.com/sapcc/redfish-exporter

## Overview

##### Project Type and Purpose
- This is a backend microservice (a Prometheus exporter) written in Python.
- Its purpose is to expose HTTP endpoints (`/health`, `/firmware`, `/performance`) that collect metrics from servers via the Redfish API and present them in Prometheus format.

##### File Structure
- Top-level files:
- `main.py` – entry point, starts the HTTP server (Prometheus client exposition or built-in HTTP handler)
- `handler.py` – routes incoming HTTP calls to the appropriate collector
- `collector.py` – defines the base collector interface and metric registration logic
- `config.yml` + `requirements.txt` + `Dockerfile` + `.github/workflows` – configuration, dependencies, CI/CD, and containerization
- `collectors/` package – four specialized collectors:
– `health_collector.py`
– `firmware_collector.py`
– `performance_collector.py`
– `certificate_collector.py`
- Infrastructure scripts: `redfish-exporter.sh`, `dockerbuild.ps1`
- CI: CodeQL and Pylint workflows

##### Extract README Insights
- Key technologies: Python 3.6+, Prometheus Python client library, Redfish API
- Configuration via `config.yml` or environment variables
- Runs standalone or in Docker, listens on port 9220 by default

##### Main Components and Interactions
a. Components
1. HTTP Server (Prometheus exposition endpoint)
2. Request Router/Handler (`handler.py`)
3. Collector Manager (`collector.py`)
4. Individual Collector Modules (`collectors/…`)
5. Redfish API Client (internal HTTP calls to target servers)
6. Config & Credentials Provider (reads `config.yml` + env vars)
7. Prometheus Metrics Registry (in-memory gauge metrics)
8. External Targets (servers with Redfish API)
9. Container & CI/CD (Docker, GitHub Actions)

b. Interactions / Data Flow
1. User or Prometheus server sends HTTP GET to `/health`, `/firmware`, or `/performance` on exporter.
2. HTTP Server forwards request to `handler.py`.
3. Handler parses query params (`target`, `job`, etc.), fetches config/credentials.
4. Handler invokes the appropriate Collector via the Collector Manager.
5. Collector module performs HTTP calls to the target server’s Redfish API.
6. Collector parses JSON, pushes gauge metrics into the Prometheus Registry.
7. Handler returns success/failure status; metrics become available at the `/metrics` endpoint.

c. Architectural Patterns and Principles
- Plugin-style collectors: each metric category is isolated in its own module
- Single-process, event-driven HTTP server
- Configuration as code + environment variable overrides
- Docker-friendly: container build and run scripts included

d. Key Technologies & Frameworks
- Python 3.6+ with `prometheus_client` library
- Redfish API over HTTPS
- Docker for containerization
- GitHub Actions for CI (CodeQL security scanning, Pylint linting)

##### Detailed Elements to Capture
- Intra-process breakdown:
- Main entry (`main.py`)
- Routing logic (`handler.py`)
- Collector base (`collector.py`) vs. specialized collectors
- Configuration flow: `config.yml` + environment variables
- Prometheus client registry & exposition endpoint
- External HTTP calls to Redfish API

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Docker Container"
        subgraph "Exporter Application"
            HTTP["HTTP Server\n(main.py)"]:::internal
            Handler["Request Router / Handler\n(handler.py)"]:::internal
            Manager["Collector Manager\n(collector.py)"]:::internal
            subgraph "Collectors"
                Health["Health Collector\n(health_collector.py)"]:::internal
                Firmware["Firmware Collector\n(firmware_collector.py)"]:::internal
                Performance["Performance Collector\n(performance_collector.py)"]:::internal
                Certificate["Certificate Collector\n(certificate_collector.py)"]:::internal
            end
            Config["Config & Credentials\n(config.yml)"]:::internal
            Registry["Prometheus Metrics Registry"]:::internal
        end
        InfraDesc["Dependencies\n(requirements.txt)"]:::infra
        DockerfileNode["Containerization\n(Dockerfile)"]:::infra
        AuxScripts["Build Scripts\n(redfish-exporter.sh,\n dockerbuild.ps1)"]:::infra
        CI1["CodeQL Scan\n(.github/workflows/codeql.yml)"]:::infra
        CI2["Pylint Lint\n(.github/workflows/pylint.yml)"]:::infra
    end

    Client["User/Prometheus\nClient"]:::external
    Redfish["Redfish-enabled\nServers"]:::external

    Client -->|"GET /health,/firmware,/performance"| HTTP
    HTTP --> Handler
    Handler --> Config
    Handler --> Manager
    Manager --> Health
    Manager --> Firmware
    Manager --> Performance
    Manager --> Certificate
    Health -->|"HTTP calls"| Redfish
    Firmware -->|"HTTP calls"| Redfish
    Performance -->|"HTTP calls"| Redfish
    Certificate -->|"HTTP calls"| Redfish
    Manager --> Registry
    Registry -->|"/metrics scrape"| Client

    click HTTP "https://github.com/sapcc/redfish-exporter/blob/main/main.py"
    click Handler "https://github.com/sapcc/redfish-exporter/blob/main/handler.py"
    click Manager "https://github.com/sapcc/redfish-exporter/blob/main/collector.py"
    click Health "https://github.com/sapcc/redfish-exporter/blob/main/collectors/health_collector.py"
    click Firmware "https://github.com/sapcc/redfish-exporter/blob/main/collectors/firmware_collector.py"
    click Performance "https://github.com/sapcc/redfish-exporter/blob/main/collectors/performance_collector.py"
    click Certificate "https://github.com/sapcc/redfish-exporter/blob/main/collectors/certificate_collector.py"
    click Config "https://github.com/sapcc/redfish-exporter/blob/main/config.yml"
    click InfraDesc "https://github.com/sapcc/redfish-exporter/blob/main/requirements.txt"
    click DockerfileNode "https://github.com/sapcc/redfish-exporter/tree/main/Dockerfile"
    click AuxScripts "https://github.com/sapcc/redfish-exporter/blob/main/redfish-exporter.sh"
    click AuxScripts "https://github.com/sapcc/redfish-exporter/blob/main/dockerbuild.ps1"
    click CI1 "https://github.com/sapcc/redfish-exporter/blob/main/.github/workflows/codeql.yml"
    click CI2 "https://github.com/sapcc/redfish-exporter/blob/main/.github/workflows/pylint.yml"

    classDef internal fill:#a8e6cf,stroke:#000
    classDef external fill:#84b6f4,stroke:#000
    classDef infra fill:#ffd3b6,stroke:#000
```
