diff --git a/lbry/wallet/server/block_processor.py b/lbry/wallet/server/block_processor.py index dcc885ee6..00378050f 100644 --- a/lbry/wallet/server/block_processor.py +++ b/lbry/wallet/server/block_processor.py @@ -9,6 +9,7 @@ from lbry.wallet.server.daemon import DaemonError from lbry.wallet.server.hash import hash_to_hex_str, HASHX_LEN from lbry.wallet.server.util import chunks, class_logger from lbry.wallet.server.leveldb import FlushData +from lbry.wallet.server.prometheus import BLOCK_COUNT, BLOCK_UPDATE_TIMES class Prefetcher: @@ -188,14 +189,15 @@ class BlockProcessor: chain = [self.tip] + [self.coin.header_hash(h) for h in headers[:-1]] if hprevs == chain: - start = time.time() + start = time.perf_counter() await self.run_in_thread_with_lock(self.advance_blocks, blocks) await self._maybe_flush() + processed_time = time.perf_counter() - start + BLOCK_COUNT.set(self.height) + BLOCK_UPDATE_TIMES.observe(processed_time) if not self.db.first_sync: s = '' if len(blocks) == 1 else 's' - self.logger.info('processed {:,d} block{} in {:.1f}s' - .format(len(blocks), s, - time.time() - start)) + self.logger.info('processed {:,d} block{} in {:.1f}s'.format(len(blocks), s, processed_time)) if self._caught_up_event.is_set(): await self.notifications.on_block(self.touched, self.height) self.touched = set() diff --git a/lbry/wallet/server/prometheus.py b/lbry/wallet/server/prometheus.py index c0bfde613..e98c920d9 100644 --- a/lbry/wallet/server/prometheus.py +++ b/lbry/wallet/server/prometheus.py @@ -47,6 +47,10 @@ CLIENT_VERSIONS = Counter( "clients", "Number of connections received per client version", namespace=NAMESPACE, labelnames=("version",) ) +BLOCK_COUNT = Gauge( + "block_count", "Number of processed blocks", namespace=NAMESPACE +) +BLOCK_UPDATE_TIMES = Histogram("block_time", "Block update times", namespace=NAMESPACE) class PrometheusServer: