# sflow-rt/prometheus architecture

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

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

## Overview

##### Project Type and Purpose
- This is an open‐source exporter application (plugin) for the sFlow-RT real-time analytics engine.
- Purpose: collect flow metrics via sFlow, transform them to Prometheus format, and expose them for Prometheus to scrape.

##### File Structure
- Top-level files:
- LICENSE – licensing information
- README.md – project overview and installation instructions
- api.yml – API definition (exposed endpoints, metric descriptions)
- scripts/
- export.js – main exporter script that plugs into sFlow-RT
- No separate frontend/backend folders—this is a standalone plugin module loaded by sFlow-RT.

##### README for Insights
- Describes installation: uses sflow-rt/get-app.sh to deploy the exporter
- References a blog post on flow metrics with Prometheus and Grafana → implies integration points with Prometheus and Grafana

a. Main Components
- Network Devices (routers, switches) sending sFlow data
- sFlow-RT Engine – core analytics server
- Prometheus Exporter (export.js + api.yml) loaded into sFlow-RT
- Prometheus Server – scrapes metrics
- (Optionally) Grafana – visualizes metrics
b. Relationships & Interactions
1. Network Devices → sFlow-RT Engine (streams sFlow datagrams)
2. sFlow-RT Engine processes flows and passes metrics to the Exporter script
3. Exporter script formats metrics per api.yml and exposes an HTTP endpoint
4. Prometheus Server periodically scrapes the Exporter’s HTTP endpoint
5. (Optional) Grafana pulls metrics from Prometheus for dashboards
c. Architectural Patterns & Principles
- Plugin architecture: export.js is a dynamic app loaded into sFlow-RT
- Producer-consumer flow: sFlow data producers → RT processor → metrics consumer (Prometheus)
- Configuration-driven: api.yml defines exposed metrics, enabling easy extension
d. Key Technologies & Libraries
- JavaScript plugin engine (within sFlow-RT)
- sFlow-RT REST API for defining metrics and endpoints
- Prometheus exposition format (text-based HTTP interface)
- Shell script (get-app.sh) for deployment

##### Detailed Component Breakdown (optional blocks with
- sFlow-RT Engine:
– Flow collector module
– JavaScript app loader
- Exporter App:
– Metric definitions (api.yml)
– HTTP exposition interface
- Prometheus:
– Scrape configuration
– Time series storage
- Grafana:
– Data source configuration
– Dashboards

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Global Entities
    ND["Network Devices\n(routers/switches)"]:::external
    SR["sFlow-RT Engine"]:::engine
    subgraph "Plugin: Prometheus Exporter" 
        ES["export.js\n(Main Script)"]:::plugin
        AY["api.yml\n(Metric Definitions)"]:::config
    end
    PR["Prometheus Server"]:::prometheus
    GF["Grafana"]:::grafana

    %% Sub-components of sFlow-RT
    subgraph "sFlow-RT Engine Internals"
        FC["Flow Collector Module"]:::engine
        JL["JavaScript App Loader"]:::engine
    end

    %% Connections
    ND -->|"sFlow datagrams"| FC
    FC -->|"process flows"| JL
    JL -->|"loads export.js"| ES
    ES -->|"uses definitions"| AY
    ES -->|"exposes HTTP endpoint"| PR
    PR -->|"scrapes metrics"| ES
    PR -->|"provides TSDB"| GF
    GF -->|"dashboards"| PR

    %% Click Events
    click ES "https://github.com/sflow-rt/prometheus/blob/master/scripts/export.js"
    click AY "https://github.com/sflow-rt/prometheus/blob/master/api.yml"
    click SR "https://github.com/sflow-rt/prometheus/blob/master/README.md"
    click SR "https://github.com/sflow-rt/prometheus/tree/master/LICENSE"

    %% Styles
    classDef external fill:#E8F0FE,stroke:#0366d6,color:#0366d6
    classDef engine fill:#FFF4E5,stroke:#D27D00,color:#D27D00
    classDef plugin fill:#E6FFFA,stroke:#00A36C,color:#00A36C
    classDef config fill:#FFF0F5,stroke:#C71585,color:#C71585
    classDef prometheus fill:#FCF3CF,stroke:#F1C40F,color:#B7950B
    classDef grafana fill:#F0F8FF,stroke:#1E90FF,color:#1E90FF
```
