From 61c7492d3630bdb1b61d44ddce650226c1930249 Mon Sep 17 00:00:00 2001 From: Aurora Gaffney Date: Sun, 15 Sep 2024 17:24:57 -0500 Subject: [PATCH] feat: add metrics for indexer slot and tip slot (#210) Fixes #204 --- internal/indexer/indexer.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/indexer/indexer.go b/internal/indexer/indexer.go index e16fa7d..8014b43 100644 --- a/internal/indexer/indexer.go +++ b/internal/indexer/indexer.go @@ -17,6 +17,8 @@ import ( "github.com/blinklabs-io/cdnsd/internal/config" "github.com/blinklabs-io/cdnsd/internal/state" ouroboros "github.com/blinklabs-io/gouroboros" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" "github.com/blinklabs-io/adder/event" filter_event "github.com/blinklabs-io/adder/filter/event" @@ -34,6 +36,17 @@ const ( syncStatusLogInterval = 30 * time.Second ) +var ( + metricSlot = promauto.NewGauge(prometheus.GaugeOpts{ + Name: "indexer_slot", + Help: "Indexer current slot number", + }) + metricTipSlot = promauto.NewGauge(prometheus.GaugeOpts{ + Name: "indexer_tip_slot", + Help: "Slot number for upstream chain tip", + }) +) + type Domain struct { Name string Nameservers map[string]string @@ -108,6 +121,8 @@ func (i *Indexer) Start() error { input_chainsync.WithStatusUpdateFunc( func(status input_chainsync.ChainSyncStatus) { i.syncStatus = status + metricSlot.Set(float64(status.SlotNumber)) + metricTipSlot.Set(float64(status.TipSlotNumber)) if err := state.GetState().UpdateCursor(status.SlotNumber, status.BlockHash); err != nil { slog.Error( fmt.Sprintf("failed to update cursor: %s", err),