diff --git a/pkg/prom/db_stats_collector.go b/pkg/prom/db_stats_collector.go index 738f60d..3dc1223 100644 --- a/pkg/prom/db_stats_collector.go +++ b/pkg/prom/db_stats_collector.go @@ -23,7 +23,7 @@ import ( ) const ( - namespace = "eth-statediff-service" + namespace = "eth_statediff_service" subsystem = "connections" ) diff --git a/pkg/prom/prom.go b/pkg/prom/prom.go index dee6167..61f5a8a 100644 --- a/pkg/prom/prom.go +++ b/pkg/prom/prom.go @@ -38,43 +38,52 @@ var ( tTxCommit prometheus.Histogram ) +const ( + LOADED_HEIGHT = "loaded_height" + PROCESSED_HEIGHT = "processed_height" + T_BLOCK_LOAD = "t_block_load" + T_BLOCK_PROCESSING = "t_block_processing" + T_STATE_PROCESSING = "t_state_processing" + T_POSTGRES_TX_COMMIT = "t_postgres_tx_commit" +) + // Init module initialization func Init() { metrics = true lastLoadedHeight = promauto.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, - Name: "loaded_height", + Name: LOADED_HEIGHT, Help: "The last block that was loaded for processing", }) lastProcessedHeight = promauto.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, - Name: "processed_height", + Name: PROCESSED_HEIGHT, Help: "The last block that was processed", }) tBlockLoad = promauto.NewHistogram(prometheus.HistogramOpts{ Namespace: namespace, Subsystem: statsSubsystem, - Name: "t_block_load", + Name: T_BLOCK_LOAD, Help: "Block loading time", }) tBlockProcessing = promauto.NewHistogram(prometheus.HistogramOpts{ Namespace: namespace, Subsystem: statsSubsystem, - Name: "t_block_processing", + Name: T_BLOCK_PROCESSING, Help: "Block (header, uncles, txs, rcts, tx trie, rct trie) processing time", }) tStateProcessing = promauto.NewHistogram(prometheus.HistogramOpts{ Namespace: namespace, Subsystem: statsSubsystem, - Name: "t_state_processing", + Name: T_STATE_PROCESSING, Help: "State (state trie, storage tries, and code) processing time", }) tTxCommit = promauto.NewHistogram(prometheus.HistogramOpts{ Namespace: namespace, Subsystem: statsSubsystem, - Name: "t_postgres_tx_commit", + Name: T_POSTGRES_TX_COMMIT, Help: "Postgres tx commit time", }) } @@ -107,13 +116,13 @@ func SetTimeMetric(name string, t time.Duration) { } tAsF64 := t.Seconds() switch name { - case "t_block_load": + case T_BLOCK_LOAD: tBlockLoad.Observe(tAsF64) - case "t_block_processing": + case T_BLOCK_PROCESSING: tBlockProcessing.Observe(tAsF64) - case "t_state_processing": + case T_STATE_PROCESSING: tStateProcessing.Observe(tAsF64) - case "t_postgres_tx_commit": + case T_POSTGRES_TX_COMMIT: tTxCommit.Observe(tAsF64) } } diff --git a/pkg/service.go b/pkg/service.go index 00f02dd..360b936 100644 --- a/pkg/service.go +++ b/pkg/service.go @@ -309,7 +309,7 @@ func (sds *Service) writeStateDiff(block *types.Block, parentRoot common.Hash, p } height := block.Number().Int64() prom.SetLastLoadedHeight(height) - prom.SetTimeMetric("t_block_load", time.Now().Sub(t)) + prom.SetTimeMetric(prom.T_BLOCK_LOAD, time.Now().Sub(t)) t = time.Now() tx, err := sds.indexer.PushBlock(block, receipts, totalDifficulty) if err != nil { @@ -322,16 +322,16 @@ func (sds *Service) writeStateDiff(block *types.Block, parentRoot common.Hash, p codeOutput := func(c sdtypes.CodeAndCodeHash) error { return sds.indexer.PushCodeAndCodeHash(tx, c) } - prom.SetTimeMetric("t_block_processing", time.Now().Sub(t)) + prom.SetTimeMetric(prom.T_BLOCK_PROCESSING, time.Now().Sub(t)) t = time.Now() err = sds.Builder.WriteStateDiffObject(sd.StateRoots{ NewStateRoot: block.Root(), OldStateRoot: parentRoot, }, params, output, codeOutput) - prom.SetTimeMetric("t_state_processing", time.Now().Sub(t)) + prom.SetTimeMetric(prom.T_STATE_PROCESSING, time.Now().Sub(t)) t = time.Now() err = tx.Close(err) prom.SetLastProcessedHeight(height) - prom.SetTimeMetric("t_postgres_tx_commit", time.Now().Sub(t)) + prom.SetTimeMetric(prom.T_POSTGRES_TX_COMMIT, time.Now().Sub(t)) return err }