fixed duplicate register issue
This commit is contained in:
parent
7bfab5fae3
commit
0985203997
|
@ -209,15 +209,15 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
client := rpc.NewRPCClient(config.RpcUrl, config.HttpTimeout)
|
client := rpc.NewRPCClient(config.RpcUrl, config.HttpTimeout)
|
||||||
ctx_, cancel := context.WithTimeout(ctx, config.HttpTimeout)
|
votekeys, err := GetAssociatedVoteAccounts(ctx, client, rpc.CommitmentFinalized, config.NodeKeys)
|
||||||
defer cancel()
|
|
||||||
votekeys, err := GetAssociatedVoteAccounts(ctx_, client, rpc.CommitmentFinalized, config.NodeKeys)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Fatalf("Failed to get associated vote accounts for %v: %v", config.NodeKeys, err)
|
klog.Fatalf("Failed to get associated vote accounts for %v: %v", config.NodeKeys, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
collector := NewSolanaCollector(client, slotPacerSchedule, config.BalanceAddresses, config.NodeKeys, votekeys)
|
collector := NewSolanaCollector(client, slotPacerSchedule, config.BalanceAddresses, config.NodeKeys, votekeys)
|
||||||
slotWatcher := NewSlotWatcher(client, config.NodeKeys, votekeys, config.ComprehensiveSlotTracking)
|
slotWatcher := NewSlotWatcher(client, config.NodeKeys, votekeys, config.ComprehensiveSlotTracking)
|
||||||
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
defer cancel()
|
||||||
go slotWatcher.WatchSlots(ctx, collector.slotPace)
|
go slotWatcher.WatchSlots(ctx, collector.slotPace)
|
||||||
|
|
||||||
prometheus.MustRegister(collector)
|
prometheus.MustRegister(collector)
|
||||||
|
|
|
@ -107,15 +107,29 @@ func NewSlotWatcher(
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
// register:
|
// register:
|
||||||
prometheus.MustRegister(watcher.TotalTransactionsMetric)
|
for _, collector := range []prometheus.Collector{
|
||||||
prometheus.MustRegister(watcher.SlotHeightMetric)
|
watcher.TotalTransactionsMetric,
|
||||||
prometheus.MustRegister(watcher.EpochNumberMetric)
|
watcher.SlotHeightMetric,
|
||||||
prometheus.MustRegister(watcher.EpochFirstSlotMetric)
|
watcher.EpochNumberMetric,
|
||||||
prometheus.MustRegister(watcher.EpochLastSlotMetric)
|
watcher.EpochFirstSlotMetric,
|
||||||
prometheus.MustRegister(watcher.LeaderSlotsTotalMetric)
|
watcher.EpochLastSlotMetric,
|
||||||
prometheus.MustRegister(watcher.LeaderSlotsByEpochMetric)
|
watcher.LeaderSlotsTotalMetric,
|
||||||
prometheus.MustRegister(watcher.InflationRewardsMetric)
|
watcher.LeaderSlotsByEpochMetric,
|
||||||
prometheus.MustRegister(watcher.FeeRewardsMetric)
|
watcher.InflationRewardsMetric,
|
||||||
|
watcher.FeeRewardsMetric,
|
||||||
|
} {
|
||||||
|
if err := prometheus.Register(collector); err != nil {
|
||||||
|
var (
|
||||||
|
alreadyRegisteredErr *prometheus.AlreadyRegisteredError
|
||||||
|
duplicateErr = strings.Contains(err.Error(), "duplicate metrics collector registration attempted")
|
||||||
|
)
|
||||||
|
if errors.As(err, &alreadyRegisteredErr) || duplicateErr {
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
klog.Fatal(fmt.Errorf("failed to register collector: %w", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return &watcher
|
return &watcher
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue