Skip to content

Commit abfbce7

Browse files
authored
Report the indexed tip height as a Prometheus metric (#37)
1 parent a33e97e commit abfbce7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/new_index/schema.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::chain::{BlockHeader, Network, OutPoint, Transaction, TxOut, Value};
2424
use crate::config::Config;
2525
use crate::daemon::Daemon;
2626
use crate::errors::*;
27-
use crate::metrics::{HistogramOpts, HistogramTimer, HistogramVec, Metrics};
27+
use crate::metrics::{Gauge, HistogramOpts, HistogramTimer, HistogramVec, MetricOpts, Metrics};
2828
use crate::util::{
2929
full_hash, has_prevout, is_spendable, script_to_address, BlockHeaderMeta, BlockId, BlockMeta,
3030
BlockStatus, Bytes, HeaderEntry, HeaderList,
@@ -164,6 +164,7 @@ pub struct Indexer {
164164
from: FetchFrom,
165165
iconfig: IndexerConfig,
166166
duration: HistogramVec,
167+
tip_metric: Gauge,
167168
}
168169

169170
struct IndexerConfig {
@@ -208,6 +209,7 @@ impl Indexer {
208209
HistogramOpts::new("index_duration", "Index update duration (in seconds)"),
209210
&["step"],
210211
),
212+
tip_metric: metrics.gauge(MetricOpts::new("tip_height", "Current chain tip height")),
211213
}
212214
}
213215

@@ -296,6 +298,8 @@ impl Indexer {
296298
self.from = FetchFrom::Bitcoind;
297299
}
298300

301+
self.tip_metric.set(headers.len() as i64 - 1);
302+
299303
Ok(tip)
300304
}
301305

0 commit comments

Comments
 (0)