-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
metric.go
66 lines (52 loc) · 1.22 KB
/
metric.go
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
57
58
59
60
61
62
63
64
65
66
package queue
import "sync/atomic"
// Metric interface
type Metric interface {
IncBusyWorker()
DecBusyWorker()
BusyWorkers() uint64
SuccessTasks() uint64
FailureTasks() uint64
SubmittedTasks() uint64
IncSuccessTask()
IncFailureTask()
IncSubmittedTask()
}
var _ Metric = (*metric)(nil)
type metric struct {
busyWorkers uint64
successTasks uint64
failureTasks uint64
submittedTasks uint64
}
// NewMetric for default metric structure
func NewMetric() Metric {
return &metric{}
}
func (m *metric) IncBusyWorker() {
atomic.AddUint64(&m.busyWorkers, 1)
}
func (m *metric) DecBusyWorker() {
atomic.AddUint64(&m.busyWorkers, ^uint64(0))
}
func (m *metric) BusyWorkers() uint64 {
return atomic.LoadUint64(&m.busyWorkers)
}
func (m *metric) IncSuccessTask() {
atomic.AddUint64(&m.successTasks, 1)
}
func (m *metric) IncFailureTask() {
atomic.AddUint64(&m.failureTasks, 1)
}
func (m *metric) IncSubmittedTask() {
atomic.AddUint64(&m.submittedTasks, 1)
}
func (m *metric) SuccessTasks() uint64 {
return atomic.LoadUint64(&m.successTasks)
}
func (m *metric) FailureTasks() uint64 {
return atomic.LoadUint64(&m.failureTasks)
}
func (m *metric) SubmittedTasks() uint64 {
return atomic.LoadUint64(&m.submittedTasks)
}