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