# thunderbottom/aws-exporter architecture

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

- Interactive diagram: https://gitdiagram.com/thunderbottom/aws-exporter
- Repository: https://github.com/thunderbottom/aws-exporter

## Overview

##### Project type and purpose
- This is a single-binary, open-source Prometheus exporter written in Go.
- It fetches AWS Cost Explorer and EC2 Instance data via the AWS Go SDK, exposes them on an HTTP `/metrics` endpoint, and is scraped by Prometheus.

##### File structure
- Top-level files:
- `main.go` – application entry point, starts HTTP server and registers handlers.
- `handler.go` – HTTP handler that orchestrates all configured exporters and collects metrics.
- `config/` – holds configuration model (`model.go`) and loader (`config.go`).
- `exporter/` – package containing individual exporters:
– `costexplorer.go` – implements Cost Explorer metrics
– `instance.go` – implements EC2 Instance metrics
– `utils.go` – shared helper functions
- `docker/` – `Dockerfile` for containerized execution
- `config.toml.example` – sample config for jobs, credentials, filters, tags
- CI/infra files: `.drone.yml`, `Makefile`, `.hadolint.yml`

##### Key insights from README
- Configurable jobs: each job has AWS creds, region, optional role ARN, filters, tags.
- Prometheus scrapes at `/metrics` (default port 9980).
- Extensibility: to add a new exporter, create a new file in `exporter/`, implement an `Exporter` interface, register it in `handler.go`.

##### Components
a. Main components
- AWS Services (Cost Explorer, EC2 API)
- Exporter Binary (Go application)
- Config Loader
- Exporter Manager (in handler.go)
- Individual Exporters (Cost Explorer, EC2 Instance)
- HTTP Metrics Endpoint
- Prometheus Server
- (Optional) Docker Container / Kubernetes Pod
b. Relationships and interactions
- On startup, Exporter Binary reads `config.toml`.
- For each configured job, the Exporter Manager invokes each exporter:
- Cost Explorer exporter calls AWS CE API → parses cost metrics
- Instance exporter calls EC2 DescribeInstances → collects tags and metadata
- Exporters push metrics into Prometheus client registry inside the binary.
- Prometheus periodically scrapes `http://<exporter-host>:9980/metrics`.
- (Optional) Exporter Binary runs inside a Docker container or k8s pod.
c. Architectural patterns and design principles
- Modular exporter plugins in a package, pluggable via registration in `handler.go`.
- Configuration-driven multi-job execution.
- Separation of concerns: config parsing, metric collection, HTTP serving.
d. Technologies, frameworks, libraries
- Language: Go
- AWS Go SDK (github.com/aws/aws-sdk-go)
- Prometheus Go client (github.com/prometheus/client_golang)
- Docker for containerization

##### Detailed capture of architectural elements
- How `role_arn` enables cross-account scraping.
- Metrics path `/metrics` and default port `9980`.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Configuration
    CF["config.toml.example"]:::database
    click CF "https://github.com/thunderbottom/aws-exporter/blob/master/config.toml.example"

    %% Infra Layer
    subgraph "Infrastructure" 
        DC["Dockerfile"]:::infra
        click DC "https://github.com/thunderbottom/aws-exporter/tree/master/docker/Dockerfile"
        CI1[".drone.yml"]:::infra
        click CI1 "https://github.com/thunderbottom/aws-exporter/blob/master/.drone.yml"
        CI2["Makefile"]:::infra
        click CI2 "https://github.com/thunderbottom/aws-exporter/tree/master/Makefile"
        CI3[".hadolint.yml"]:::infra
        click CI3 "https://github.com/thunderbottom/aws-exporter/blob/master/.hadolint.yml"
    end

    %% Config Layer
    subgraph "Configuration" 
        CM["Configuration Model"]:::internal
        click CM "https://github.com/thunderbottom/aws-exporter/blob/master/config/model.go"
        CL["Config Loader"]:::internal
        click CL "https://github.com/thunderbottom/aws-exporter/blob/master/config/config.go"
    end

    %% Exporter Binary Core Components
    subgraph "Exporter Binary (Go Application)" 
        MS["main.go\n(HTTP Metrics & Server)"]:::internal
        click MS "https://github.com/thunderbottom/aws-exporter/blob/master/main.go"
        HM["Exporter Manager (handler.go)"]:::internal
        click HM "https://github.com/thunderbottom/aws-exporter/blob/master/handler.go"
        subgraph "Exporters Plugin Package" 
            CE["Cost Explorer Exporter"]:::internal
            click CE "https://github.com/thunderbottom/aws-exporter/blob/master/exporter/costexplorer.go"
            IE["EC2 Instance Exporter"]:::internal
            click IE "https://github.com/thunderbottom/aws-exporter/blob/master/exporter/instance.go"
            SU["Shared Utilities"]:::internal
            click SU "https://github.com/thunderbottom/aws-exporter/blob/master/exporter/utils.go"
        end
    end

    %% External Services
    AWSCE["AWS Cost Explorer API"]:::external
    AWSEC2["AWS EC2 API"]:::external
    PROM["Prometheus Server"]:::external

    %% Data Flows
    CF -->|loads| CL
    CL -->|populates| CM
    CM -->|provides config to| MS
    MS -->|registers handler| HM
    HM -->|manages| CE
    HM -->|manages| IE
    CE -->|calls| AWSCE
    IE -->|calls| AWSEC2
    SU -->|used by| CE
    SU -->|used by| IE
    MS -->|exposes metrics at /metrics| PROM
    PROM -->|scrapes HTTP endpoint| MS

    %% Styles
    classDef internal fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef external fill:#d4edda,stroke:#333,stroke-width:1px
    classDef infra fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef database fill:#f8d7da,stroke:#333,stroke-width:1px
```
