2019-02-24 04:33:10 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
2019-03-05 02:38:03 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
2019-02-24 04:33:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
validatorBalancesGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
|
Name: "state_validator_balances",
|
|
|
|
Help: "Balances of validators, updated on epoch transition",
|
|
|
|
}, []string{
|
|
|
|
"validator",
|
|
|
|
})
|
2019-03-05 02:38:03 +00:00
|
|
|
lastSlotGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
2019-03-03 13:18:27 +00:00
|
|
|
Name: "state_last_slot",
|
|
|
|
Help: "Last slot number of the processed state",
|
|
|
|
})
|
2019-03-05 02:38:03 +00:00
|
|
|
lastJustifiedEpochGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
2019-03-04 06:53:20 +00:00
|
|
|
Name: "state_last_justified_epoch",
|
|
|
|
Help: "Last justified epoch of the processed state",
|
|
|
|
})
|
2019-03-05 02:38:03 +00:00
|
|
|
lastPrevJustifiedEpochGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
2019-03-04 06:53:20 +00:00
|
|
|
Name: "state_last_prev_justified_epoch",
|
|
|
|
Help: "Last prev justified epoch of the processed state",
|
|
|
|
})
|
2019-03-05 02:38:03 +00:00
|
|
|
lastFinalizedEpochGauge = promauto.NewGauge(prometheus.GaugeOpts{
|
2019-03-04 06:53:20 +00:00
|
|
|
Name: "state_last_finalized_epoch",
|
|
|
|
Help: "Last finalized epoch of the processed state",
|
|
|
|
})
|
2019-02-24 04:33:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func reportEpochTransitionMetrics(state *pb.BeaconState) {
|
|
|
|
// Validator balances
|
|
|
|
for i, bal := range state.ValidatorBalances {
|
|
|
|
validatorBalancesGauge.WithLabelValues(
|
|
|
|
"0x" + hex.EncodeToString(state.ValidatorRegistry[i].Pubkey), // Validator
|
|
|
|
).Set(float64(bal))
|
|
|
|
}
|
2019-03-05 02:38:03 +00:00
|
|
|
s := params.BeaconConfig().GenesisSlot
|
2019-03-05 15:51:13 +00:00
|
|
|
e := params.BeaconConfig().GenesisEpoch
|
2019-03-03 13:18:27 +00:00
|
|
|
// Slot number
|
2019-03-05 02:38:03 +00:00
|
|
|
lastSlotGauge.Set(float64(state.Slot - s))
|
2019-03-04 06:53:20 +00:00
|
|
|
// Last justified slot
|
2019-03-05 15:51:13 +00:00
|
|
|
lastJustifiedEpochGauge.Set(float64(state.JustifiedEpoch - e))
|
2019-03-04 06:53:20 +00:00
|
|
|
// Last previous justified slot
|
2019-03-05 15:51:13 +00:00
|
|
|
lastPrevJustifiedEpochGauge.Set(float64(state.PreviousJustifiedEpoch - e))
|
2019-03-04 06:53:20 +00:00
|
|
|
// Last finalized slot
|
2019-03-05 15:51:13 +00:00
|
|
|
lastFinalizedEpochGauge.Set(float64(state.FinalizedEpoch - e))
|
2019-02-24 04:33:10 +00:00
|
|
|
}
|