Skip to content

Commit c45c33b

Browse files
Slashing amount in prometheus metrics
1 parent 04f4713 commit c45c33b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pkg/metrics/metrics.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ var (
2929
},
3030
[]string{"vault", "slasher"},
3131
)
32+
33+
AmountSlashedEventCounter = prometheus.NewCounterVec(
34+
prometheus.CounterOpts{
35+
Name: "amount_slashed_by_operator",
36+
Help: "Amount of tokens slashed due to operator misbehavior",
37+
},
38+
[]string{"vault", "operator", "subnetwork"}, // ← this is correct
39+
)
3240
)
3341

3442
func Init() {

pkg/observer/observer.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func StartVetoSlasherObserver(ctx context.Context, address string, vault string)
9999
continue
100100
}
101101

102-
decoded := make(map[string]interface{})
102+
decoded := make(map[string]interface{}) //<-- here to change
103103
if err := parsedABI.UnpackIntoMap(decoded, event.Name, vLog.Data); err != nil {
104104
log.Printf("❌ [%s] Failed to unpack data: %v", address, err)
105105
continue
@@ -124,6 +124,23 @@ func StartVetoSlasherObserver(ctx context.Context, address string, vault string)
124124
alertmanager.SendStructuredData(alertData)
125125
metrics.SlashingEventCounter.WithLabelValues(vault, address).Inc()
126126

127+
if event.Name == "RequestSlash" {
128+
operatorAddr, ok1 := decoded["operator"].(common.Address)
129+
subnetworkRaw, ok2 := decoded["subnetwork"].(string)
130+
slashAmount, ok3 := decoded["slashAmount"].(*big.Int)
131+
132+
if !ok1 || !ok2 || !ok3 {
133+
log.Printf("⚠️ [%s] Failed to cast RequestSlash fields properly", address)
134+
continue
135+
}
136+
137+
amountFloat, _ := new(big.Float).SetInt(slashAmount).Float64()
138+
139+
metrics.AmountSlashedEventCounter.
140+
WithLabelValues(vault, operatorAddr.Hex(), subnetworkRaw).
141+
Add(amountFloat)
142+
}
143+
127144
case <-ctx.Done():
128145
log.Printf("🛑 [%s] Stopping observer...", address)
129146
return

0 commit comments

Comments
 (0)