/
metrics.go
62 lines (53 loc) · 1.76 KB
/
metrics.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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package ttx
import (
"reflect"
view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/metrics"
)
var (
spKey = reflect.TypeOf((*Metrics)(nil))
endorsedTransactions = metrics.CounterOpts{
Namespace: "ttx",
Name: "endorsed_transactions",
Help: "The number of endorsed transactions.",
LabelNames: []string{"network", "channel", "namespace"},
StatsdFormat: "%{#fqname}.%{network}.%{channel}.%{namespace}",
}
auditApprovedTransactions = metrics.CounterOpts{
Namespace: "ttx",
Name: "audit_approved_transactions",
Help: "The number of approved transactions by the auditor.",
LabelNames: []string{"network", "channel", "namespace"},
StatsdFormat: "%{#fqname}.%{network}.%{channel}.%{namespace}",
}
acceptedTransactions = metrics.CounterOpts{
Namespace: "ttx",
Name: "accepted_transactions",
Help: "The number of accepted transactions.",
LabelNames: []string{"network", "channel", "namespace"},
StatsdFormat: "%{#fqname}.%{network}.%{channel}.%{namespace}",
}
)
type Metrics struct {
EndorsedTransactions metrics.Counter
AuditApprovedTransactions metrics.Counter
AcceptedTransactions metrics.Counter
}
func NewMetrics(p metrics.Provider) *Metrics {
return &Metrics{
EndorsedTransactions: p.NewCounter(endorsedTransactions),
AuditApprovedTransactions: p.NewCounter(auditApprovedTransactions),
AcceptedTransactions: p.NewCounter(acceptedTransactions),
}
}
func GetMetrics(sp view2.ServiceProvider) *Metrics {
s, err := sp.GetService(spKey)
if err != nil {
panic(err)
}
return s.(*Metrics)
}