Skip to content

Commit

Permalink
feat: add DbLatestHeight metric to prometheus (#88)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
huichiaotsou authored Dec 30, 2022
1 parent 86c1cc5 commit 4ad38b4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 14 additions & 0 deletions logging/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -70,4 +79,9 @@ func init() {
if err != nil {
panic(err)
}

err = prometheus.Register(DbLatestHeight)
if err != nil {
panic(err)
}
}
6 changes: 6 additions & 0 deletions parser/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 4ad38b4

Please sign in to comment.