forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 3
/
height.go
35 lines (28 loc) · 843 Bytes
/
height.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
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
)
var _ Height = (*height)(nil)
// Height reports the last accepted height
type Height interface {
Accepted(height uint64)
}
type height struct {
// lastAcceptedHeight keeps track of the last accepted height
lastAcceptedHeight prometheus.Gauge
}
func NewHeight(namespace string, reg prometheus.Registerer) (Height, error) {
h := &height{
lastAcceptedHeight: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "last_accepted_height",
Help: "Last height accepted",
}),
}
return h, reg.Register(h.lastAcceptedHeight)
}
func (h *height) Accepted(height uint64) {
h.lastAcceptedHeight.Set(float64(height))
}