mirror of
https://github.com/moghtech/komodo.git
synced 2026-01-25 05:59:21 -06:00
rename stats_interval to stats_polling_rate
This commit is contained in:
@@ -246,8 +246,8 @@ pub fn gen_periphery_config(sub_matches: &ArgMatches) {
|
||||
.parse::<u16>()
|
||||
.expect("invalid port");
|
||||
|
||||
let stats_refresh_interval = sub_matches
|
||||
.get_one::<String>("stats_interval")
|
||||
let stats_polling_rate = sub_matches
|
||||
.get_one::<String>("stats_polling_rate")
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("1-sec")
|
||||
.parse::<Timelength>()
|
||||
@@ -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(),
|
||||
|
||||
@@ -119,7 +119,7 @@ fn cli() -> Command {
|
||||
.required(false)
|
||||
)
|
||||
.arg(
|
||||
arg!(--stats_interval <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 <INTERVAL> "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)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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<SystemNetwork>,
|
||||
pub polling_rate: Timelength,
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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<Arc<RwLock<StatsClient>>>;
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user