Skip to content

Commit

Permalink
Serve metrics on different port
Browse files Browse the repository at this point in the history
  • Loading branch information
poszu committed Nov 6, 2023
1 parent a466079 commit 152f4dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions certifier/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ pub struct Config {
pub post_cfg: post::config::ProofConfig,
pub init_cfg: post::config::InitConfig,

/// Whether to enable metrics on /metrics.
pub metrics: bool,
/// Address to expose metrics on.
/// Metrics are disabled if not configured.
pub metrics: Option<std::net::SocketAddr>,
}

pub fn get_configuration(config_path: &Path) -> Result<Config, config::ConfigError> {
Expand Down
14 changes: 7 additions & 7 deletions certifier/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let mut app = certifier::certifier::new(config.post_cfg, config.init_cfg, signer);

if config.metrics {
info!("metrics on: {}/metrics", config.listen.to_string());
let (metric_layer, metric_handle) = PrometheusMetricLayerBuilder::new()
if let Some(addr) = config.metrics {
info!("metrics enabled on: http://{addr:?}/metrics");
let (layer, handle) = PrometheusMetricLayerBuilder::new()
.with_prefix("certifier")
.with_ignore_patterns(&["/metrics"])
.with_default_metrics()
.build_pair();
app = app
.route("/metrics", get(|| async move { metric_handle.render() }))
.layer(metric_layer);

app = app.layer(layer);
let metrics = axum::Router::new().route("/metrics", get(|| async move { handle.render() }));
tokio::spawn(axum::Server::bind(&addr).serve(metrics.into_make_service()));
}

axum::Server::bind(&config.listen)
Expand Down

0 comments on commit 152f4dd

Please sign in to comment.