-
Notifications
You must be signed in to change notification settings - Fork 1
/
metrics.go
59 lines (49 loc) · 1.29 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"strings"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/rs/zerolog/log"
)
var (
validatorStatus = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "validator_effectiveness_status",
}, []string{"wallet_id", "validator_index"})
)
func ValidatorEffectiveness() error {
for _, wallet := range strings.Split(cfg.OPERATOR_WALLETS, ",") {
pubkeys, err := GetPubkeys(wallet)
if err != nil {
log.Error().Err(err)
return err
}
currentSlot, previousSlot, err := getEpoch()
if err != nil {
log.Error().Err(err)
return err
}
log.Info().Msgf("Operator efficiency calculation. Wallet ID: %s Slots: %d-%d", wallet, previousSlot, currentSlot)
currentBalance, err := ValidatorBalances(currentSlot, pubkeys)
if err != nil {
log.Error().Err(err)
return err
}
previousBalance, err := ValidatorBalances(previousSlot, pubkeys)
if err != nil {
log.Error().Err(err)
return err
}
for k, v := range currentBalance {
if oldBalance, ok := previousBalance[k]; ok {
if v <= (oldBalance - 5000) {
validatorStatus.WithLabelValues(wallet, k).Set(0)
} else {
validatorStatus.WithLabelValues(wallet, k).Set(1)
}
} else {
continue
}
}
}
return nil
}