moved stats into own folder
Some checks failed
Rust Cross-Platform Build / Detect Rust Project (push) Successful in 4s
Rust Cross-Platform Build / Run Tests (push) Failing after 1m9s
Rust Cross-Platform Build / Build (x86_64-unknown-linux-gnu) (push) Has been skipped
Rust Cross-Platform Build / Build (x86_64-pc-windows-gnu) (push) Has been skipped
Rust Cross-Platform Build / Set Tag Name (push) Has been skipped
Rust Cross-Platform Build / Build and Push Docker Image (push) Has been skipped
Rust Cross-Platform Build / Create Tag (push) Has been skipped
Rust Cross-Platform Build / Workflow Summary (push) Successful in 2s
Some checks failed
Rust Cross-Platform Build / Detect Rust Project (push) Successful in 4s
Rust Cross-Platform Build / Run Tests (push) Failing after 1m9s
Rust Cross-Platform Build / Build (x86_64-unknown-linux-gnu) (push) Has been skipped
Rust Cross-Platform Build / Build (x86_64-pc-windows-gnu) (push) Has been skipped
Rust Cross-Platform Build / Set Tag Name (push) Has been skipped
Rust Cross-Platform Build / Build and Push Docker Image (push) Has been skipped
Rust Cross-Platform Build / Create Tag (push) Has been skipped
Rust Cross-Platform Build / Workflow Summary (push) Successful in 2s
This commit is contained in:
@@ -55,18 +55,19 @@ impl DockerManager {
|
||||
|
||||
Ok(containers
|
||||
.into_iter()
|
||||
.find(|c| c.image.contains(client_image))
|
||||
.find(|c| c.clone().image.unwrap().contains(client_image))
|
||||
.map(|container| DockerContainer {
|
||||
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.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()
|
||||
@@ -102,60 +103,7 @@ impl DockerManager {
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Gets container metrics for all containers
|
||||
pub async fn get_container_metrics(
|
||||
&self,
|
||||
) -> Result<Vec<DockerContainer>, Box<dyn Error + Send + Sync>> {
|
||||
let containers = container::get_available_containers(&self.docker).await;
|
||||
let mut metrics = Vec::new();
|
||||
|
||||
for container in containers {
|
||||
// Get network stats (you'll need to implement this in container.rs)
|
||||
let network_stats = container::get_network_stats(&self.docker, &container.id).await?;
|
||||
// Get CPU stats (you'll need to implement this in container.rs)
|
||||
let cpu_stats = container::get_cpu_stats(&self.docker, &container.id).await?;
|
||||
|
||||
// Get current status by inspecting the container
|
||||
let status = match self
|
||||
.docker
|
||||
.inspect_container(&container.id, None::<InspectContainerOptions>)
|
||||
.await
|
||||
{
|
||||
Ok(container_info) => {
|
||||
// Extract status from container state and convert to string
|
||||
container_info
|
||||
.state
|
||||
.and_then(|state| state.status)
|
||||
.map(|status_enum| {
|
||||
match status_enum {
|
||||
bollard::models::ContainerStateStatusEnum::CREATED => "created",
|
||||
bollard::models::ContainerStateStatusEnum::RUNNING => "running",
|
||||
bollard::models::ContainerStateStatusEnum::PAUSED => "paused",
|
||||
bollard::models::ContainerStateStatusEnum::RESTARTING => {
|
||||
"restarting"
|
||||
}
|
||||
bollard::models::ContainerStateStatusEnum::REMOVING => "removing",
|
||||
bollard::models::ContainerStateStatusEnum::EXITED => "exited",
|
||||
bollard::models::ContainerStateStatusEnum::DEAD => "dead",
|
||||
bollard::secret::ContainerStateStatusEnum::EMPTY => todo!(),
|
||||
}
|
||||
.to_string()
|
||||
})
|
||||
.unwrap_or_else(|| "unknown".to_string())
|
||||
}
|
||||
Err(_) => "unknown".to_string(),
|
||||
};
|
||||
|
||||
metrics.push(DockerContainerMetricDto {
|
||||
server_id: container.id,
|
||||
status: status,
|
||||
network: network_stats,
|
||||
cpu: cpu_stats,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(metrics)
|
||||
}
|
||||
|
||||
|
||||
/// Gets the number of running containers
|
||||
pub async fn get_container_count(&self) -> Result<usize, Box<dyn Error + Send + Sync>> {
|
||||
@@ -170,18 +118,6 @@ impl DockerManager {
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
container::restart_container(&self.docker, container_id).await
|
||||
}
|
||||
|
||||
/// Gets total network statistics across all containers
|
||||
pub async fn get_total_network_stats(
|
||||
&self,
|
||||
) -> Result<(u64, u64), Box<dyn Error + Send + Sync>> {
|
||||
let metrics = self.get_container_metrics().await?;
|
||||
|
||||
let net_in_total: u64 = metrics.iter().map(|m| m.network.rx_bytes).sum();
|
||||
let net_out_total: u64 = metrics.iter().map(|m| m.network.tx_bytes).sum();
|
||||
|
||||
Ok((net_in_total, net_out_total))
|
||||
}
|
||||
}
|
||||
|
||||
// Keep these as utility functions if needed, but they should use DockerManager internally
|
||||
@@ -193,11 +129,11 @@ impl DockerContainer {
|
||||
|
||||
/// Returns the image name
|
||||
pub fn image(&self) -> &str {
|
||||
&self.image
|
||||
&self.image.as_deref().unwrap_or("unknown")
|
||||
}
|
||||
|
||||
/// Returns the container name
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
&self.name.as_deref().unwrap_or("unknown")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user