-
Notifications
You must be signed in to change notification settings - Fork 210
/
metrics.go
60 lines (49 loc) · 2 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
package sync
import (
"github.com/go-kit/kit/metrics"
prmkit "github.com/go-kit/kit/metrics/prometheus"
"github.com/prometheus/client_golang/prometheus"
"github.com/spacemeshos/go-spacemesh/p2p/server"
)
const (
namespace = "spacemesh"
subsystem = "consensus"
)
func newCounter(name, help string, labels []string) metrics.Counter {
return prmkit.NewCounterFrom(prometheus.CounterOpts{Namespace: namespace, Subsystem: subsystem, Name: name, Help: help}, labels)
}
func newMilliTimer(sum prometheus.Summary) *prometheus.Timer {
return prometheus.NewTimer(prometheus.ObserverFunc(func(v float64) {
us := v * 1000 // make microseconds
sum.Observe(us)
}))
}
func newFetchRequestTimer(msgtype server.MessageType) *prometheus.Timer {
if msgtype == blockMsg {
return newMilliTimer(blockTime)
}
if msgtype == txMsg {
return newMilliTimer(txTime)
}
if msgtype == atxMsg {
return newMilliTimer(atxTime)
}
return nil
}
var (
gossipBlockTime = prometheus.NewSummary(prometheus.SummaryOpts{Name: "gossip_block_request_durations",
Help: "gossip block handle duration in milliseconds",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}})
syncLayerTime = prometheus.NewSummary(prometheus.SummaryOpts{Name: "sync_Layer_durations",
Help: "Layer Fetch duration in milliseconds",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}})
blockTime = prometheus.NewSummary(prometheus.SummaryOpts{Name: "block_request_durations",
Help: "block requests duration in milliseconds",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}})
txTime = prometheus.NewSummary(prometheus.SummaryOpts{Name: "tx_request_durations",
Help: "tx requests duration in milliseconds",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}})
atxTime = prometheus.NewSummary(prometheus.SummaryOpts{Name: "atx_request_durations",
Help: "atx requests duration in milliseconds",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}})
)