59 lines
2.0 KiB
Go
59 lines
2.0 KiB
Go
package monitor
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
)
|
|
|
|
// Metrics Prometheus 指标集合
|
|
type Metrics struct {
|
|
tvl prometheus.Gauge
|
|
ethLocked prometheus.Gauge
|
|
genexMinted prometheus.Gauge
|
|
discrepancy prometheus.Gauge
|
|
reconciliations prometheus.Counter
|
|
largeTransfers prometheus.Counter
|
|
emergencyPauses prometheus.Counter
|
|
}
|
|
|
|
func NewMetrics() *Metrics {
|
|
return &Metrics{
|
|
tvl: promauto.NewGauge(prometheus.GaugeOpts{
|
|
Name: "bridge_total_value_locked",
|
|
Help: "Total value locked in the bridge (USD)",
|
|
}),
|
|
ethLocked: promauto.NewGauge(prometheus.GaugeOpts{
|
|
Name: "bridge_eth_locked_amount",
|
|
Help: "Amount locked on Ethereum side",
|
|
}),
|
|
genexMinted: promauto.NewGauge(prometheus.GaugeOpts{
|
|
Name: "bridge_genex_minted_amount",
|
|
Help: "Amount minted on Genex Chain side",
|
|
}),
|
|
discrepancy: promauto.NewGauge(prometheus.GaugeOpts{
|
|
Name: "bridge_discrepancy_amount",
|
|
Help: "Discrepancy between locked and minted amounts",
|
|
}),
|
|
reconciliations: promauto.NewCounter(prometheus.CounterOpts{
|
|
Name: "bridge_reconciliation_total",
|
|
Help: "Total number of reconciliations performed",
|
|
}),
|
|
largeTransfers: promauto.NewCounter(prometheus.CounterOpts{
|
|
Name: "bridge_large_transfer_total",
|
|
Help: "Total number of large bridge transfers detected",
|
|
}),
|
|
emergencyPauses: promauto.NewCounter(prometheus.CounterOpts{
|
|
Name: "bridge_emergency_pause_total",
|
|
Help: "Total number of emergency pauses triggered",
|
|
}),
|
|
}
|
|
}
|
|
|
|
func (m *Metrics) SetTVL(v float64) { m.tvl.Set(v) }
|
|
func (m *Metrics) SetEthLocked(v float64) { m.ethLocked.Set(v) }
|
|
func (m *Metrics) SetGenexMinted(v float64) { m.genexMinted.Set(v) }
|
|
func (m *Metrics) SetDiscrepancy(v float64) { m.discrepancy.Set(v) }
|
|
func (m *Metrics) IncReconciliation() { m.reconciliations.Inc() }
|
|
func (m *Metrics) IncLargeTransfer() { m.largeTransfers.Inc() }
|
|
func (m *Metrics) IncEmergencyPause() { m.emergencyPauses.Inc() }
|