# grafana/node_exporter architecture

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

- Interactive diagram: https://gitdiagram.com/grafana/node_exporter
- Repository: https://github.com/grafana/node_exporter

## Overview

##### Main Components
- Node Exporter Process: Represent the central Go binary (node_exporter.go) that configures and starts the service.
- Collector Manager: Inside the main process, show a “collector” component that loads a variety of metric collectors.
- OS/Host Interfaces: Illustrate the interactions with the host’s resources (such as /proc, /sys, and OS-specific system calls) that are used to extract metrics.
- External Integration: Show the relationship with Prometheus (or similar systems) that scrape the HTTP endpoint to ingest the metrics.
- Optional TLS/HTTPS Configuration: (As indicated in the README’s experimental TLS section) include a secure web configuration module if TLS is enabled.

##### Representing Relationships and Interactions
- That, on receiving a request, the main process iterates through the Collector Manager which in turn invokes each collector.
- That each collector communicates with its corresponding OS components (files like /proc/stat, /proc/meminfo, /sys/class/net, etc.) to gather raw data.
- That the aggregated metrics are then formatted and returned as the HTTP response to Prometheus.

##### Highlighting Architectural Patterns and Design Principles
- Pluggable Collector Architecture: Emphasize how collectors are segregated into separate source files/modules (each collector implements a specific interface).
- Modular & Extensible Design: Indicate that the service can be extended by enabling/disabling collectors through command-line flags (as shown in the README, e.g., --collector.<name> and --no-collector.<name>).
- Lightweight and Focused Service: This is a single-binary exporter optimized for low overhead with a clear separation of metric collection logic from the HTTP exposure logic.

##### Technologies, Frameworks, and Libraries
- Go Language: Note that the binary is built with Go (as shown by the files go.mod, go.sum, etc.).
- OS Interfaces: The collectors rely heavily on direct OS data sources and system calls.

##### Usage Scenarios
- That the system is self-contained and optimized for node-level monitoring rather than multi-tier service architectures.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    Prometheus["Prometheus Server"]:::external
    OSInterfaces["OS/Host Interfaces (/proc, /sys, etc.)"]:::external
    DeploymentExamples["Deployment Examples (systemd, init.d)"]:::config

    %% Node Exporter main process subgraph
    subgraph "Node Exporter"
        NodeExportProc["Node Exporter Process"]:::internal
        HTTPServer["HTTP Server (Metrics Endpoint port 9100)"]:::internal
        CollectorManager["Collector Manager"]:::internal
        TLSConfig["TLS Configuration (Experimental)"]:::config
    end

    %% Pluggable Collectors subgraph
    subgraph "Pluggable Collectors"
        CPUCollector["CPU Collector"]:::collector
        DiskstatsCollector["Diskstats Collector"]:::collector
        FilesystemCollector["Filesystem Collector"]:::collector
        NetdevCollector["Netdev Collector"]:::collector
        MemoryCollector["Memory Collector"]:::collector
    end

    %% External interactions and data flow
    Prometheus -->|"scrape"| HTTPServer
    HTTPServer -->|"invoke"| CollectorManager
    CollectorManager -->|"call"| CPUCollector
    CollectorManager -->|"call"| DiskstatsCollector
    CollectorManager -->|"call"| FilesystemCollector
    CollectorManager -->|"call"| NetdevCollector
    CollectorManager -->|"call"| MemoryCollector
    CPUCollector -->|"gather"| OSInterfaces
    DiskstatsCollector -->|"gather"| OSInterfaces
    FilesystemCollector -->|"gather"| OSInterfaces
    NetdevCollector -->|"gather"| OSInterfaces
    MemoryCollector -->|"gather"| OSInterfaces
    %% Aggregation arrow: collectors return data to HTTP server
    CollectorManager -->|"aggregate"| HTTPServer

    %% External configuration integration arrow
    DeploymentExamples -->|"deploy/configure"| NodeExportProc

    %% Click Events
    click NodeExportProc "https://github.com/grafana/node_exporter/blob/master/node_exporter.go"
    click HTTPServer "https://github.com/grafana/node_exporter/blob/master/node_exporter.go"
    click CollectorManager "https://github.com/grafana/node_exporter/blob/master/collector/collector.go"
    click CPUCollector "https://github.com/grafana/node_exporter/blob/master/collector/cpu_linux.go"
    click DiskstatsCollector "https://github.com/grafana/node_exporter/blob/master/collector/diskstats_linux.go"
    click FilesystemCollector "https://github.com/grafana/node_exporter/blob/master/collector/filesystem_linux.go"
    click NetdevCollector "https://github.com/grafana/node_exporter/blob/master/collector/netdev_linux.go"
    click MemoryCollector "https://github.com/grafana/node_exporter/blob/master/collector/memory_linux.go"
    click DeploymentExamples "https://github.com/grafana/node_exporter/tree/master/examples/"
    click TLSConfig "https://github.com/grafana/node_exporter/blob/master/tls_config_noAuth.bad.yml"

    %% Styles
    classDef internal fill:#AEDFF7,stroke:#1A5276,stroke-width:2px;
    classDef external fill:#C3F7C7,stroke:#27AE60,stroke-width:2px;
    classDef collector fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef config fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
```
