# prometheus-community/windows_exporter architecture

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

- Interactive diagram: https://gitdiagram.com/prometheus-community/windows_exporter
- Repository: https://github.com/prometheus-community/windows_exporter

## Overview

##### Main Components
- Windows Exporter Executable – Represented in the “cmd/windows_exporter” directory. This is the entry-point of the application which sets up the service and HTTP endpoints (e.g., /metrics, /health, /debug/pprof).
- Collectors – Located under “internal/collector” (and also available via “pkg/collector” and documented in “docs/collector*.md” files). These modules are responsible for gathering the metrics from different Windows subsystems. Each collector (such as cpu, memory, diskdrive, service, etc.) is implemented in its own package.
- Configuration & Flags – The “config.yaml” at the project root and the “internal/config” package, which handle reading, parsing, and applying runtime configurations. This component governs which collectors are enabled and how they behave.
- HTTP Handler – Found in “internal/httphandler”. It exposes the endpoints (/metrics, /health, /debug/pprof) and also manages some aspects like version and health reporting.
- Logging & Utility Modules – Under “internal/log”, “internal/utils”, and “internal/mi”, these components handle logging, error handling, metrics instrumentation, and interactions with Windows APIs.
- Installer & Packaging – The “installer” directory and associated scripts (like Dockerfile, Kubernetes manifests) illustrate how the binary is packaged and deployed (as a service, container, or Kubernetes pod).

##### Relationships and Data Flow
- The “cmd/windows_exporter” component boots the application. It first loads configurations (from local config files or flags) using the configuration module.
- The configuration component then determines which collectors to initialize.
- Each active collector module (in internal/collector) collects its specific metrics (often interfacing with Windows Performance Counters, Windows APIs, or other system interfaces).
- These collected metrics flow into the HTTP handler, which formats and exposes the metrics on an HTTP endpoint (/metrics) in the Prometheus-compatible text format.
- Logging modules capture events throughout this process, ensuring that issues or state changes are properly reported.
- Deployment tools like installer scripts and Kubernetes manifests (located in “installer” and “kubernetes”) use the packaged binary to deploy the exporter as a Windows service, container, or within a Kubernetes cluster.

##### Architectural Patterns and Design Principles
- Modular Design – Each collector is a separate module in its own package, showing separation of concerns and a plug-in style architecture. This allows enabling or disabling individual collectors as needed.
- Configuration-Driven Behavior – The project supports both CLI flags and YAML configuration files, with clear precedence. This separation helps in customizing behaviour without code changes.
- Dependency Injection & Abstraction – Interfaces and abstraction layers (e.g., “internal/mi” for metric instrumentation and “internal/pdh” for performance data) encapsulate Windows API interactions, making testing and maintenance easier.
- Extensible HTTP Service – The design of the HTTP server and its endpoints (health, metrics, pprof) follows best practices for exporters in the Prometheus ecosystem.

##### Relevant Technologies and Frameworks
- Languages & Libraries – Written in Go; uses Golang’s HTTP libraries, and includes third-party libraries for configuration (YAML), logging, and integration tests.
- Windows-Specific APIs – Uses Windows API wrappers (found under “internal/headers”) and PDH (Performance Data Helper) libraries for metric collection.
- Prometheus Integration – Uses patterns common to the Prometheus ecosystem, such as providing /metrics endpoints, collector enablement flags, etc.

##### Final Assembly
- At the top, show the external Prometheus server scraping metrics from the “/metrics” HTTP endpoint of the windows_exporter.
- HTTP Server (exposing /metrics, /health, /debug/pprof)
- Configuration Loader (reading flag and YAML config)
- Collector Manager (initializing individual collector modules)
- Under the Collector Manager, list the various collectors (group them by function if useful, such as system, CPU/memory, networking, etc.) to show modularity.
- At the bottom or on the side, represent supporting modules:
- Logging & Utilities
- Windows API wrapper modules (PDH, headers)
- Installer and Packaging components (mention Docker, Kubernetes, and MSI installer)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External
    A["Prometheus Server"]:::external

    %% Windows Exporter Process Subgraph
    subgraph "Windows Exporter Process"
        direction TB
        B["Entry Point (cmd/windows_exporter)"]:::service
        subgraph "Configuration"
            direction TB
            C1["YAML Config (config.yaml)"]:::config
            C2["Config Module (internal/config)"]:::config
        end
        D["Collector Manager"]:::manager
        E["HTTP Handler (/metrics, /health, /debug/pprof)\n(internal/httphandler)"]:::http
    end

    %% Collectors Subgraph
    subgraph "Collectors"
        direction TB
        F["Collectors Modules\n(internal/collector, pkg/collector)"]:::collectors
        I["Collector Documentation\n(docs/collector*.md)"]:::collectors
    end

    %% Supporting Modules Subgraph
    subgraph "Supporting Modules"
        direction TB
        G1["Logging Module (internal/log)"]:::logging
        G2["Utility Module (internal/utils)"]:::logging
        G3["Metrics Instrumentation (internal/mi)"]:::logging
        H["Installer & Packaging\n(installer, kubernetes)"]:::installer
    end

    %% Data Flow Connections
    B --> C1
    B --> C2
    C1 --> D
    C2 --> D
    D --> F
    F --> E
    I --> F
    E -->|"scrapes"| A

    %% Supporting links
    B -->|"logs"| G1
    B --> G2
    B --> G3
    H -->|"deploys"| B

    %% Click Events
    click B "https://github.com/prometheus-community/windows_exporter/tree/master/cmd/windows_exporter"
    click C1 "https://github.com/prometheus-community/windows_exporter/blob/master/config.yaml"
    click C2 "https://github.com/prometheus-community/windows_exporter/tree/master/internal/config"
    click E "https://github.com/prometheus-community/windows_exporter/tree/master/internal/httphandler"
    click F "https://github.com/prometheus-community/windows_exporter/tree/master/internal/collector"
    click F "https://github.com/prometheus-community/windows_exporter/tree/master/pkg/collector"
    click I "https://github.com/prometheus-community/windows_exporter/blob/master/docs/collector*.md"
    click G1 "https://github.com/prometheus-community/windows_exporter/tree/master/internal/log"
    click G2 "https://github.com/prometheus-community/windows_exporter/tree/master/internal/utils"
    click G3 "https://github.com/prometheus-community/windows_exporter/tree/master/internal/mi"
    click H "https://github.com/prometheus-community/windows_exporter/tree/master/installer"

    %% Styles
    classDef external fill:#F9E79F,stroke:#D35400,stroke-width:2px;
    classDef service fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef config fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef manager fill:#FAD7A0,stroke:#CA6F1E,stroke-width:2px;
    classDef http fill:#F5B7B1,stroke:#943126,stroke-width:2px;
    classDef collectors fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef logging fill:#F9CCE1,stroke:#7D3C98,stroke-width:2px;
    classDef installer fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
```
