返回 DeepSeek-Reasonix
ledger_metrics.go
根目录 / internal / turnevent / ledger_metrics.go
1 package turnevent
2
3 import "time"
4
5 type MetricsSnapshot struct {
6 RawEvents uint64
7 StreamRecords uint64
8 BytesWritten uint64
9 ReplayEvents uint64
10 ReplayBytes uint64
11 ReplayResets uint64
12 Compactions uint64
13 CompactionFailures uint64
14 BytesBeforeCompact uint64
15 BytesAfterCompact uint64
16 TornTails uint64
17 WriteFailures uint64
18 ProjectionRetries uint64
19 OpenCount uint64
20 SyncCount uint64
21 CloseCount uint64
22 AppendLatencyBuckets [5]uint64
23 ReplayLatencyBuckets [5]uint64
24 CompactLatencyBuckets [5]uint64
25 FileSizeBytes int64
26 UnconfirmedTurns int
27 }
28
29 func (l *Ledger) MetricsSnapshot() MetricsSnapshot {
30 if l == nil {
31 return MetricsSnapshot{}
32 }
33 l.mu.Lock()
34 defer l.mu.Unlock()
35 out := l.metrics
36 out.FileSizeBytes = l.fileSize
37 out.UnconfirmedTurns = len(l.pendingProjectionsLocked())
38 return out
39 }
40
41 func (l *Ledger) DrainMetrics() MetricsSnapshot {
42 if l == nil {
43 return MetricsSnapshot{}
44 }
45 l.mu.Lock()
46 defer l.mu.Unlock()
47 out := l.metrics
48 out.FileSizeBytes = l.fileSize
49 out.UnconfirmedTurns = len(l.pendingProjectionsLocked())
50 l.metrics = MetricsSnapshot{}
51 return out
52 }
53
54 func latencyBucket(elapsed time.Duration) int {
55 switch {
56 case elapsed < time.Millisecond:
57 return 0
58 case elapsed < 5*time.Millisecond:
59 return 1
60 case elapsed < 20*time.Millisecond:
61 return 2
62 case elapsed < 100*time.Millisecond:
63 return 3
64 default:
65 return 4
66 }
67 }
68
68 lines GO