added Option to data structs
This commit is contained in:
@@ -11,7 +11,7 @@ pub mod container;
|
||||
pub mod serverclientcomm;
|
||||
pub mod stats;
|
||||
|
||||
use crate::models::{DockerRegistrationDto, DockerMetricDto, DockerContainer, DockerContainerInfo};
|
||||
use crate::models::{DockerContainer, DockerContainerInfo, DockerMetricDto, DockerRegistrationDto};
|
||||
use bollard::{query_parameters::InspectContainerOptions, Docker};
|
||||
use std::error::Error;
|
||||
|
||||
@@ -60,14 +60,20 @@ impl DockerManager {
|
||||
id: container.id,
|
||||
image: container.image,
|
||||
name: container.name,
|
||||
|
||||
}))
|
||||
}
|
||||
|
||||
/// Gets the current client version (image name) if running in Docker
|
||||
pub async fn get_client_version(&self) -> String {
|
||||
match self.get_client_container().await {
|
||||
Ok(Some(container)) => container.image.clone().unwrap().split(':').next().unwrap_or("unknown").to_string(),
|
||||
Ok(Some(container)) => container
|
||||
.image
|
||||
.clone()
|
||||
.unwrap()
|
||||
.split(':')
|
||||
.next()
|
||||
.unwrap_or("unknown")
|
||||
.to_string(),
|
||||
Ok(None) => {
|
||||
println!("Warning: No WatcherAgent container found");
|
||||
"unknown".to_string()
|
||||
@@ -118,9 +124,7 @@ impl DockerManager {
|
||||
}
|
||||
|
||||
/// Collects Docker metrics for all containers
|
||||
pub async fn collect_metrics(
|
||||
&self,
|
||||
) -> Result<DockerMetricDto, Box<dyn Error + Send + Sync>> {
|
||||
pub async fn collect_metrics(&self) -> Result<DockerMetricDto, Box<dyn Error + Send + Sync>> {
|
||||
let containers = self.get_containers().await?;
|
||||
let (cpu_stats, net_stats, mem_stats) = stats::get_container_stats(&self.docker).await?;
|
||||
|
||||
@@ -129,15 +133,15 @@ impl DockerManager {
|
||||
.map(|container| {
|
||||
let cpu = cpu_stats
|
||||
.iter()
|
||||
.find(|c| c.container_id == container.id)
|
||||
.find(|c| c.container_id == Some(container.id.clone()))
|
||||
.cloned();
|
||||
let network = net_stats
|
||||
.iter()
|
||||
.find(|n| n.container_id == container.id)
|
||||
.find(|n| n.container_id == Some(container.id.clone()))
|
||||
.cloned();
|
||||
let ram = mem_stats
|
||||
.iter()
|
||||
.find(|m| m.container_id == container.id)
|
||||
.find(|m| m.container_id == Some(container.id.clone()))
|
||||
.cloned();
|
||||
|
||||
DockerContainerInfo {
|
||||
|
||||
Reference in New Issue
Block a user