Snapshot
Snapshot() is the one addition to the gobreaker API. It returns a point-in-time,
read-only view of the signals fluxgo uses to decide. All fields are read under
their component locks, so it is safe to call concurrently.
snap := cb.Snapshot()fmt.Println(snap.State) // Closed / Open / HalfOpenfmt.Println(snap.ThetaT) // current adaptive thresholdfmt.Println(snap.FailureRate) // failure rate in the outcome windowfmt.Println(snap.DegradedRequests) // slow requests classified as degradedfmt.Println(snap.IsWarmingUp) // baseline not captured yet?Fields
Section titled “Fields”| Field | Type | Meaning |
|---|---|---|
State | State | Closed, Open or HalfOpen |
St | float64 | Current EWMA latency (ms) |
Pt | float64 | Current rolling percentile, P95 or P99 (ms) |
Dt | float64 | Degradation ratio |
ThetaT | float64 | Current adaptive threshold θₜ |
Sbase | float64 | Healthy-state EWMA baseline |
Pbase | float64 | Healthy-state percentile baseline |
FailureRate | float64 | Current failure rate in the outcome window |
DegradedRequests | int64 | Requests classified as slow |
IsWarmingUp | bool | True until the baseline is set |
Exposing it over HTTP
Section titled “Exposing it over HTTP”A small debug endpoint is often enough to watch the breaker from a dashboard or a terminal:
http.HandleFunc("/debug/cb", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(cb.Snapshot())})