Skip to content

Commit 6f59588

Browse files
committed
metrics host
1 parent e651713 commit 6f59588

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

config.example.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ SOME_ENV_VAR = "some_value"
141141
# Configuration for how metrics should be collected and scraped
142142
# OPTIONAL, skip metrics collection if missing
143143
[metrics]
144+
# Host for prometheus, grafana, and cadvisor
145+
# OPTIONAL, DEFAULT: 127.0.0.1
146+
host = "127.0.0.1"
144147
# Path to a `prometheus.yml` file to use in Prometheus. If using a custom config file, be sure to add a
145148
# file discovery section as follows:
146149
# ```yml

crates/cli/src/docker_init.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
419419
image: Some("prom/prometheus:latest".to_owned()),
420420
volumes: vec![prom_volume, targets_volume, data_volume],
421421
// to inspect prometheus from localhost
422-
ports: Ports::Short(vec!["9090:9090".to_owned()]),
422+
ports: Ports::Short(vec![format!("{}:9090", metrics_config.host)]),
423423
networks: Networks::Simple(vec![METRICS_NETWORK.to_owned()]),
424424
..Service::default()
425425
};
@@ -446,7 +446,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
446446
let grafana_service = Service {
447447
container_name: Some("cb_grafana".to_owned()),
448448
image: Some("grafana/grafana:latest".to_owned()),
449-
ports: Ports::Short(vec!["3000:3000".to_owned()]),
449+
ports: Ports::Short(vec![format!("{}:3000", metrics_config.host)]),
450450
networks: Networks::Simple(vec![METRICS_NETWORK.to_owned()]),
451451
depends_on: DependsOnOptions::Simple(vec!["cb_prometheus".to_owned()]),
452452
environment: Environment::List(vec!["GF_SECURITY_ADMIN_PASSWORD=admin".to_owned()]),
@@ -486,7 +486,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
486486
Some(Service {
487487
container_name: Some("cb_cadvisor".to_owned()),
488488
image: Some("gcr.io/cadvisor/cadvisor".to_owned()),
489-
ports: Ports::Short(vec![format!("{cadvisor_port}:8080")]),
489+
ports: Ports::Short(vec![format!("{}:8080", metrics_config.host)]),
490490
networks: Networks::Simple(vec![METRICS_NETWORK.to_owned()]),
491491
volumes: vec![
492492
Volumes::Simple("/var/run/docker.sock:/var/run/docker.sock:ro".to_owned()),

crates/common/src/config/metrics.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
use std::net::Ipv4Addr;
2+
13
use eyre::Result;
24
use serde::{Deserialize, Serialize};
35

46
use super::{constants::METRICS_PORT_ENV, load_optional_env_var};
5-
use crate::utils::default_bool;
7+
use crate::utils::{default_bool, default_host};
68

79
#[derive(Debug, Serialize, Deserialize, Clone)]
810
pub struct MetricsConfig {
11+
/// Host for prometheus, grafana, and cadvisor
12+
#[serde(default = "default_host")]
13+
pub host: Ipv4Addr,
914
/// Path to prometheus config file
1015
pub prometheus_config: String,
1116
/// Whether to start the grafana service

0 commit comments

Comments
 (0)