Skip to content

Commit

Permalink
Report the indexed tip height as a Prometheus metric (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
shesek authored Jun 25, 2021
1 parent a33e97e commit abfbce7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/new_index/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::chain::{BlockHeader, Network, OutPoint, Transaction, TxOut, Value};
use crate::config::Config;
use crate::daemon::Daemon;
use crate::errors::*;
use crate::metrics::{HistogramOpts, HistogramTimer, HistogramVec, Metrics};
use crate::metrics::{Gauge, HistogramOpts, HistogramTimer, HistogramVec, MetricOpts, Metrics};
use crate::util::{
full_hash, has_prevout, is_spendable, script_to_address, BlockHeaderMeta, BlockId, BlockMeta,
BlockStatus, Bytes, HeaderEntry, HeaderList,
Expand Down Expand Up @@ -164,6 +164,7 @@ pub struct Indexer {
from: FetchFrom,
iconfig: IndexerConfig,
duration: HistogramVec,
tip_metric: Gauge,
}

struct IndexerConfig {
Expand Down Expand Up @@ -208,6 +209,7 @@ impl Indexer {
HistogramOpts::new("index_duration", "Index update duration (in seconds)"),
&["step"],
),
tip_metric: metrics.gauge(MetricOpts::new("tip_height", "Current chain tip height")),
}
}

Expand Down Expand Up @@ -296,6 +298,8 @@ impl Indexer {
self.from = FetchFrom::Bitcoind;
}

self.tip_metric.set(headers.len() as i64 - 1);

Ok(tip)
}

Expand Down

0 comments on commit abfbce7

Please sign in to comment.