refactor: update_container_stat combine is_alive()
This commit is contained in:
Generated
+14
-14
@@ -89,9 +89,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.93"
|
||||
version = "1.0.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775"
|
||||
checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
@@ -151,7 +151,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
"serde_urlencoded",
|
||||
"thiserror 2.0.3",
|
||||
"thiserror 2.0.4",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tower-service",
|
||||
@@ -239,9 +239,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.21"
|
||||
version = "4.5.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f"
|
||||
checksum = "69371e34337c4c984bbe322360c2547210bf632eb2814bbe78a6e87a2935bd2b"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
@@ -249,9 +249,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.21"
|
||||
version = "4.5.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec"
|
||||
checksum = "6e24c1b4099818523236a8ca881d2b45db98dadfb4625cf6608c12069fcbbde1"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@@ -556,9 +556,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "1.1.0"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258"
|
||||
checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
@@ -1481,11 +1481,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.3"
|
||||
version = "2.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa"
|
||||
checksum = "2f49a1853cf82743e3b7950f77e0f4d622ca36cf4317cba00c767838bac8d490"
|
||||
dependencies = [
|
||||
"thiserror-impl 2.0.3",
|
||||
"thiserror-impl 2.0.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1501,9 +1501,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.3"
|
||||
version = "2.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568"
|
||||
checksum = "8381894bb3efe0c4acac3ded651301ceee58a15d47c2e34885ed1908ad667061"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
||||
+41
-45
@@ -117,62 +117,58 @@ impl DockerData {
|
||||
spawn_id: SpawnId,
|
||||
spawns: Arc<Mutex<HashMap<SpawnId, JoinHandle<()>>>>,
|
||||
) {
|
||||
if state.is_alive() {
|
||||
let id = spawn_id.get_id();
|
||||
let mut stream = docker
|
||||
.stats(
|
||||
id.get(),
|
||||
Some(StatsOptions {
|
||||
stream: false,
|
||||
one_shot: false,
|
||||
}),
|
||||
)
|
||||
.take(1);
|
||||
let id = spawn_id.get_id();
|
||||
let mut stream = docker
|
||||
.stats(
|
||||
id.get(),
|
||||
Some(StatsOptions {
|
||||
stream: false,
|
||||
one_shot: false,
|
||||
}),
|
||||
)
|
||||
.take(1);
|
||||
|
||||
while let Some(Ok(stats)) = stream.next().await {
|
||||
// Memory stats are only collected if the container is alive - is this the behaviour we want?
|
||||
let mem_stat = if state.is_alive() {
|
||||
let mem_cache = stats.memory_stats.stats.map_or(0, |i| match i {
|
||||
MemoryStatsStats::V1(x) => x.inactive_file,
|
||||
MemoryStatsStats::V2(x) => x.inactive_file,
|
||||
});
|
||||
while let Some(Ok(stats)) = stream.next().await {
|
||||
// Memory stats are only collected if the container is alive - is this the behaviour we want?
|
||||
let (mem_stat, cpu_stats) = if state.is_alive() {
|
||||
let mem_cache = stats.memory_stats.stats.map_or(0, |i| match i {
|
||||
MemoryStatsStats::V1(x) => x.inactive_file,
|
||||
MemoryStatsStats::V2(x) => x.inactive_file,
|
||||
});
|
||||
(
|
||||
Some(
|
||||
stats
|
||||
.memory_stats
|
||||
.usage
|
||||
.unwrap_or_default()
|
||||
.saturating_sub(mem_cache),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
),
|
||||
Some(Self::calculate_usage(&stats)),
|
||||
)
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
let mem_limit = stats.memory_stats.limit.unwrap_or_default();
|
||||
let mem_limit = stats.memory_stats.limit.unwrap_or_default();
|
||||
|
||||
let op_key = stats
|
||||
let op_key = stats
|
||||
.networks
|
||||
.as_ref()
|
||||
.and_then(|networks| networks.keys().next().cloned());
|
||||
|
||||
let (rx, tx) = if let Some(key) = op_key {
|
||||
stats
|
||||
.networks
|
||||
.as_ref()
|
||||
.and_then(|networks| networks.keys().next().cloned());
|
||||
.unwrap_or_default()
|
||||
.get(&key)
|
||||
.map_or((0, 0), |f| (f.rx_bytes, f.tx_bytes))
|
||||
} else {
|
||||
(0, 0)
|
||||
};
|
||||
|
||||
let cpu_stats = if state.is_alive() {
|
||||
Some(Self::calculate_usage(&stats))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let (rx, tx) = if let Some(key) = op_key {
|
||||
stats
|
||||
.networks
|
||||
.unwrap_or_default()
|
||||
.get(&key)
|
||||
.map_or((0, 0), |f| (f.rx_bytes, f.tx_bytes))
|
||||
} else {
|
||||
(0, 0)
|
||||
};
|
||||
|
||||
app_data
|
||||
.lock()
|
||||
.update_stats_by_id(id, cpu_stats, mem_stat, mem_limit, rx, tx);
|
||||
}
|
||||
app_data
|
||||
.lock()
|
||||
.update_stats_by_id(id, cpu_stats, mem_stat, mem_limit, rx, tx);
|
||||
}
|
||||
spawns.lock().remove(&spawn_id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user