# prometheus/snmp_exporter architecture

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

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

## Overview

##### Main Components
- HTTP Server / API Layer: The entry point of the exporter (see main.go). This component listens on endpoints such as /snmp (to trigger SNMP data collection) and /metrics (for Prometheus to scrape exporter metrics).
- SNMP Scraper/Collector: Found in directories like collector and scraper, these modules perform the SNMP walks, handle SNMP requests, and transform the resulting data into Prometheus-compatible metrics.
- Configuration Management: The configuration is mainly driven by the snmp.yml file. The config and generator directories indicate that the project supports dynamic configuration generation (e.g., generator/README.md, generator/mibs, generator/generator.yml) allowing users to create custom configurations based on MIBs.
- SNMP Mixins: The snmp-mixin directory holds dashboards, alerting rules, and example configurations for integrating with Prometheus. This helps users to deploy complete monitoring solutions.
- Auxiliary Tools & CI/CD: Files like Dockerfile, .circleci configurations, Makefiles, GitHub workflows, and testdata ensure that the project is built, tested, and deployed correctly. Though not central to the runtime, they reflect architectural decisions for deployment and development practices.

##### Understand the Relationships and Interactions
- At runtime, the HTTP server parses incoming requests (with query parameters such as target, module, auth). It passes these to the SNMP scraper/collector modules.
- The Collector/ Scraper interacts with SNMP devices using Go SNMP libraries (referenced in files like scraper/gosnmp.go), collects SNMP data according to the configuration read from snmp.yml, and then transforms that data into Prometheus metrics.
- The Generator tool assists in creating and testing custom SNMP configurations; it processes MIB files, as seen in generator/mibs, to output a configuration that the Exporter’ll use.
- Configuration management ensures that the proper authentication, modules, and transport details (UDP/TCP) are applied to connect with SNMP devices securely.

##### Architectural Patterns and Design Principles
- Modularity: The clear separation between the HTTP reaping layer, configuration generation, and SNMP data collection shows a modular design which enables scalability (as a single instance can handle thousands of devices).
- Declarative configuration: With separate configuration files (snmp.yml, generator/generator.yml), the system is designed to be highly configurable without code changes.
- Extensibility: The presence of generator and mixin directories implies the architecture supports extending functionality through custom modules types, dashboards, and alert rules.
- CI/CD Integration: The repository includes CI configurations (.circleci, GitHub workflows) to ensure high code quality and smooth DevOps flows.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    Prom["Prometheus"]:::external
    SNMPD["SNMP Devices"]:::external

    %% Runtime Components
    subgraph "Runtime Components"
        API["HTTP Server / API Layer"]:::runtime
        subgraph "SNMP Collector/Scraper"
            COLL["Collector"]:::runtime
            SCR["Scraper"]:::runtime
            SNMPLIB["SNMP Calls"]:::runtime
        end
    end

    %% Configuration & Generation Components
    subgraph "Configuration & Generation"
        subgraph "Configuration Management"
            ConfigYML["snmp.yml"]:::config
            ConfigMod["Config Module"]:::config
        end
        subgraph "Generator Tool"
            GenMain["Generator Main"]:::tooling
            GenConfig["Generator Config"]:::tooling
            GenYML["Generator Config File"]:::tooling
            GenMIB["MIB Files"]:::tooling
        end
    end

    %% SNMP Mixins
    MIXINS["SNMP Mixins"]:::tooling

    %% CI/CD Tools
    CI["Auxiliary Tools & CI/CD"]:::cicd

    %% Connections
    Prom -->|"scrapes_metrics9116"| API
    API -->|"triggers_collection"| COLL
    COLL --> SCR
    SCR -->|"SNMP_requests_(v2/v3,_port161)"| SNMPLIB
    SNMPLIB --> SNMPD
    COLL -->|"returns_metrics"| API

    %% Configuration Integration
    ConfigYML ---|"config_input"| COLL
    ConfigMod ---|"config_input"| COLL

    %% Generator to Configuration Management
    GenMain ---|"generates_config"| ConfigYML
    GenMain ---|"generates_config"| ConfigMod
    GenConfig ---|"updates"| ConfigYML
    GenYML ---|"defines"| ConfigMod
    GenMIB ---|"supplies_MIB_info"| ConfigYML

    %% SNMP Mixins Connection
    MIXINS ---|"dashboards&alerts"| Prom

    %% CI/CD Integration (dotted lines)
    CI -.-> API
    CI -.-> COLL
    CI -.-> ConfigYML
    CI -.-> GenMain
    CI -.-> MIXINS

    %% Styles
    classDef external fill:#fffbbe,stroke:#333,stroke-width:1.5px;
    classDef runtime fill:#bbf,stroke:#333,stroke-width:1.5px;
    classDef config fill:#bfb,stroke:#333,stroke-width:1.5px;
    classDef tooling fill:#fbb,stroke:#333,stroke-width:1.5px;
    classDef cicd fill:#fd9,stroke:#333,stroke-width:1.5px;

    %% Click Events
    click API "https://github.com/prometheus/snmp_exporter/blob/main/main.go"
    click COLL "https://github.com/prometheus/snmp_exporter/blob/main/collector/collector.go"
    click SCR "https://github.com/prometheus/snmp_exporter/blob/main/scraper/scraper.go"
    click SNMPLIB "https://github.com/prometheus/snmp_exporter/blob/main/scraper/gosnmp.go"
    click ConfigYML "https://github.com/prometheus/snmp_exporter/blob/main/snmp.yml"
    click ConfigMod "https://github.com/prometheus/snmp_exporter/blob/main/config/config.go"
    click GenMain "https://github.com/prometheus/snmp_exporter/blob/main/generator/main.go"
    click GenConfig "https://github.com/prometheus/snmp_exporter/blob/main/generator/config.go"
    click GenYML "https://github.com/prometheus/snmp_exporter/blob/main/generator/generator.yml"
    click GenMIB "https://github.com/prometheus/snmp_exporter/tree/main/generator/mibs"
    click MIXINS "https://github.com/prometheus/snmp_exporter/tree/main/snmp-mixin/"
    click CI "https://github.com/prometheus/snmp_exporter/blob/main/.circleci/config.yml"
    click CI "https://github.com/prometheus/snmp_exporter/tree/main/.github/workflows"
    click CI "https://github.com/prometheus/snmp_exporter/tree/main/Dockerfile"
    click CI "https://github.com/prometheus/snmp_exporter/tree/main/Makefile"
```
