@@ -9,6 +9,9 @@ module Cardano.DbSync.Metrics (
99 setDbSlotHeight ,
1010 setDbEpochSyncDuration ,
1111 setDbEpochSyncNumber ,
12+ setDbBlocksPerSecond ,
13+ setInsertDuration ,
14+ setCacheHitRate ,
1215 makeMetrics ,
1316 withMetricSetters ,
1417 withMetricsServer ,
@@ -41,6 +44,24 @@ data Metrics = Metrics
4144 -- ^ The duration of the last epoch sync in seconds.
4245 , mDbEpochSyncNumber :: ! Gauge
4346 -- ^ The number of the last epoch that was synced.
47+ , mDbBlocksPerSecond :: ! Gauge
48+ -- ^ The number of blocks being processes per second.
49+ , mInsertDuration :: ! Gauge
50+ -- ^ The duration of the last insert operation in seconds.
51+ , mCacheStakeHitRate :: ! Gauge
52+ -- ^ Cache hit rate for stake cache.
53+ , mCachePoolsHitRate :: ! Gauge
54+ -- ^ Cache hit rate for pools cache.
55+ , mCacheDatumHitRate :: ! Gauge
56+ -- ^ Cache hit rate for datum cache.
57+ , mCacheMultiAssetsHitRate :: ! Gauge
58+ -- ^ Cache hit rate for multi_assets cache.
59+ , mCachePrevBlockHitRate :: ! Gauge
60+ -- ^ Cache hit rate for prev_block cache.
61+ , mCacheAddressHitRate :: ! Gauge
62+ -- ^ Cache hit rate for address cache.
63+ , mCacheTxIdsHitRate :: ! Gauge
64+ -- ^ Cache hit rate for tx_ids cache.
4465 }
4566
4667-- This enables us to be much more flexibile with what we actually measure.
@@ -61,6 +82,20 @@ withMetricSetters prometheusPort action =
6182 Gauge. set duration $ mDbEpochSyncDuration metrics
6283 , metricsSetDbEpochSyncNumber = \ epochNo ->
6384 Gauge. set (fromIntegral epochNo) $ mDbEpochSyncNumber metrics
85+ , metricsSetDbBlocksPerSecond = \ bps ->
86+ Gauge. set bps $ mDbBlocksPerSecond metrics
87+ , metricsSetInsertDuration = \ duration ->
88+ Gauge. set duration $ mInsertDuration metrics
89+ , metricsSetCacheHitRate = \ cacheName hitRate ->
90+ case cacheName of
91+ " stake" -> Gauge. set hitRate $ mCacheStakeHitRate metrics
92+ " pools" -> Gauge. set hitRate $ mCachePoolsHitRate metrics
93+ " datum" -> Gauge. set hitRate $ mCacheDatumHitRate metrics
94+ " multi_assets" -> Gauge. set hitRate $ mCacheMultiAssetsHitRate metrics
95+ " prev_block" -> Gauge. set hitRate $ mCachePrevBlockHitRate metrics
96+ " address" -> Gauge. set hitRate $ mCacheAddressHitRate metrics
97+ " tx_ids" -> Gauge. set hitRate $ mCacheTxIdsHitRate metrics
98+ _ -> pure ()
6499 }
65100
66101withMetricsServer :: Int -> (Metrics -> IO a ) -> IO a
@@ -83,6 +118,15 @@ makeMetrics =
83118 <*> registerGauge " cardano_db_sync_db_slot_height" mempty
84119 <*> registerGauge " cardano_db_sync_db_epoch_sync_duration_seconds" mempty
85120 <*> registerGauge " cardano_db_sync_db_epoch_sync_number" mempty
121+ <*> registerGauge " cardano_db_sync_blocks_per_second" mempty
122+ <*> registerGauge " cardano_db_sync_insert_duration_seconds" mempty
123+ <*> registerGauge " cardano_db_sync_cache_stake_hit_rate" mempty
124+ <*> registerGauge " cardano_db_sync_cache_pools_hit_rate" mempty
125+ <*> registerGauge " cardano_db_sync_cache_datum_hit_rate" mempty
126+ <*> registerGauge " cardano_db_sync_cache_multi_assets_hit_rate" mempty
127+ <*> registerGauge " cardano_db_sync_cache_prev_block_hit_rate" mempty
128+ <*> registerGauge " cardano_db_sync_cache_address_hit_rate" mempty
129+ <*> registerGauge " cardano_db_sync_cache_tx_ids_hit_rate" mempty
86130
87131setNodeBlockHeight :: MetricSetters -> WithOrigin BlockNo -> IO ()
88132setNodeBlockHeight setters woBlkNo =
@@ -102,3 +146,12 @@ setDbEpochSyncDuration = metricsSetDbEpochSyncDuration
102146
103147setDbEpochSyncNumber :: MetricSetters -> Word64 -> IO ()
104148setDbEpochSyncNumber = metricsSetDbEpochSyncNumber
149+
150+ setDbBlocksPerSecond :: MetricSetters -> Double -> IO ()
151+ setDbBlocksPerSecond = metricsSetDbBlocksPerSecond
152+
153+ setInsertDuration :: MetricSetters -> Double -> IO ()
154+ setInsertDuration = metricsSetInsertDuration
155+
156+ setCacheHitRate :: MetricSetters -> Text -> Double -> IO ()
157+ setCacheHitRate = metricsSetCacheHitRate
0 commit comments