Skip to content

Commit

Permalink
Add metrics per keys for next scheduled attestation and proposal (#8583)
Browse files Browse the repository at this point in the history
* Add metrics per keys for next scheduled attestation and proposal

* Found a better place where to update the counters

* Wrap with emitAccountMetrics flag
  • Loading branch information
killerwhile authored Mar 9, 2021
1 parent 72be10f commit 9980ca3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
22 changes: 22 additions & 0 deletions validator/client/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,28 @@ var (
"pubkey",
},
)
// ValidatorNextAttestationSlotGaugeVec used to track validator statuses by public key.
ValidatorNextAttestationSlotGaugeVec = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "validator",
Name: "next_attestation_slot",
Help: "validator next scheduled attestation slot",
},
[]string{
"pubkey",
},
)
// ValidatorNextProposalSlotGaugeVec used to track validator statuses by public key.
ValidatorNextProposalSlotGaugeVec = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "validator",
Name: "next_proposal_slot",
Help: "validator next scheduled proposal slot",
},
[]string{
"pubkey",
},
)
)

// LogValidatorGainsAndLosses logs important metrics related to this validator client's
Expand Down
10 changes: 8 additions & 2 deletions validator/client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,9 @@ func (v *validator) logDuties(slot types.Slot, duties []*ethpb.DutiesResponse_Du
slotOffset := slot - (slot % params.BeaconConfig().SlotsPerEpoch)
var totalAttestingKeys uint64
for _, duty := range duties {
validatorNotTruncatedKey := fmt.Sprintf("%#x", duty.PublicKey)
if v.emitAccountMetrics {
fmtKey := fmt.Sprintf("%#x", duty.PublicKey)
ValidatorStatusesGaugeVec.WithLabelValues(fmtKey).Set(float64(duty.Status))
ValidatorStatusesGaugeVec.WithLabelValues(validatorNotTruncatedKey).Set(float64(duty.Status))
}

// Only interested in validators who are attesting/proposing.
Expand All @@ -652,6 +652,9 @@ func (v *validator) logDuties(slot types.Slot, duties []*ethpb.DutiesResponse_Du
} else {
attesterKeys[duty.AttesterSlot-slotOffset] = append(attesterKeys[duty.AttesterSlot-slotOffset], validatorKey)
totalAttestingKeys++
if v.emitAccountMetrics {
ValidatorNextAttestationSlotGaugeVec.WithLabelValues(validatorNotTruncatedKey).Set(float64(duty.AttesterSlot))
}
}

for _, proposerSlot := range duty.ProposerSlots {
Expand All @@ -661,6 +664,9 @@ func (v *validator) logDuties(slot types.Slot, duties []*ethpb.DutiesResponse_Du
} else {
proposerKeys[proposerIndex] = validatorKey
}
if v.emitAccountMetrics {
ValidatorNextProposalSlotGaugeVec.WithLabelValues(validatorNotTruncatedKey).Set(float64(proposerSlot))
}
}
}
for i := types.Slot(0); i < params.BeaconConfig().SlotsPerEpoch; i++ {
Expand Down

0 comments on commit 9980ca3

Please sign in to comment.