-
Notifications
You must be signed in to change notification settings - Fork 665
/
timestamp.go
38 lines (30 loc) · 963 Bytes
/
timestamp.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
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
)
var _ Timestamp = (*timestamp)(nil)
// Timestamp reports the last accepted block time,
// to track it in unix seconds.
type Timestamp interface {
Accepted(ts time.Time)
}
type timestamp struct {
// lastAcceptedTimestamp keeps track of the last accepted timestamp
lastAcceptedTimestamp prometheus.Gauge
}
func NewTimestamp(namespace string, reg prometheus.Registerer) (Timestamp, error) {
t := ×tamp{
lastAcceptedTimestamp: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "last_accepted_timestamp",
Help: "Last accepted block timestamp in unix seconds",
}),
}
return t, reg.Register(t.lastAcceptedTimestamp)
}
func (t *timestamp) Accepted(ts time.Time) {
t.lastAcceptedTimestamp.Set(float64(ts.Unix()))
}