fix: docker_data unwrap()
use a match clause to remove an unwrap() from the network_stats section of update_container_stat
This commit is contained in:
+10
-8
@@ -34,8 +34,8 @@ impl DockerData {
|
|||||||
if stats.cpu_stats.system_cpu_usage.is_some()
|
if stats.cpu_stats.system_cpu_usage.is_some()
|
||||||
&& stats.precpu_stats.system_cpu_usage.is_some()
|
&& stats.precpu_stats.system_cpu_usage.is_some()
|
||||||
{
|
{
|
||||||
let system_delta = (stats.cpu_stats.system_cpu_usage.unwrap()
|
let system_delta = (stats.cpu_stats.system_cpu_usage.unwrap_or(0)
|
||||||
- stats.precpu_stats.system_cpu_usage.unwrap())
|
- stats.precpu_stats.system_cpu_usage.unwrap_or(0))
|
||||||
as f64;
|
as f64;
|
||||||
let online_cpus = stats.cpu_stats.online_cpus.unwrap_or_else(|| {
|
let online_cpus = stats.cpu_stats.online_cpus.unwrap_or_else(|| {
|
||||||
stats
|
stats
|
||||||
@@ -75,7 +75,7 @@ impl DockerData {
|
|||||||
let mem_stat = stats.memory_stats.usage.unwrap_or(0);
|
let mem_stat = stats.memory_stats.usage.unwrap_or(0);
|
||||||
let mem_limit = stats.memory_stats.limit.unwrap_or(0);
|
let mem_limit = stats.memory_stats.limit.unwrap_or(0);
|
||||||
|
|
||||||
let key = if let Some(networks) = &stats.networks {
|
let some_key = if let Some(networks) = &stats.networks {
|
||||||
networks.keys().next().map(|x| x.to_owned())
|
networks.keys().next().map(|x| x.to_owned())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -83,12 +83,14 @@ impl DockerData {
|
|||||||
|
|
||||||
let cpu_stats = Self::calculate_usage(&stats);
|
let cpu_stats = Self::calculate_usage(&stats);
|
||||||
|
|
||||||
let (rx, tx) = if let Some(k) = key {
|
let no_bytes = (0, 0);
|
||||||
let ii = stats.networks.unwrap();
|
let (rx, tx) = if let Some(key) = some_key {
|
||||||
let v = ii.get(&k).unwrap();
|
match stats.networks.unwrap_or_default().get(&key) {
|
||||||
(v.rx_bytes.to_owned(), v.tx_bytes.to_owned())
|
Some(data) => (data.rx_bytes.to_owned(), data.tx_bytes.to_owned()),
|
||||||
|
None => no_bytes,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
(0, 0)
|
no_bytes
|
||||||
};
|
};
|
||||||
|
|
||||||
if is_running {
|
if is_running {
|
||||||
|
|||||||
Reference in New Issue
Block a user