Skip to content

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 / HalfOpen
fmt.Println(snap.ThetaT) // current adaptive threshold
fmt.Println(snap.FailureRate) // failure rate in the outcome window
fmt.Println(snap.DegradedRequests) // slow requests classified as degraded
fmt.Println(snap.IsWarmingUp) // baseline not captured yet?
FieldTypeMeaning
StateStateClosed, Open or HalfOpen
Stfloat64Current EWMA latency (ms)
Ptfloat64Current rolling percentile, P95 or P99 (ms)
Dtfloat64Degradation ratio
ThetaTfloat64Current adaptive threshold θₜ
Sbasefloat64Healthy-state EWMA baseline
Pbasefloat64Healthy-state percentile baseline
FailureRatefloat64Current failure rate in the outcome window
DegradedRequestsint64Requests classified as slow
IsWarmingUpboolTrue until the baseline is set

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())
})