2020-02-14 13:38:33 -08:00
|
|
|
//! An HTTP endpoint for metrics collection.
|
|
|
|
|
|
|
|
use abscissa_core::{Component, FrameworkError};
|
|
|
|
|
2020-11-19 12:54:31 -08:00
|
|
|
use crate::config::ZebradConfig;
|
2020-08-06 10:29:31 -07:00
|
|
|
|
2020-02-14 13:38:33 -08:00
|
|
|
/// Abscissa component which runs a metrics endpoint.
|
|
|
|
#[derive(Debug, Component)]
|
2020-11-19 12:54:31 -08:00
|
|
|
pub struct MetricsEndpoint {}
|
2020-02-14 13:38:33 -08:00
|
|
|
|
|
|
|
impl MetricsEndpoint {
|
|
|
|
/// Create the component.
|
2020-08-06 10:29:31 -07:00
|
|
|
pub fn new(config: &ZebradConfig) -> Result<Self, FrameworkError> {
|
2020-11-19 12:54:31 -08:00
|
|
|
if let Some(addr) = config.metrics.endpoint_addr {
|
2021-01-29 04:36:33 -08:00
|
|
|
let endpoint_result = metrics_exporter_prometheus::PrometheusBuilder::new()
|
2020-11-19 12:54:31 -08:00
|
|
|
.listen_address(addr)
|
2021-01-29 04:36:33 -08:00
|
|
|
.install();
|
|
|
|
match endpoint_result {
|
|
|
|
Ok(endpoint) => {
|
|
|
|
info!("Opened metrics endpoint at {}", addr);
|
|
|
|
endpoint
|
|
|
|
}
|
|
|
|
Err(e) => panic!(
|
|
|
|
"Opening metrics endpoint listener {:?} failed: {:?}. \
|
|
|
|
Hint: Check if another zebrad or zcashd process is running. \
|
|
|
|
Try changing the metrics endpoint_addr in the Zebra config.",
|
|
|
|
addr, e,
|
|
|
|
),
|
|
|
|
}
|
2020-11-19 12:54:31 -08:00
|
|
|
}
|
|
|
|
Ok(Self {})
|
2020-02-14 13:38:33 -08:00
|
|
|
}
|
|
|
|
}
|