Align metrics to interop (#3406)

This commit is contained in:
terence tsao
2019-09-05 08:32:35 -07:00
committed by GitHub
parent c383b6a30c
commit 75bce9b7e1
5 changed files with 66 additions and 24 deletions

View File

@@ -4,26 +4,35 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params"
)
var (
lastSlotGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "state_last_slot",
Help: "Last slot number of the processed state",
})
lastJustifiedEpochGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "state_last_justified_epoch",
Help: "Last justified epoch of the processed state",
})
lastPrevJustifiedEpochGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "state_last_prev_justified_epoch",
Help: "Last prev justified epoch of the processed state",
})
lastFinalizedEpochGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "state_last_finalized_epoch",
beaconFinalizedEpoch = promauto.NewGauge(prometheus.GaugeOpts{
Name: "beacon_finalized_epoch",
Help: "Last finalized epoch of the processed state",
})
beaconFinalizedRoot = promauto.NewGauge(prometheus.GaugeOpts{
Name: "beacon_finalized_root",
Help: "Last finalized root of the processed state",
})
beaconCurrentJustifiedEpoch = promauto.NewGauge(prometheus.GaugeOpts{
Name: "beacon_current_justified_epoch",
Help: "Current justified epoch of the processed state",
})
beaconCurrentJustifiedRoot = promauto.NewGauge(prometheus.GaugeOpts{
Name: "beacon_current_justified_root",
Help: "Current justified root of the processed state",
})
beaconPrevJustifiedEpoch = promauto.NewGauge(prometheus.GaugeOpts{
Name: "beacon_previous_justified_epoch",
Help: "Previous justified epoch of the processed state",
})
beaconPrevJustifiedRoot = promauto.NewGauge(prometheus.GaugeOpts{
Name: "beacon_previous_justified_root",
Help: "Previous justified root of the processed state",
})
activeValidatorsGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "state_active_validators",
Help: "Total number of active validators",
@@ -37,12 +46,12 @@ var (
Help: "Total withdrawn validators",
})
totalValidatorsGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "state_total_validators",
Help: "All time total validators",
Name: "beacon_current_validators",
Help: "Number of status=pending|active|exited|withdrawable validators in current epoch",
})
)
func reportStateMetrics(state *pb.BeaconState) {
func reportEpochMetrics(state *pb.BeaconState) {
currentEpoch := state.Slot / params.BeaconConfig().SlotsPerEpoch
// Validator counts
@@ -65,19 +74,19 @@ func reportStateMetrics(state *pb.BeaconState) {
withdrawnValidatorsGauge.Set(withdrawn)
totalValidatorsGauge.Set(float64(len(state.Validators)))
// Slot number
lastSlotGauge.Set(float64(state.Slot))
// Last justified slot
if state.CurrentJustifiedCheckpoint != nil {
lastJustifiedEpochGauge.Set(float64(state.CurrentJustifiedCheckpoint.Epoch))
beaconCurrentJustifiedEpoch.Set(float64(state.CurrentJustifiedCheckpoint.Epoch))
beaconCurrentJustifiedRoot.Set(float64(bytesutil.ToLowInt64(state.CurrentJustifiedCheckpoint.Root)))
}
// Last previous justified slot
if state.PreviousJustifiedCheckpoint != nil {
lastPrevJustifiedEpochGauge.Set(float64(state.PreviousJustifiedCheckpoint.Epoch))
beaconPrevJustifiedEpoch.Set(float64(state.PreviousJustifiedCheckpoint.Epoch))
beaconPrevJustifiedRoot.Set(float64(bytesutil.ToLowInt64(state.PreviousJustifiedCheckpoint.Root)))
}
// Last finalized slot
if state.FinalizedCheckpoint != nil {
lastFinalizedEpochGauge.Set(float64(state.FinalizedCheckpoint.Epoch))
beaconFinalizedEpoch.Set(float64(state.FinalizedCheckpoint.Epoch))
beaconFinalizedRoot.Set(float64(bytesutil.ToLowInt64(state.FinalizedCheckpoint.Root)))
}
}

View File

@@ -121,7 +121,7 @@ func (s *Store) OnBlock(ctx context.Context, b *ethpb.BeaconBlock) error {
// Epoch boundary bookkeeping such as logging epoch summaries.
if helpers.IsEpochStart(postState.Slot) {
logEpochData(postState)
reportStateMetrics(postState)
reportEpochMetrics(postState)
}
return nil

View File

@@ -3,9 +3,22 @@ package blockchain
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
)
var (
beaconSlot = promauto.NewGauge(prometheus.GaugeOpts{
Name: "beacon_slot",
Help: "Latest slot of the beacon chain state",
})
beaconHeadSlot = promauto.NewGauge(prometheus.GaugeOpts{
Name: "beacon_head_slot",
Help: "Slot of the head block of the beacon chain",
})
beaconHeadRoot = promauto.NewGauge(prometheus.GaugeOpts{
Name: "beacon_head_root",
Help: "Root of the head block of the beacon chain, it returns the lowest 8 bytes interpreted as little endian",
})
competingAtts = promauto.NewCounter(prometheus.CounterOpts{
Name: "competing_attestations",
Help: "The # of attestations received and processed from a competing chain",
@@ -35,3 +48,9 @@ var (
Help: "The # of processed attestation with pubsub and fork choice, this ususally means attestations from rpc",
})
)
func (c *ChainService) reportSlotMetrics(currentSlot uint64) {
beaconSlot.Set(float64(currentSlot))
beaconHeadSlot.Set(float64(c.HeadSlot()))
beaconHeadRoot.Set(float64(bytesutil.ToLowInt64(c.HeadRoot())))
}

View File

@@ -96,6 +96,9 @@ func (c *ChainService) ReceiveBlockNoPubsub(ctx context.Context, block *ethpb.Be
return errors.Wrap(err, "could not clean up block deposits, attestations, and other operations")
}
// Reports on block and fork choice metrics.
c.reportSlotMetrics(block.Slot)
processedBlkNoPubsub.Inc()
return nil
}
@@ -128,6 +131,9 @@ func (c *ChainService) ReceiveBlockNoPubsubForkchoice(ctx context.Context, block
return errors.Wrap(err, "could not clean up block deposits, attestations, and other operations")
}
// Reports on block and fork choice metrics.
c.reportSlotMetrics(block.Slot)
processedBlkNoPubsubForkchoice.Inc()
return nil
}

View File

@@ -142,3 +142,11 @@ func Trunc(x []byte) []byte {
}
return x
}
// ToLowInt64 returns the lowest 8 bytes interpreted as little endian.
func ToLowInt64(x []byte) int64 {
if len(x) > 8 {
x = x[:8]
}
return int64(binary.LittleEndian.Uint64(x))
}