TsgcWSCircuitBreaker › 属性 › Metrics
只读聚合计数器,供仪表板、日志记录和告警使用。
property Metrics: TsgcCircuitBreakerMetrics read FMetrics;
—
随着调用流经断路器,内部以原子方式更新的计数器,跨所有密钥/主机名聚合。子属性包括:TotalCalls(Int64,已处理的总调用数)、TotalFailures(Int64,记录的失败次数)、TotalSuccesses(Int64,记录的成功调用次数)、TotalRejected(Int64,因断路器 Open 而被拒绝的调用次数)、CurrentOpenBreakers(Integer,当前处于 Open 状态的密钥数量;每次状态转换后刷新)和 AverageLatencyMs(Double,在 Execute/ExecuteWithResult 调用中测量的平均延迟(毫秒))。可通过 TTimer 轮询以绘制实时仪表盘,或向 Prometheus/StatsD 发送以进行告警。Metrics 为只读;使用 ResetAll 可将所有计数器清零。
// Poll Metrics from a TTimer to update a dashboard
procedure TForm1.MetricsTimer(Sender: TObject);
begin
LabelCalls.Caption := Format('Calls: %d (ok %d / fail %d / rejected %d)',
[sgcWSCircuitBreaker1.Metrics.TotalCalls,
sgcWSCircuitBreaker1.Metrics.TotalSuccesses,
sgcWSCircuitBreaker1.Metrics.TotalFailures,
sgcWSCircuitBreaker1.Metrics.TotalRejected]);
LabelOpen.Caption := Format('Open breakers: %d',
[sgcWSCircuitBreaker1.Metrics.CurrentOpenBreakers]);
LabelLatency.Caption := Format('Avg latency: %.1f ms',
[sgcWSCircuitBreaker1.Metrics.AverageLatencyMs]);
end;