-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmetrics.go
More file actions
56 lines (51 loc) · 1.53 KB
/
metrics.go
File metadata and controls
56 lines (51 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package worker
import (
"sync/atomic"
"time"
)
// taskMetrics holds counters for task lifecycle events.
type taskMetrics struct {
scheduled atomic.Int64
running atomic.Int64
completed atomic.Int64
failed atomic.Int64
cancelled atomic.Int64
retried atomic.Int64
latencyCount atomic.Int64
latencyTotalNs atomic.Int64
latencyMaxNs atomic.Int64
}
// MetricsSnapshot represents a snapshot of task metrics.
type MetricsSnapshot struct {
Scheduled int64
Running int64
Completed int64
Failed int64
Cancelled int64
Retried int64
ResultsDropped int64
QueueDepth int
TaskLatencyCount int64
TaskLatencyTotal time.Duration
TaskLatencyMax time.Duration
}
// GetMetrics returns a snapshot of current metrics.
func (tm *TaskManager) GetMetrics() MetricsSnapshot {
queueDepth := tm.queueDepth()
latencyCount := tm.metrics.latencyCount.Load()
latencyTotal := time.Duration(tm.metrics.latencyTotalNs.Load())
latencyMax := time.Duration(tm.metrics.latencyMaxNs.Load())
return MetricsSnapshot{
Scheduled: tm.metrics.scheduled.Load(),
Running: tm.metrics.running.Load(),
Completed: tm.metrics.completed.Load(),
Failed: tm.metrics.failed.Load(),
Cancelled: tm.metrics.cancelled.Load(),
Retried: tm.metrics.retried.Load(),
ResultsDropped: tm.results.Drops(),
QueueDepth: queueDepth,
TaskLatencyCount: latencyCount,
TaskLatencyTotal: latencyTotal,
TaskLatencyMax: latencyMax,
}
}