From abdf639aa93e7e1db510c68a1ff69c36b1489bcd Mon Sep 17 00:00:00 2001 From: Aaron <76254323+huichiaotsou@users.noreply.github.com> Date: Fri, 30 Dec 2022 21:41:39 +0800 Subject: [PATCH] feat: add `DbLatestHeight` metric to prometheus (#88) ## Description https://forbole.atlassian.net/browse/BDU-724 ## Checklist - [x] Targeted PR against correct branch. - [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Wrote unit tests. - [x] Re-reviewed `Files changed` in the Github PR explorer. --- CHANGELOG.md | 2 ++ logging/prometheus.go | 14 ++++++++++++++ parser/worker.go | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3270486e..8b0d6d3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## Unreleased + ### Changes - ([\#74](https://github.com/forbole/juno/pull/74)) Applied `GetMissingHeights()` in `enqueueMissingBlocks()` & in `parse blocks missing` cmd +- ([\#88](https://github.com/forbole/juno/pull/88)) Added `juno_db_latest_height` metric to prometheus monitoring ## v4.0.0 ### Changes diff --git a/logging/prometheus.go b/logging/prometheus.go index 725da8aa..96dea5a9 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 { @@ -70,4 +79,9 @@ func init() { if err != nil { panic(err) } + + err = prometheus.Register(DbLatestHeight) + if err != nil { + panic(err) + } } diff --git a/parser/worker.go b/parser/worker.go index 9c239271..65200a79 100644 --- a/parser/worker.go +++ b/parser/worker.go @@ -358,5 +358,11 @@ func (w Worker) ExportTxs(txs []*types.Tx) error { totalBlocks := w.db.GetTotalBlocks() logging.DbBlockCount.WithLabelValues("total_blocks_in_db").Set(float64(totalBlocks)) + dbLatestHeight, err := w.db.GetLastBlockHeight() + if err != nil { + return err + } + logging.DbLatestHeight.WithLabelValues("db_latest_height").Set(float64(dbLatestHeight)) + return nil }