mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
Add back state metrics (#3369)
This commit is contained in:
@@ -5,6 +5,7 @@ go_library(
|
||||
srcs = [
|
||||
"doc.go",
|
||||
"log.go",
|
||||
"metrics.go",
|
||||
"process_attestation.go",
|
||||
"process_block.go",
|
||||
"service.go",
|
||||
@@ -25,6 +26,8 @@ go_library(
|
||||
"//shared/roughtime:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@io_opencensus_go//trace:go_default_library",
|
||||
|
||||
83
beacon-chain/blockchain/forkchoice/metrics.go
Normal file
83
beacon-chain/blockchain/forkchoice/metrics.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package forkchoice
|
||||
|
||||
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/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",
|
||||
Help: "Last finalized epoch of the processed state",
|
||||
})
|
||||
activeValidatorsGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "state_active_validators",
|
||||
Help: "Total number of active validators",
|
||||
})
|
||||
slashedValidatorsGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "state_slashed_validators",
|
||||
Help: "Total slashed validators",
|
||||
})
|
||||
withdrawnValidatorsGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "state_withdrawn_validators",
|
||||
Help: "Total withdrawn validators",
|
||||
})
|
||||
totalValidatorsGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "state_total_validators",
|
||||
Help: "All time total validators",
|
||||
})
|
||||
)
|
||||
|
||||
func reportStateMetrics(state *pb.BeaconState) {
|
||||
currentEpoch := state.Slot / params.BeaconConfig().SlotsPerEpoch
|
||||
|
||||
// Validator counts
|
||||
var active float64
|
||||
var slashed float64
|
||||
var withdrawn float64
|
||||
for _, v := range state.Validators {
|
||||
if v.ActivationEpoch <= currentEpoch && currentEpoch < v.ExitEpoch {
|
||||
active++
|
||||
}
|
||||
if v.Slashed {
|
||||
slashed++
|
||||
}
|
||||
if currentEpoch >= v.ExitEpoch {
|
||||
withdrawn++
|
||||
}
|
||||
}
|
||||
activeValidatorsGauge.Set(active)
|
||||
slashedValidatorsGauge.Set(slashed)
|
||||
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))
|
||||
}
|
||||
// Last previous justified slot
|
||||
if state.PreviousJustifiedCheckpoint != nil {
|
||||
lastPrevJustifiedEpochGauge.Set(float64(state.PreviousJustifiedCheckpoint.Epoch))
|
||||
}
|
||||
// Last finalized slot
|
||||
if state.FinalizedCheckpoint != nil {
|
||||
lastFinalizedEpochGauge.Set(float64(state.FinalizedCheckpoint.Epoch))
|
||||
}
|
||||
}
|
||||
@@ -120,6 +120,7 @@ func (s *Store) OnBlock(ctx context.Context, b *ethpb.BeaconBlock) error {
|
||||
return errors.Wrap(err, "could not save finalized checkpoint")
|
||||
}
|
||||
logEpochData(postState)
|
||||
reportStateMetrics(postState)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -9,35 +9,35 @@ import (
|
||||
|
||||
var (
|
||||
lastSlotGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "state_last_slot",
|
||||
Name: "deprecated_state_last_slot",
|
||||
Help: "Last slot number of the processed state",
|
||||
})
|
||||
lastJustifiedEpochGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "state_last_justified_epoch",
|
||||
Name: "deprecated_state_last_justified_epoch",
|
||||
Help: "Last justified epoch of the processed state",
|
||||
})
|
||||
lastPrevJustifiedEpochGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "state_last_prev_justified_epoch",
|
||||
Name: "deprecated_state_last_prev_justified_epoch",
|
||||
Help: "Last prev justified epoch of the processed state",
|
||||
})
|
||||
lastFinalizedEpochGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "state_last_finalized_epoch",
|
||||
Name: "deprecated_state_last_finalized_epoch",
|
||||
Help: "Last finalized epoch of the processed state",
|
||||
})
|
||||
activeValidatorsGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "state_active_validators",
|
||||
Name: "deprecated_state_active_validators",
|
||||
Help: "Total number of active validators",
|
||||
})
|
||||
slashedValidatorsGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "state_slashed_validators",
|
||||
Name: "deprecated_state_slashed_validators",
|
||||
Help: "Total slashed validators",
|
||||
})
|
||||
withdrawnValidatorsGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "state_withdrawn_validators",
|
||||
Name: "deprecated_state_withdrawn_validators",
|
||||
Help: "Total withdrawn validators",
|
||||
})
|
||||
totalValidatorsGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "state_total_validators",
|
||||
Name: "deprecated_state_total_validators",
|
||||
Help: "All time total validators",
|
||||
})
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user