updated models to parse json better
All checks were successful
Rust Cross-Platform Build / Detect Rust Project (push) Successful in 4s
Rust Cross-Platform Build / Run Tests (push) Successful in 1m19s
Rust Cross-Platform Build / Build (x86_64-unknown-linux-gnu) (push) Successful in 3m28s
Rust Cross-Platform Build / Build (x86_64-pc-windows-gnu) (push) Successful in 4m26s
Rust Cross-Platform Build / Set Tag Name (push) Successful in 4s
Rust Cross-Platform Build / Build and Push Docker Image (push) Successful in 2m31s
Rust Cross-Platform Build / Workflow Summary (push) Successful in 2s
Rust Cross-Platform Build / Create Tag (push) Successful in 5s
All checks were successful
Rust Cross-Platform Build / Detect Rust Project (push) Successful in 4s
Rust Cross-Platform Build / Run Tests (push) Successful in 1m19s
Rust Cross-Platform Build / Build (x86_64-unknown-linux-gnu) (push) Successful in 3m28s
Rust Cross-Platform Build / Build (x86_64-pc-windows-gnu) (push) Successful in 4m26s
Rust Cross-Platform Build / Set Tag Name (push) Successful in 4s
Rust Cross-Platform Build / Build and Push Docker Image (push) Successful in 2m31s
Rust Cross-Platform Build / Workflow Summary (push) Successful in 2s
Rust Cross-Platform Build / Create Tag (push) Successful in 5s
This commit is contained in:
@@ -15,12 +15,13 @@ use std::time::Duration;
|
|||||||
use crate::docker::serverclientcomm::handle_server_message;
|
use crate::docker::serverclientcomm::handle_server_message;
|
||||||
use crate::hardware::HardwareInfo;
|
use crate::hardware::HardwareInfo;
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
Acknowledgment, DockerMetricDto, DockerRegistrationDto, HeartbeatDto, IdResponse, MetricDto,
|
Acknowledgment, DockerContainer, DockerMetricDto, DockerRegistrationDto, HeartbeatDto,
|
||||||
RegistrationDto, ServerMessage,
|
IdResponse, MetricDto, RegistrationDto, ServerMessage,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use reqwest::{Client, StatusCode};
|
use reqwest::{Client, StatusCode};
|
||||||
|
use serde::Serialize;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,6 @@ impl DockerManager {
|
|||||||
let _ = self.debug_container_stats(&first_container.id).await;
|
let _ = self.debug_container_stats(&first_container.id).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get stats with proper error handling
|
// Get stats with proper error handling
|
||||||
let stats_result = stats::get_container_stats(&self.docker).await;
|
let stats_result = stats::get_container_stats(&self.docker).await;
|
||||||
let (cpu_stats, net_stats, mem_stats) = match stats_result {
|
let (cpu_stats, net_stats, mem_stats) = match stats_result {
|
||||||
@@ -146,41 +145,49 @@ impl DockerManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("Debug: Found {} containers, {} CPU stats, {} network stats, {} memory stats",
|
println!(
|
||||||
containers.len(), cpu_stats.len(), net_stats.len(), mem_stats.len());
|
"Debug: Found {} containers, {} CPU stats, {} network stats, {} memory stats",
|
||||||
|
containers.len(),
|
||||||
|
cpu_stats.len(),
|
||||||
|
net_stats.len(),
|
||||||
|
mem_stats.len()
|
||||||
|
);
|
||||||
|
|
||||||
let container_infos_total: Vec<_> = containers
|
let container_infos_total: Vec<_> = containers
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|container| {
|
.map(|container| {
|
||||||
// Use short ID for matching (first 12 chars)
|
// Use short ID for matching (first 12 chars)
|
||||||
let container_short_id = if container.id.len() > 12 {
|
let container_short_id = if container.id.len() > 12 {
|
||||||
&container.id[..12]
|
&container.id[..12]
|
||||||
} else {
|
} else {
|
||||||
&container.id
|
&container.id
|
||||||
};
|
};
|
||||||
|
|
||||||
let cpu = cpu_stats
|
let cpu = cpu_stats
|
||||||
.iter()
|
.iter()
|
||||||
.find(|c| {
|
.find(|c| {
|
||||||
c.container_id.as_ref()
|
c.container_id
|
||||||
|
.as_ref()
|
||||||
.map(|id| id.starts_with(container_short_id))
|
.map(|id| id.starts_with(container_short_id))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
})
|
})
|
||||||
.cloned();
|
.cloned();
|
||||||
|
|
||||||
let network = net_stats
|
let network = net_stats
|
||||||
.iter()
|
.iter()
|
||||||
.find(|n| {
|
.find(|n| {
|
||||||
n.container_id.as_ref()
|
n.container_id
|
||||||
|
.as_ref()
|
||||||
.map(|id| id.starts_with(container_short_id))
|
.map(|id| id.starts_with(container_short_id))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
})
|
})
|
||||||
.cloned();
|
.cloned();
|
||||||
|
|
||||||
let ram = mem_stats
|
let ram = mem_stats
|
||||||
.iter()
|
.iter()
|
||||||
.find(|m| {
|
.find(|m| {
|
||||||
m.container_id.as_ref()
|
m.container_id
|
||||||
|
.as_ref()
|
||||||
.map(|id| id.starts_with(container_short_id))
|
.map(|id| id.starts_with(container_short_id))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
})
|
})
|
||||||
@@ -188,8 +195,13 @@ impl DockerManager {
|
|||||||
|
|
||||||
// Debug output for this container
|
// Debug output for this container
|
||||||
if cpu.is_none() || network.is_none() || ram.is_none() {
|
if cpu.is_none() || network.is_none() || ram.is_none() {
|
||||||
println!("Debug: Container {} - CPU: {:?}, Network: {:?}, RAM: {:?}",
|
println!(
|
||||||
container_short_id, cpu.is_some(), network.is_some(), ram.is_some());
|
"Debug: Container {} - CPU: {:?}, Network: {:?}, RAM: {:?}",
|
||||||
|
container_short_id,
|
||||||
|
cpu.is_some(),
|
||||||
|
network.is_some(),
|
||||||
|
ram.is_some()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
DockerContainerInfo {
|
DockerContainerInfo {
|
||||||
@@ -267,8 +279,7 @@ impl DockerManager {
|
|||||||
let containers = self.get_containers().await?;
|
let containers = self.get_containers().await?;
|
||||||
let dto = DockerRegistrationDto {
|
let dto = DockerRegistrationDto {
|
||||||
server_id: 0, // This will be set by the caller
|
server_id: 0, // This will be set by the caller
|
||||||
containers: serde_json::to_string(&containers)
|
containers, // Fallback to empty array
|
||||||
.unwrap_or_else(|_| "[]".to_string()), // Fallback to empty array
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(dto)
|
Ok(dto)
|
||||||
@@ -276,36 +287,37 @@ impl DockerManager {
|
|||||||
|
|
||||||
/// Debug function to check stats collection for a specific container
|
/// Debug function to check stats collection for a specific container
|
||||||
pub async fn debug_container_stats(
|
pub async fn debug_container_stats(
|
||||||
&self,
|
&self,
|
||||||
container_id: &str
|
container_id: &str,
|
||||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
println!("=== DEBUG STATS FOR CONTAINER {} ===", container_id);
|
println!("=== DEBUG STATS FOR CONTAINER {} ===", container_id);
|
||||||
|
|
||||||
let (cpu_info, net_info, mem_info) = stats::get_single_container_stats(&self.docker, container_id).await?;
|
let (cpu_info, net_info, mem_info) =
|
||||||
|
stats::get_single_container_stats(&self.docker, container_id).await?;
|
||||||
|
|
||||||
println!("CPU Info: {:?}", cpu_info);
|
println!("CPU Info: {:?}", cpu_info);
|
||||||
println!("Network Info: {:?}", net_info);
|
println!("Network Info: {:?}", net_info);
|
||||||
println!("Memory Info: {:?}", mem_info);
|
println!("Memory Info: {:?}", mem_info);
|
||||||
|
|
||||||
// Also try the individual stats functions
|
// Also try the individual stats functions
|
||||||
println!("--- Individual CPU Stats ---");
|
println!("--- Individual CPU Stats ---");
|
||||||
match stats::cpu::get_single_container_cpu_stats(&self.docker, container_id).await {
|
match stats::cpu::get_single_container_cpu_stats(&self.docker, container_id).await {
|
||||||
Ok(cpu) => println!("CPU: {:?}", cpu),
|
Ok(cpu) => println!("CPU: {:?}", cpu),
|
||||||
Err(e) => println!("CPU Error: {}", e),
|
Err(e) => println!("CPU Error: {}", e),
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("--- Individual Network Stats ---");
|
println!("--- Individual Network Stats ---");
|
||||||
match stats::network::get_single_container_network_stats(&self.docker, container_id).await {
|
match stats::network::get_single_container_network_stats(&self.docker, container_id).await {
|
||||||
Ok(net) => println!("Network: {:?}", net),
|
Ok(net) => println!("Network: {:?}", net),
|
||||||
Err(e) => println!("Network Error: {}", e),
|
Err(e) => println!("Network Error: {}", e),
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("--- Individual Memory Stats ---");
|
println!("--- Individual Memory Stats ---");
|
||||||
match stats::ram::get_single_container_memory_stats(&self.docker, container_id).await {
|
match stats::ram::get_single_container_memory_stats(&self.docker, container_id).await {
|
||||||
Ok(mem) => println!("Memory: {:?}", mem),
|
Ok(mem) => println!("Memory: {:?}", mem),
|
||||||
Err(e) => println!("Memory Error: {}", e),
|
Err(e) => println!("Memory Error: {}", e),
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -326,4 +338,4 @@ impl DockerContainer {
|
|||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
&self.name.as_deref().unwrap_or("unknown")
|
&self.name.as_deref().unwrap_or("unknown")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
|||||||
models::DockerRegistrationDto {
|
models::DockerRegistrationDto {
|
||||||
server_id: 0,
|
server_id: 0,
|
||||||
//container_count: 0, --- IGNORE ---
|
//container_count: 0, --- IGNORE ---
|
||||||
containers: "[]".to_string(),
|
containers: Vec::new(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let _ =
|
let _ =
|
||||||
|
|||||||
@@ -185,6 +185,7 @@ pub struct Acknowledgment {
|
|||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
pub struct DockerRegistrationDto {
|
pub struct DockerRegistrationDto {
|
||||||
/// Unique server identifier (integer)
|
/// Unique server identifier (integer)
|
||||||
|
#[serde(rename = "Server_id")]
|
||||||
pub server_id: u16,
|
pub server_id: u16,
|
||||||
/// Number of currently running containers
|
/// Number of currently running containers
|
||||||
// pub container_count: usize, --- IGNORE ---
|
// pub container_count: usize, --- IGNORE ---
|
||||||
@@ -197,7 +198,8 @@ pub struct DockerRegistrationDto {
|
|||||||
/// id: unique container ID (first 12 hex digits)
|
/// id: unique container ID (first 12 hex digits)
|
||||||
/// image: docker image name
|
/// image: docker image name
|
||||||
/// name: container name
|
/// name: container name
|
||||||
pub containers: String, // Vec<DockerContainer>,
|
#[serde(rename = "Containers")]
|
||||||
|
pub containers: Vec<DockerContainer>, // Vec<DockerContainer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
@@ -257,6 +259,8 @@ pub struct DockerContainerInfo {
|
|||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
pub struct DockerContainer {
|
pub struct DockerContainer {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
#[serde(default)]
|
||||||
pub image: Option<String>,
|
pub image: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user