-
Notifications
You must be signed in to change notification settings - Fork 211
/
metrics.go
46 lines (39 loc) · 1.16 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
package miner
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/spacemeshos/go-spacemesh/log"
"github.com/spacemeshos/go-spacemesh/metrics"
)
var proposalBuild = metrics.NewHistogramWithBuckets(
"proposal_build_seconds",
"miner",
"duration to build a proposal in seconds",
[]string{},
prometheus.ExponentialBuckets(0.1, 2, 10),
).WithLabelValues()
type latencyTracker struct {
start time.Time
data time.Time
tortoise time.Time
txs time.Time
hash time.Time
publish time.Time
}
func (lt *latencyTracker) total() time.Duration {
return lt.publish.Sub(lt.start)
}
func (lt *latencyTracker) MarshalLogObject(encoder log.ObjectEncoder) error {
encoder.AddDuration("data", lt.data.Sub(lt.start))
encoder.AddDuration("tortoise", lt.tortoise.Sub(lt.data))
encoder.AddDuration("hash", lt.hash.Sub(lt.tortoise))
encoder.AddDuration("txs", lt.txs.Sub(lt.hash))
encoder.AddDuration("publish", lt.publish.Sub(lt.hash))
total := lt.total()
encoder.AddDuration("total", total)
// arbitrary threshold that we want to highlight as a problem
if total > 10*time.Second {
encoder.AddBool("LATE PROPOSAL", true)
}
return nil
}