-
Notifications
You must be signed in to change notification settings - Fork 5
/
report.go
87 lines (76 loc) · 2.26 KB
/
report.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package handel
// ReportHandel holds a handel struct but modifies it so it is able to issue
// some stats.
type ReportHandel struct {
*Handel
}
// Reporter can report values indexed by a string key as float64 types.
type Reporter interface {
Values() map[string]float64
}
// NewReportHandel returns a Handel implementing the Reporter interface.
// It reports values about the network interface and the store interface of
// Handel.
func NewReportHandel(h *Handel) *ReportHandel {
h.store = newReportStore(h.store)
return &ReportHandel{h}
}
// Values returns the values of the internal components of Handel merged together.
func (r *ReportHandel) Values() map[string]float64 {
net := r.Network()
netValues := net.Values()
store := r.Handel.store.(*ReportStore)
storeValues := store.Values()
merged := make(map[string]float64)
for k, v := range netValues {
merged["net_"+k] = float64(v)
}
for k, v := range storeValues {
merged["store_"+k] = float64(v)
}
return merged
}
// Network returns the Network reporter interface
func (r *ReportHandel) Network() Reporter {
return r.Handel.net.(Reporter)
}
// Store returns the Store reporter interface
func (r *ReportHandel) Store() Reporter {
return r.Handel.store.(*ReportStore)
}
// Processing returns the Store reporter interface
func (r *ReportHandel) Processing() Reporter {
return r.Handel.proc.(Reporter)
}
// ReportStore is a Store that can report some statistics about the storage
type ReportStore struct {
SignatureStore
sucessReplaced int64
replacedTrial int64
}
// newReportStore returns a signatureStore with some addtional reporting
// capabilities
func newReportStore(s SignatureStore) SignatureStore {
return &ReportStore{
SignatureStore: s,
}
}
// Store overload the signatureStore interface's method.
func (r *ReportStore) Store(sp *incomingSig) *MultiSignature {
ms := r.SignatureStore.Store(sp)
if ms != nil {
r.sucessReplaced++
} else {
r.replacedTrial++
}
return ms
}
// Values implements the simul/monitor/counterIO interface
func (r *ReportStore) Values() map[string]float64 {
return map[string]float64{
// how many times did we successfully replaced a signature
"successReplace": float64(r.sucessReplaced),
// how many times did we tried to
"replaceTrial": float64(r.replacedTrial),
}
}