From 48fa37ae5af21943ddb046663e86fcc4b7131a60 Mon Sep 17 00:00:00 2001 From: huichiaotsou Date: Wed, 21 Dec 2022 16:57:40 +0800 Subject: [PATCH 1/4] add prometheus DbLatestHeight --- logging/prometheus.go | 9 +++++++++ parser/worker.go | 3 +++ 2 files changed, 12 insertions(+) diff --git a/logging/prometheus.go b/logging/prometheus.go index 725da8aa..8da65824 100644 --- a/logging/prometheus.go +++ b/logging/prometheus.go @@ -45,6 +45,15 @@ var DbBlockCount = prometheus.NewGaugeVec( []string{"total_blocks_in_db"}, ) +// DbLatestHeight represents the Telemetry counter used to track the last indexed height in the database +var DbLatestHeight = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "juno_db_latest_height", + Help: "Latest block height in the database.", + }, + []string{"db_latest_height"}, +) + func init() { err := prometheus.Register(StartHeight) if err != nil { diff --git a/parser/worker.go b/parser/worker.go index a0b485b2..a3b00717 100644 --- a/parser/worker.go +++ b/parser/worker.go @@ -358,5 +358,8 @@ func (w Worker) ExportTxs(txs []*types.Tx) error { totalBlocks := w.db.GetTotalBlocks() logging.DbBlockCount.WithLabelValues("total_blocks_in_db").Set(float64(totalBlocks)) + dbLatestHeight, _ := w.db.GetLastBlockHeight() + logging.DbLatestHeight.WithLabelValues("db_latest_height").Set(float64(dbLatestHeight)) + return nil } From ee7a0a007f043e1b748fb28256fa95fad957d7ad Mon Sep 17 00:00:00 2001 From: huichiaotsou Date: Wed, 21 Dec 2022 16:59:29 +0800 Subject: [PATCH 2/4] add chagne log --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f991125..b8d0c524 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## Unreleased +- ([\#88](https://github.com/forbole/juno/pull/88)) Added `DbLatestHeight` metric to prometheus monitoring + ## v4.0.0 ### Changes - Updated cosmos/cosmos-sdk to `v0.45.8` From 18867c73d04ee817d821b9647f67d605cdb35cc9 Mon Sep 17 00:00:00 2001 From: huichiaotsou Date: Wed, 21 Dec 2022 17:24:29 +0800 Subject: [PATCH 3/4] prometheus.Register --- logging/prometheus.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/logging/prometheus.go b/logging/prometheus.go index 8da65824..96dea5a9 100644 --- a/logging/prometheus.go +++ b/logging/prometheus.go @@ -79,4 +79,9 @@ func init() { if err != nil { panic(err) } + + err = prometheus.Register(DbLatestHeight) + if err != nil { + panic(err) + } } From bb58aad6ff2c4b3dbbe433761fba43c21864c8aa Mon Sep 17 00:00:00 2001 From: huichiaotsou Date: Fri, 30 Dec 2022 14:43:55 +0800 Subject: [PATCH 4/4] handle error at w.db.GetLastBlockHeight() --- parser/worker.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/parser/worker.go b/parser/worker.go index a3b00717..de50f732 100644 --- a/parser/worker.go +++ b/parser/worker.go @@ -358,7 +358,10 @@ func (w Worker) ExportTxs(txs []*types.Tx) error { totalBlocks := w.db.GetTotalBlocks() logging.DbBlockCount.WithLabelValues("total_blocks_in_db").Set(float64(totalBlocks)) - dbLatestHeight, _ := w.db.GetLastBlockHeight() + dbLatestHeight, err := w.db.GetLastBlockHeight() + if err != nil { + return err + } logging.DbLatestHeight.WithLabelValues("db_latest_height").Set(float64(dbLatestHeight)) return nil