diff --git a/cli/src/helpers.rs b/cli/src/helpers.rs index 1685afe15..705479145 100644 --- a/cli/src/helpers.rs +++ b/cli/src/helpers.rs @@ -246,8 +246,8 @@ pub fn gen_periphery_config(sub_matches: &ArgMatches) { .parse::() .expect("invalid port"); - let stats_refresh_interval = sub_matches - .get_one::("stats_interval") + let stats_polling_rate = sub_matches + .get_one::("stats_polling_rate") .map(|p| p.as_str()) .unwrap_or("1-sec") .parse::() @@ -255,7 +255,7 @@ pub fn gen_periphery_config(sub_matches: &ArgMatches) { let config = PeripheryConfig { port, - stats_refresh_interval, + stats_polling_rate, repo_dir: "/repos".to_string(), secrets: Default::default(), github_accounts: Default::default(), diff --git a/cli/src/main.rs b/cli/src/main.rs index 9147df519..7fe108cbe 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -119,7 +119,7 @@ fn cli() -> Command { .required(false) ) .arg( - arg!(--stats_interval "sets stats refresh interval to control granularity of system stats returned. default is 1-sec. options: 1-sec, 5-sec, 10-sec, 30-sec, 1-min") + arg!(--stats_polling_rate "sets stats polling rate to control granularity of system stats returned. default is 1-sec. options: 1-sec, 5-sec, 10-sec, 30-sec, 1-min") .required(false) ) ) diff --git a/cli/src/types.rs b/cli/src/types.rs index a8761a5d0..9e580d1eb 100644 --- a/cli/src/types.rs +++ b/cli/src/types.rs @@ -74,7 +74,7 @@ pub struct PeripheryConfig { #[serde(default = "default_repo_dir")] pub repo_dir: String, #[serde(default = "default_stats_refresh_interval")] - pub stats_refresh_interval: Timelength, + pub stats_polling_rate: Timelength, #[serde(default)] pub secrets: SecretsMap, #[serde(default)] diff --git a/config_example/periphery.config.example.toml b/config_example/periphery.config.example.toml index 6a1b7a474..1ce295648 100644 --- a/config_example/periphery.config.example.toml +++ b/config_example/periphery.config.example.toml @@ -1,6 +1,6 @@ port = 9001 # optional. 9001 is default repo_dir = "/repos" # optional. /repos is default. no reason to change if running the docker container, just mount your desired repo dir to /repos in the container -stats_refresh_interval = "1-sec" # optional. 1-sec is default. can use 1-sec, 5-sec, 10-sec, 30-sec, 1-min. controls granularity of system stats recorded +stats_polling_rate = "1-sec" # optional. 1-sec is default. can use 1-sec, 5-sec, 10-sec, 30-sec, 1-min. controls granularity of system stats recorded [secrets] # optional. can inject these values into your deployments configuration. secret_variable = "secret_value" diff --git a/lib/types/src/lib.rs b/lib/types/src/lib.rs index 652352611..28e9dd47d 100644 --- a/lib/types/src/lib.rs +++ b/lib/types/src/lib.rs @@ -623,7 +623,7 @@ pub struct PeripheryConfig { #[serde(default = "default_repo_dir")] pub repo_dir: String, #[serde(default = "default_stats_refresh_interval")] - pub stats_refresh_interval: Timelength, + pub stats_polling_rate: Timelength, #[serde(default)] pub secrets: SecretsMap, #[serde(default)] @@ -659,6 +659,7 @@ pub struct SystemStats { pub mem_total_gb: f64, // in GB pub disk: DiskUsage, pub networks: Vec, + pub polling_rate: Timelength, } #[typeshare] diff --git a/periphery/src/api/mod.rs b/periphery/src/api/mod.rs index 7b3a9df73..10e9ab79d 100644 --- a/periphery/src/api/mod.rs +++ b/periphery/src/api/mod.rs @@ -16,7 +16,7 @@ pub fn router(config: &PeripheryConfig) -> Router { .route("/accounts/:account_type", get(accounts::get_accounts)) .nest("/container", container::router()) .nest("/network", network::router()) - .nest("/stats", stats::router(config.stats_refresh_interval)) + .nest("/stats", stats::router(config.stats_polling_rate)) .nest("/git", git::router()) .nest("/build", build::router()) .nest("/image", image::router()) diff --git a/periphery/src/api/stats.rs b/periphery/src/api/stats.rs index d03c9828b..54cb66f7a 100644 --- a/periphery/src/api/stats.rs +++ b/periphery/src/api/stats.rs @@ -5,7 +5,7 @@ use axum::{routing::get, Extension, Json, Router}; use sysinfo::{CpuExt, DiskExt, NetworkExt, ProcessExt, ProcessRefreshKind, SystemExt}; use types::{DiskUsage, SingleDiskUsage, SystemNetwork, SystemStats}; -pub fn router(stats_refresh_interval: Timelength) -> Router { +pub fn router(stats_polling_rate: Timelength) -> Router { Router::new() .route( "/system", @@ -14,28 +14,30 @@ pub fn router(stats_refresh_interval: Timelength) -> Router { Json(stats) }), ) - .layer(StatsClient::extension(stats_refresh_interval)) + .layer(StatsClient::extension(stats_polling_rate)) } type StatsExtension = Extension>>; struct StatsClient { sys: sysinfo::System, + polling_rate: Timelength, } const BYTES_PER_GB: f64 = 1073741824.0; const BYTES_PER_KB: f64 = 1024.0; impl StatsClient { - pub fn extension(refresh_stats_interval: Timelength) -> StatsExtension { + pub fn extension(polling_rate: Timelength) -> StatsExtension { let client = StatsClient { sys: sysinfo::System::new_all(), + polling_rate, }; let client = Arc::new(RwLock::new(client)); let clone = client.clone(); tokio::spawn(async move { loop { - wait_until_timelength(refresh_stats_interval, 0).await; + wait_until_timelength(polling_rate, 0).await; { clone.write().unwrap().refresh(); } @@ -60,6 +62,7 @@ impl StatsClient { mem_total_gb: self.sys.total_memory() as f64 / BYTES_PER_GB, disk: self.get_disk_usage(), networks: self.get_networks(), + polling_rate: self.polling_rate, } }