| 1 | package sessioninbox |
| 2 | |
| 3 | import "sync/atomic" |
| 4 | |
| 5 | // Lightweight process-local counters (no message bodies). Telemetry sinks may |
| 6 | // scrape these; zero values mean the feature was unused. |
| 7 | var ( |
| 8 | metricEnqueue atomic.Int64 |
| 9 | metricEnqueueBytes atomic.Int64 |
| 10 | metricRecovered atomic.Int64 |
| 11 | metricPaused atomic.Int64 |
| 12 | metricSteerAccepted atomic.Int64 |
| 13 | metricSteerRejected atomic.Int64 |
| 14 | metricCapacityRej atomic.Int64 |
| 15 | metricUncertain atomic.Int64 |
| 16 | metricTxFail atomic.Int64 |
| 17 | ) |
| 18 | |
| 19 | // MetricsSnapshot is a body-free counters view for diagnostics. |
| 20 | type MetricsSnapshot struct { |
| 21 | Enqueue int64 `json:"enqueue"` |
| 22 | EnqueueBytes int64 `json:"enqueueBytes"` |
| 23 | Recovered int64 `json:"recovered"` |
| 24 | Paused int64 `json:"paused"` |
| 25 | SteerAccepted int64 `json:"steerAccepted"` |
| 26 | SteerRejected int64 `json:"steerRejected"` |
| 27 | CapacityReject int64 `json:"capacityReject"` |
| 28 | Uncertain int64 `json:"uncertain"` |
| 29 | TxFail int64 `json:"txFail"` |
| 30 | } |
| 31 | |
| 32 | // Metrics returns current process-local inbox counters. |
| 33 | func Metrics() MetricsSnapshot { |
| 34 | return MetricsSnapshot{ |
| 35 | Enqueue: metricEnqueue.Load(), |
| 36 | EnqueueBytes: metricEnqueueBytes.Load(), |
| 37 | Recovered: metricRecovered.Load(), |
| 38 | Paused: metricPaused.Load(), |
| 39 | SteerAccepted: metricSteerAccepted.Load(), |
| 40 | SteerRejected: metricSteerRejected.Load(), |
| 41 | CapacityReject: metricCapacityRej.Load(), |
| 42 | Uncertain: metricUncertain.Load(), |
| 43 | TxFail: metricTxFail.Load(), |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | // NoteEnqueue increments durable-enqueue counters (body length only, no text). |
| 48 | func NoteEnqueue(bytes int64) { |
| 49 | metricEnqueue.Add(1) |
| 50 | if bytes > 0 { |
| 51 | metricEnqueueBytes.Add(bytes) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // NoteRecovered records crash-recovery item counts. |
| 56 | func NoteRecovered(n int) { |
| 57 | if n > 0 { |
| 58 | metricRecovered.Add(int64(n)) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | func NotePaused() { metricPaused.Add(1) } |
| 63 | func NoteSteerAccepted() { metricSteerAccepted.Add(1) } |
| 64 | func NoteSteerRejected() { metricSteerRejected.Add(1) } |
| 65 | func NoteCapacityReject() { metricCapacityRej.Add(1) } |
| 66 | func NoteUncertain() { metricUncertain.Add(1) } |
| 67 | func NoteTxFail() { metricTxFail.Add(1) } |
| 68 |