Skip to content

Commit

Permalink
Add Pebble cache metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak committed Feb 15, 2024
1 parent a0b9083 commit 23dc51e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions node/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/NethermindEth/juno/jsonrpc"
"github.com/NethermindEth/juno/l1"
"github.com/NethermindEth/juno/sync"
"github.com/cockroachdb/pebble"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -261,3 +262,42 @@ func makeGatewayMetrics() gateway.EventListener {
},
}
}

func makePebbleMetrics(nodeDB db.DB) {
pebbleDB, ok := nodeDB.Impl().(*pebble.DB)
if !ok {
return
}

blockCacheSize := prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "pebble",
Subsystem: "block_cache",
Name: "size",
}, func() float64 {
return float64(pebbleDB.Metrics().BlockCache.Size)
})
blockHitRate := prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "pebble",
Subsystem: "block_cache",
Name: "hit_rate",
}, func() float64 {
metrics := pebbleDB.Metrics()
return float64(metrics.BlockCache.Hits) / float64(metrics.BlockCache.Hits+metrics.BlockCache.Misses)
})
tableCacheSize := prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "pebble",
Subsystem: "table_cache",
Name: "size",
}, func() float64 {
return float64(pebbleDB.Metrics().TableCache.Size)
})
tableHitRate := prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "pebble",
Subsystem: "table_cache",
Name: "hit_rate",
}, func() float64 {
metrics := pebbleDB.Metrics()
return float64(metrics.TableCache.Hits) / float64(metrics.TableCache.Hits+metrics.TableCache.Misses)
})
prometheus.MustRegister(blockCacheSize, blockHitRate, tableCacheSize, tableHitRate)
}
1 change: 1 addition & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen
}
var metricsService service.Service
if cfg.Metrics {
makePebbleMetrics(database)
chain.WithListener(makeBlockchainMetrics())
makeJunoMetrics(version)
database.WithListener(makeDBMetrics())
Expand Down

0 comments on commit 23dc51e

Please sign in to comment.