22//
33// Licensed under the Apache License, Version 2.0
44
5- use prometheus:: { CounterVec , Opts , Registry } ;
5+ use prometheus:: { CounterVec , Histogram , HistogramOpts , Opts , Registry } ;
66use crate :: archiver:: datakind:: DataKind ;
77use super :: Direction ;
88
99/// Metrics for the archive processing zone.
1010///
11- /// Uses two `CounterVec` metrics with ` type` and ` direction` labels:
12- /// - `items ` — total number of items (blocks, transactions, traces) processed
13- /// - `bytes ` — total number of bytes transferred to/from storage
11+ /// - `items` — counter of items (blocks, transactions, traces) processed, by type and direction
12+ /// - `bytes ` — counter of bytes transferred, by type and direction
13+ /// - `block_archive_duration ` — histogram of single-block archival time (block + txes + traces)
1414pub struct ArchiveMetrics {
1515 /// Total items processed, labeled by type and direction
1616 pub items : CounterVec ,
1717 /// Total bytes transferred, labeled by type and direction
1818 pub bytes : CounterVec ,
19+ /// Time to archive a single block with all its tables
20+ pub block_archive_duration : Histogram ,
1921}
2022
2123impl ArchiveMetrics {
2224 pub fn new ( app_name : & str ) -> Self {
25+ // Buckets tuned for the expected 500ms–2s range, with tails for slow blocks
26+ let buckets = vec ! [
27+ 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.6 , 0.7 , 0.8 , 0.9 , 1.0 ,
28+ 1.25 , 1.5 , 1.75 , 2.0 , 2.5 ,
29+ 3.0 , 4.0 , 5.0 , 7.5 , 10.0 , 12.5 , 15.0 ,
30+ 20.0 , 25.0 , 30.0 ,
31+ ] ;
2332 Self {
2433 items : CounterVec :: new (
2534 Opts :: new (
@@ -37,12 +46,21 @@ impl ArchiveMetrics {
3746 & [ "type" , "direction" ] ,
3847 )
3948 . unwrap ( ) ,
49+ block_archive_duration : Histogram :: with_opts (
50+ HistogramOpts :: new (
51+ format ! ( "{}_archive_blockTime_seconds" , app_name) ,
52+ "Time to archive a single block with all its tables (block, txes, traces)" ,
53+ )
54+ . buckets ( buckets) ,
55+ )
56+ . unwrap ( ) ,
4057 }
4158 }
4259
4360 pub fn register ( & self , registry : & Registry ) {
4461 registry. register ( Box :: new ( self . items . clone ( ) ) ) . unwrap ( ) ;
4562 registry. register ( Box :: new ( self . bytes . clone ( ) ) ) . unwrap ( ) ;
63+ registry. register ( Box :: new ( self . block_archive_duration . clone ( ) ) ) . unwrap ( ) ;
4664 }
4765
4866 /// Record that `n` items of the given data kind have been processed.
@@ -58,4 +76,9 @@ impl ArchiveMetrics {
5876 . with_label_values ( & [ kind. metrics_label ( ) , direction. metrics_label ( ) ] )
5977 . inc_by ( n as f64 ) ;
6078 }
79+
80+ /// Record the time it took to archive a single block (including txes and traces).
81+ pub fn observe_block_archive ( & self , duration_secs : f64 ) {
82+ self . block_archive_duration . observe ( duration_secs) ;
83+ }
6184}
0 commit comments