Skip to content

Commit

Permalink
Actually use config
Browse files Browse the repository at this point in the history
  • Loading branch information
kostekIV committed Feb 7, 2024
1 parent b450360 commit 66dc7f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extensions:
use_xff: true # default is false
prometheus:
port: 9616
listen_address: "0.0.0.0"
label: "dev"

middlewares:
Expand Down
10 changes: 6 additions & 4 deletions src/extensions/prometheus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use prometheus_endpoint::init_prometheus;
use prometheus_endpoint::Registry;
use serde::Deserialize;
use std::iter;
use std::net::{Ipv4Addr, SocketAddr};
use std::net::SocketAddr;
use tokio::task::JoinHandle;

pub struct Prometheus {
Expand All @@ -21,6 +21,7 @@ impl Drop for Prometheus {
#[derive(Deserialize, Debug, Clone)]
pub struct PrometheusConfig {
pub port: u16,
pub listen_address: String,
pub prefix: Option<String>,
pub chain_label: Option<String>,
}
Expand All @@ -46,7 +47,7 @@ impl Prometheus {
};
let registry = Registry::new_custom(prefix, labels).expect("Can't happen");

let exporter_task = start_prometheus_exporter(registry.clone(), config.port);
let exporter_task = start_prometheus_exporter(registry.clone(), config.port, config.listen_address);
Self {
registry,
exporter_task,
Expand All @@ -58,8 +59,9 @@ impl Prometheus {
}
}

fn start_prometheus_exporter(registry: Registry, port: u16) -> JoinHandle<()> {
let addr = SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), port);
fn start_prometheus_exporter(registry: Registry, port: u16, listen_address: String) -> JoinHandle<()> {
let address = listen_address.parse().unwrap();
let addr = SocketAddr::new(address, port);

tokio::spawn(async move {
init_prometheus(addr, registry).await.unwrap();
Expand Down

0 comments on commit 66dc7f0

Please sign in to comment.