Skip to the content.

Docs home · Overview · Architecture · Workflows

Deep Dive: Metrics and Reporting

Overview

Measurement and presentation are split into separate packages:

User-facing descriptions of these outputs are in Dashboard & Reporting.

Responsibilities

Architecture

classDiagram
  class Collector {
    -total shardedStats
    -endpoints sync.Map
    -customMetrics map
    -history DataPoint list
    +Start()
    +RecordRequest(latency, err, meta)
    +Stats(elapsed) Stats
    +Snapshot()
    +History() DataPoint list
  }
  class shardedStats {
    -shards 32 x statsBucket
  }
  class statsBucket {
    -histogram HDR
    -successes, failures
    -min, max, sum
    -statusBuckets map
  }
  class RequestMetadata {
    +Endpoint string
    +Protocol string
    +StatusCode string
    +CustomMetrics map
  }
  class Stats {
    +EndpointStats
    +Duration
    +Endpoints map
    +ProtocolMetrics map
  }
  Collector --> shardedStats
  shardedStats --> statsBucket
  Collector ..> RequestMetadata : consumes
  Collector ..> Stats : produces

Key Files

Implementation Details

Collector

Sharding. RecordRequest picks one of 32 shards with rand.Intn and updates that shard while holding its mutex. Each shard keeps:

Status buckets are recorded only for failures whose protocol and code are both non-empty.

Endpoints. Per-endpoint stats are another shardedStats stored in a sync.Map, keyed by RequestMetadata.Endpoint.

Stats. Stats(elapsed) merges all shards into freshly allocated histograms. It does this for the total and again for every endpoint. RPS is computed only once at least 100 ms have elapsed.

Elapsed time. Once Start() has been called, Stats ignores its elapsed argument and uses time.Since(startTime) instead.

Custom metrics. Values with int, int64 or float64 type are summed. Any other type keeps the last value written.

Time series. Snapshot() appends DataPoint{timestamp, total_requests, successful_requests, errors, current_rps, p50/p95/p99_latency_ms}:

clientmetrics

ClientMetrics holds one mutex over the connect timestamp, messages and bytes sent and received, and an error count. The WebSocket, SSE and gRPC clients each hold a *clientmetrics.ClientMetrics field.

See Protocol Clients.

Text report (PrintReport)

The report has these sections, in order:

  1. --- Load Test Results ---, followed by totals, duration and Requests/sec.
  2. Latency: Min, Max, Mean, P50, P90, P95, P99.
  3. Status Buckets:, one line per bucket such as HTTP 503: 12.
  4. Thresholds, followed by Threshold Summary: X/Y passed.
  5. Endpoint breakdown, sorted by total.
  6. Protocol metrics, sorted by key.

JSON report (PrintJSONReport)

JSONReport embeds metrics.Stats, so the fields are flat. The output is pretty-printed with a two-space indent.

Key Notes
total, successes, failures, requests_per_sec  
min_latency_ms, max_latency_ms, mean_latency_ms  
p50_latency_ms, p90_latency_ms, p95_latency_ms, p99_latency_ms  
status_buckets {protocol: {code: count}}, omitted when empty
duration_ms  
endpoints {name: <same per-endpoint shape>}, omitted when empty
protocol_metrics {protocol: {key: value}}, omitted when empty
thresholds {total, passed, failed, results: [{threshold, metric, aggregate, operator, expected, actual, pass}]}, omitted when empty

Progress ticker

NewProgressReporter(collector, 1s, os.Stdout) writes \rRequests: N | Successes: N | Failures: N | RPS: x.x on each tick. It appends the top endpoint with its share and P99. It also appends the name of one protocol from ProtocolMetrics, but without any values. Start and Stop are guarded by CAS.

HTML report

GenerateHTMLReport(w, stats, history, thresholdResults, ReportMetadata{TargetURL, TestedEndpoints}) renders an html/template string constant. The template is not embedded with go:embed.

The report contains:

History is embedded as a JSON string and parsed in the browser with JSON.parse. The report does not include status buckets or protocol metrics.

Set report

setreport.Render(store.SetRun) produces a fully offline page with inline CSS and no JavaScript. It contains:

Dependencies

API/Interface

func NewCollector() *Collector
func (c *Collector) RecordRequest(latency time.Duration, err error, meta *RequestMetadata)
func (c *Collector) Stats(elapsed time.Duration) Stats
func (c *Collector) Snapshot()
func (c *Collector) History() []DataPoint
func PrintReport(w io.Writer, s metrics.Stats, th []threshold.Result)
func PrintJSONReport(w io.Writer, s metrics.Stats, th []threshold.Result) error
func GenerateHTMLReport(w io.Writer, s metrics.Stats, h []metrics.DataPoint, th []threshold.Result, m ReportMetadata) error
func Render(run store.SetRun) ([]byte, error) // setreport

Testing

Known Issues & Improvement Opportunities