Skip to content

Commit

Permalink
Add the beacon ID to some metrics (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcamou committed Apr 21, 2022
1 parent 814b9e6 commit baf6249
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
16 changes: 12 additions & 4 deletions chain/beacon/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

clock "github.com/jonboulle/clockwork"

"github.com/drand/drand/common"
"github.com/drand/drand/common/scheme"

"github.com/drand/drand/chain"
Expand Down Expand Up @@ -113,13 +114,20 @@ func (d *discrepancyStore) Put(b *chain.Beacon) error {
if err := d.Store.Put(b); err != nil {
return err
}

beaconID := d.group.ID
if beaconID == "" {
beaconID = common.DefaultBeaconID
}

actual := d.clock.Now().UnixNano()
expected := chain.TimeOfRound(d.group.Period, d.group.GenesisTime, b.Round) * 1e9
discrepancy := float64(actual-expected) / float64(time.Millisecond)
metrics.BeaconDiscrepancyLatency.Set(float64(actual-expected) / float64(time.Millisecond))
metrics.LastBeaconRound.Set(float64(b.GetRound()))
metrics.GroupSize.Set(float64(d.group.Len()))
metrics.GroupThreshold.Set(float64(d.group.Threshold))

metrics.BeaconDiscrepancyLatency.WithLabelValues(beaconID).Set(float64(actual-expected) / float64(time.Millisecond))
metrics.LastBeaconRound.WithLabelValues(beaconID).Set(float64(b.GetRound()))
metrics.GroupSize.WithLabelValues(beaconID).Set(float64(d.group.Len()))
metrics.GroupThreshold.WithLabelValues(beaconID).Set(float64(d.group.Threshold))
d.l.Infow("", "NEW_BEACON_STORED", b.String(), "time_discrepancy_ms", discrepancy)
return nil
}
Expand Down
22 changes: 14 additions & 8 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,41 @@ var (
Name: "api_call_counter",
Help: "Number of API calls that we have received",
}, []string{"api_method"})

// GroupDialFailures (Group) how manuy failures connecting outbound
GroupDialFailures = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "dial_failures",
Help: "Number of times there have been network connection issues",
}, []string{"peer_address"})

// OutgoingConnections (Group) how many GrpcClient connections are present
OutgoingConnections = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "outgoing_group_connections",
Help: "Number of peers with current outgoing GrpcClient connections",
})
GroupSize = prometheus.NewGauge(prometheus.GaugeOpts{

GroupSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "group_size",
Help: "Number of peers in the current group",
})
GroupThreshold = prometheus.NewGauge(prometheus.GaugeOpts{
}, []string{"beacon_id"})

GroupThreshold = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "group_threshold",
Help: "Number of shares needed for beacon reconstruction",
})
}, []string{"beacon_id"})

// BeaconDiscrepancyLatency (Group) millisecond duration between time beacon created and
// calculated time of round.
BeaconDiscrepancyLatency = prometheus.NewGauge(prometheus.GaugeOpts{
BeaconDiscrepancyLatency = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "beacon_discrepancy_latency",
Help: "Discrepancy between beacon creation time and calculated round time",
})
}, []string{"beacon_id"})

// LastBeaconRound is the most recent round (as also seen at /health) stored.
LastBeaconRound = prometheus.NewGauge(prometheus.GaugeOpts{
LastBeaconRound = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "last_beacon_round",
Help: "Last locally stored beacon",
})
}, []string{"beacon_id"})

// HTTPCallCounter (HTTP) how many http requests
HTTPCallCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
Expand Down

0 comments on commit baf6249

Please sign in to comment.