-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmetrics.go
More file actions
45 lines (37 loc) · 698 Bytes
/
metrics.go
File metadata and controls
45 lines (37 loc) · 698 Bytes
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
package service_breaker
import (
"time"
)
//metrics
type Metrics struct {
WindowBatch uint64
WindowTimeStart time.Time
CountAll uint64
CountSuccess uint64
CountFail uint64
ConsecutiveSuccess uint64
ConsecutiveFail uint64
}
func (m *Metrics) NewBatch() {
m.WindowBatch++
}
func (m *Metrics) OnCall() {
m.CountAll++
}
func (m *Metrics) OnSuccess() {
m.CountSuccess++
m.ConsecutiveSuccess++
m.ConsecutiveFail = 0
}
func (m *Metrics) OnFail() {
m.CountFail++
m.ConsecutiveFail++
m.ConsecutiveSuccess = 0
}
func (m *Metrics) OnReset() {
m.CountAll = 0
m.CountSuccess = 0
m.CountFail = 0
m.ConsecutiveSuccess = 0
m.ConsecutiveFail = 0
}