# mgumz/mtr-exporter architecture

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

- Interactive diagram: https://gitdiagram.com/mgumz/mtr-exporter
- Repository: https://github.com/mgumz/mtr-exporter

## Overview

mtr-exporter is a scheduled network-probe exporter: CLI or jobs-file definitions become scheduled mtr executions, whose JSON reports are retained and served as Prometheus metrics. The graph includes job parsing and reload, scheduling/timeshifts, report decoding, metric exposition, and documented HTTP endpoints. Source excerpts establish the core calls; the README supplies the endpoint and Prometheus-consumer relationships. Other details of unsampled handlers and file watching are not inferred.

Main entry points: [`cmd/mtr-exporter/main.go`](https://github.com/mgumz/mtr-exporter/blob/master/cmd/mtr-exporter/main.go) (Exporter runtime), [`pkg/job/job.go`](https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/job.go) (Probe job), [`pkg/job/jobs.go`](https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/jobs.go) (Job collection), [`pkg/job/parse.go`](https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/parse.go) (Job parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and HTTP"]
  node_main["Exporter runtime<br/>[main.go]"]
  node_http["HTTP endpoints<br/>[main.go]"]
  node_health["Health page<br/>[page_health.go]"]
  node_index["Info page<br/>[page_index.go]"]
end

subgraph group_jobs["Job management"]
  node_jobfile["Jobs file<br/>[file.go]"]
  node_parser["Job parser<br/>[parse.go]"]
  node_watcher["Jobs watcher<br/>[watch_file.go]"]
  node_jobs["Job collection<br/>[jobs.go]"]
  node_job["Probe job<br/>[job.go]"]
end

subgraph group_timing["Scheduling"]
  node_scheduler["Cron scheduling<br/>[cron.go]"]
  node_timeshift["Timeshift schedules<br/>[timeshift.go]"]
  node_delay["Random delay<br/>[random_delay.go]"]
  node_deviation["Random deviation"]
end

subgraph group_probe["Probe and metrics"]
  node_mtr["mtr process<br/>[job.go]"]
  node_decode["JSON report model<br/>[mtr.go]"]
  node_collector[("Metrics collector<br/>[collector.go]")]
  node_exposition["Prometheus exposition<br/>[prometheus.go]"]
  node_hubmetrics["Hop metrics<br/>[prometheus.go]"]
end

node_operator(("Operator"))
node_prometheus(("Prometheus scraper"))

node_operator -->|"configures"| node_main
node_main -->|"builds jobs"| node_jobs
node_main -->|"starts watcher"| node_watcher
node_main -->|"registers routes"| node_http
node_http -->|"serves"| node_health
node_http -->|"serves"| node_index
node_jobfile -.->|"parsed by"| node_parser
node_watcher -->|"watches"| node_jobfile
node_watcher -.->|"reloads via"| node_parser
node_parser -->|"creates"| node_job
node_main -->|"parses file"| node_parser
node_jobs -->|"registers jobs"| node_collector
node_jobs -->|"builds schedule"| node_timeshift
node_jobs -->|"schedules jobs"| node_scheduler
node_scheduler -.->|"runs job"| node_job
node_job -->|"executes"| node_mtr
node_job -->|"decodes output"| node_decode
node_job -->|"updates report"| node_collector
node_timeshift -.->|"constructs"| node_delay
node_timeshift -->|"constructs"| node_deviation
node_http -->|"serves metrics"| node_collector
node_collector -->|"formats metrics"| node_exposition
node_exposition -->|"reads report"| node_decode
node_exposition -->|"writes hop metrics"| node_hubmetrics
node_prometheus -->|"scrapes /metrics"| node_http

click node_main "https://github.com/mgumz/mtr-exporter/blob/master/cmd/mtr-exporter/main.go"
click node_http "https://github.com/mgumz/mtr-exporter/blob/master/cmd/mtr-exporter/main.go"
click node_health "https://github.com/mgumz/mtr-exporter/blob/master/cmd/mtr-exporter/page_health.go"
click node_index "https://github.com/mgumz/mtr-exporter/blob/master/cmd/mtr-exporter/page_index.go"
click node_jobfile "https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/file.go"
click node_parser "https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/parse.go"
click node_watcher "https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/watch_file.go"
click node_jobs "https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/jobs.go"
click node_job "https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/job.go"
click node_scheduler "https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/cron.go"
click node_timeshift "https://github.com/mgumz/mtr-exporter/blob/master/pkg/timeshift/timeshift.go"
click node_delay "https://github.com/mgumz/mtr-exporter/blob/master/pkg/timeshift/random_delay.go"
click node_deviation "https://github.com/mgumz/mtr-exporter/blob/master/pkg/timeshift/random_deviation.go"
click node_mtr "https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/job.go"
click node_decode "https://github.com/mgumz/mtr-exporter/blob/master/pkg/mtr/mtr.go"
click node_collector "https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/collector.go"
click node_exposition "https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/prometheus.go"
click node_hubmetrics "https://github.com/mgumz/mtr-exporter/blob/master/pkg/mtr/prometheus.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_http,node_health,node_index toneBlue
class node_jobfile,node_parser,node_watcher,node_jobs,node_job toneAmber
class node_scheduler,node_timeshift,node_delay,node_deviation toneMint
class node_mtr,node_decode,node_collector,node_exposition,node_hubmetrics toneRose
class node_operator,node_prometheus toneIndigo
```

## Components

### CLI and HTTP

- [Exporter runtime](https://github.com/mgumz/mtr-exporter/blob/master/cmd/mtr-exporter/main.go): `cmd/mtr-exporter/main.go`
- [HTTP endpoints](https://github.com/mgumz/mtr-exporter/blob/master/cmd/mtr-exporter/main.go): `cmd/mtr-exporter/main.go`
- [Health page](https://github.com/mgumz/mtr-exporter/blob/master/cmd/mtr-exporter/page_health.go): `cmd/mtr-exporter/page_health.go`
- [Info page](https://github.com/mgumz/mtr-exporter/blob/master/cmd/mtr-exporter/page_index.go): `cmd/mtr-exporter/page_index.go`

### Job management

- [Jobs file](https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/file.go): `pkg/job/file.go`
- [Job parser](https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/parse.go): `pkg/job/parse.go`
- [Jobs watcher](https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/watch_file.go): `pkg/job/watch_file.go`
- [Job collection](https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/jobs.go): `pkg/job/jobs.go`
- [Probe job](https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/job.go): `pkg/job/job.go`

### Scheduling

- [Cron scheduling](https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/cron.go): `pkg/job/cron.go`
- [Timeshift schedules](https://github.com/mgumz/mtr-exporter/blob/master/pkg/timeshift/timeshift.go): `pkg/timeshift/timeshift.go`
- [Random delay](https://github.com/mgumz/mtr-exporter/blob/master/pkg/timeshift/random_delay.go): `pkg/timeshift/random_delay.go`
- [Random deviation](https://github.com/mgumz/mtr-exporter/blob/master/pkg/timeshift/random_deviation.go): `pkg/timeshift/random_deviation.go`

### Probe and metrics

- [mtr process](https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/job.go): `pkg/job/job.go`
- [JSON report model](https://github.com/mgumz/mtr-exporter/blob/master/pkg/mtr/mtr.go): `pkg/mtr/mtr.go`
- [Metrics collector](https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/collector.go): `pkg/job/collector.go`
- [Prometheus exposition](https://github.com/mgumz/mtr-exporter/blob/master/pkg/job/prometheus.go): `pkg/job/prometheus.go`
- [Hop metrics](https://github.com/mgumz/mtr-exporter/blob/master/pkg/mtr/prometheus.go): `pkg/mtr/prometheus.go`

### Other components

- **Operator**
- **Prometheus scraper**

## Connections

- Operator → Exporter runtime: configures (evidence: `README.md`)
- Exporter runtime → Job collection: builds jobs (evidence: `cmd/mtr-exporter/main.go`)
- Exporter runtime → Jobs watcher: starts watcher (evidence: `cmd/mtr-exporter/main.go`)
- Exporter runtime → HTTP endpoints: registers routes (evidence: `cmd/mtr-exporter/main.go`)
- HTTP endpoints → Health page: serves (evidence: `cmd/mtr-exporter/main.go`)
- HTTP endpoints → Info page: serves (evidence: `cmd/mtr-exporter/main.go`)
- Jobs file → Job parser: parsed by (evidence: `README.md`)
- Jobs watcher → Jobs file: watches (evidence: `README.md`)
- Jobs watcher → Job parser: reloads via
- Job parser → Probe job: creates (evidence: `pkg/job/parse.go`)
- Exporter runtime → Job parser: parses file (evidence: `cmd/mtr-exporter/main.go`)
- Job collection → Metrics collector: registers jobs (evidence: `pkg/job/jobs.go`)
- Job collection → Timeshift schedules: builds schedule (evidence: `pkg/job/jobs.go`)
- Job collection → Cron scheduling: schedules jobs (evidence: `pkg/job/jobs.go`)
- Cron scheduling → Probe job: runs job
- Probe job → mtr process: executes (evidence: `pkg/job/job.go`)
- Probe job → JSON report model: decodes output (evidence: `pkg/job/job.go`)
- Probe job → Metrics collector: updates report
- Timeshift schedules → Random delay: constructs
- Timeshift schedules → Random deviation: constructs (evidence: `pkg/timeshift/timeshift.go`)
- HTTP endpoints → Metrics collector: serves metrics (evidence: `cmd/mtr-exporter/main.go`)
- Metrics collector → Prometheus exposition: formats metrics (evidence: `pkg/job/prometheus.go`)
- Prometheus exposition → JSON report model: reads report (evidence: `pkg/job/prometheus.go`)
- Prometheus exposition → Hop metrics: writes hop metrics (evidence: `pkg/job/prometheus.go`)
- Prometheus scraper → HTTP endpoints: scrapes /metrics (evidence: `README.md`)
