Compare commits
3 Commits
v0.1.28
...
e02914516d
| Author | SHA1 | Date | |
|---|---|---|---|
| e02914516d | |||
| bf90d3ceb9 | |||
| a8ccb0521a |
@@ -15,12 +15,13 @@ use std::time::Duration;
|
||||
use crate::docker::serverclientcomm::handle_server_message;
|
||||
use crate::hardware::HardwareInfo;
|
||||
use crate::models::{
|
||||
Acknowledgment, DockerMetricDto, DockerRegistrationDto, HeartbeatDto, IdResponse, MetricDto,
|
||||
RegistrationDto, ServerMessage,
|
||||
Acknowledgment, DockerContainer, DockerMetricDto, DockerRegistrationDto, HeartbeatDto,
|
||||
IdResponse, MetricDto, RegistrationDto, ServerMessage,
|
||||
};
|
||||
|
||||
use anyhow::Result;
|
||||
use reqwest::{Client, StatusCode};
|
||||
use serde::Serialize;
|
||||
use std::error::Error;
|
||||
use tokio::time::sleep;
|
||||
|
||||
|
||||
@@ -134,7 +134,6 @@ impl DockerManager {
|
||||
let _ = self.debug_container_stats(&first_container.id).await;
|
||||
}
|
||||
|
||||
|
||||
// Get stats with proper error handling
|
||||
let stats_result = stats::get_container_stats(&self.docker).await;
|
||||
let (cpu_stats, net_stats, mem_stats) = match stats_result {
|
||||
@@ -146,8 +145,13 @@ impl DockerManager {
|
||||
}
|
||||
};
|
||||
|
||||
println!("Debug: Found {} containers, {} CPU stats, {} network stats, {} memory stats",
|
||||
containers.len(), cpu_stats.len(), net_stats.len(), mem_stats.len());
|
||||
println!(
|
||||
"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
|
||||
.into_iter()
|
||||
@@ -162,7 +166,8 @@ impl DockerManager {
|
||||
let cpu = cpu_stats
|
||||
.iter()
|
||||
.find(|c| {
|
||||
c.container_id.as_ref()
|
||||
c.container_id
|
||||
.as_ref()
|
||||
.map(|id| id.starts_with(container_short_id))
|
||||
.unwrap_or(false)
|
||||
})
|
||||
@@ -171,7 +176,8 @@ impl DockerManager {
|
||||
let network = net_stats
|
||||
.iter()
|
||||
.find(|n| {
|
||||
n.container_id.as_ref()
|
||||
n.container_id
|
||||
.as_ref()
|
||||
.map(|id| id.starts_with(container_short_id))
|
||||
.unwrap_or(false)
|
||||
})
|
||||
@@ -180,7 +186,8 @@ impl DockerManager {
|
||||
let ram = mem_stats
|
||||
.iter()
|
||||
.find(|m| {
|
||||
m.container_id.as_ref()
|
||||
m.container_id
|
||||
.as_ref()
|
||||
.map(|id| id.starts_with(container_short_id))
|
||||
.unwrap_or(false)
|
||||
})
|
||||
@@ -188,8 +195,13 @@ impl DockerManager {
|
||||
|
||||
// Debug output for this container
|
||||
if cpu.is_none() || network.is_none() || ram.is_none() {
|
||||
println!("Debug: Container {} - CPU: {:?}, Network: {:?}, RAM: {:?}",
|
||||
container_short_id, cpu.is_some(), network.is_some(), ram.is_some());
|
||||
println!(
|
||||
"Debug: Container {} - CPU: {:?}, Network: {:?}, RAM: {:?}",
|
||||
container_short_id,
|
||||
cpu.is_some(),
|
||||
network.is_some(),
|
||||
ram.is_some()
|
||||
);
|
||||
}
|
||||
|
||||
DockerContainerInfo {
|
||||
@@ -267,8 +279,7 @@ impl DockerManager {
|
||||
let containers = self.get_containers().await?;
|
||||
let dto = DockerRegistrationDto {
|
||||
server_id: 0, // This will be set by the caller
|
||||
containers: serde_json::to_string(&containers)
|
||||
.unwrap_or_else(|_| "[]".to_string()), // Fallback to empty array
|
||||
containers, // Fallback to empty array
|
||||
};
|
||||
|
||||
Ok(dto)
|
||||
@@ -277,11 +288,12 @@ impl DockerManager {
|
||||
/// Debug function to check stats collection for a specific container
|
||||
pub async fn debug_container_stats(
|
||||
&self,
|
||||
container_id: &str
|
||||
container_id: &str,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
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!("Network Info: {:?}", net_info);
|
||||
|
||||
@@ -117,7 +117,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
models::DockerRegistrationDto {
|
||||
server_id: 0,
|
||||
//container_count: 0, --- IGNORE ---
|
||||
containers: "[]".to_string(),
|
||||
containers: Vec::new(),
|
||||
}
|
||||
};
|
||||
let _ =
|
||||
|
||||
@@ -185,6 +185,7 @@ pub struct Acknowledgment {
|
||||
#[derive(Debug, Serialize, Clone)]
|
||||
pub struct DockerRegistrationDto {
|
||||
/// Unique server identifier (integer)
|
||||
#[serde(rename = "Server_id")]
|
||||
pub server_id: u16,
|
||||
/// Number of currently running containers
|
||||
// pub container_count: usize, --- IGNORE ---
|
||||
@@ -197,7 +198,8 @@ pub struct DockerRegistrationDto {
|
||||
/// id: unique container ID (first 12 hex digits)
|
||||
/// image: docker image name
|
||||
/// name: container name
|
||||
pub containers: String, // Vec<DockerContainer>,
|
||||
#[serde(rename = "Containers")]
|
||||
pub containers: Vec<DockerContainer>, // Vec<DockerContainer>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Clone)]
|
||||
@@ -257,6 +259,8 @@ pub struct DockerContainerInfo {
|
||||
#[derive(Debug, Serialize, Clone)]
|
||||
pub struct DockerContainer {
|
||||
pub id: String,
|
||||
#[serde(default)]
|
||||
pub image: Option<String>,
|
||||
#[serde(default)]
|
||||
pub name: Option<String>,
|
||||
}
|
||||
|
||||
44
docker-compose.example.yaml
Normal file
44
docker-compose.example.yaml
Normal file
@@ -0,0 +1,44 @@
|
||||
networks:
|
||||
watcher-network:
|
||||
driver: bridge
|
||||
|
||||
services:
|
||||
watcher:
|
||||
image: git.triggermeelmo.com/watcher/watcher-server:v0.1.11
|
||||
container_name: watcher
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 200M
|
||||
restart: unless-stopped
|
||||
env_file: .env
|
||||
ports:
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
- ./watcher-volumes/data:/app/persistence
|
||||
- ./watcher-volumes/dumps:/app/wwwroot/downloads/sqlite
|
||||
- ./watcher-volumes/logs:/app/logs
|
||||
|
||||
watcher-agent:
|
||||
image: git.triggermeelmo.com/donpat1to/watcher-agent:v0.1.28
|
||||
container_name: watcher-agent
|
||||
restart: always
|
||||
privileged: true # Grants full hardware access (use with caution)
|
||||
env_file: .env
|
||||
pid: "host"
|
||||
volumes:
|
||||
# Mount critical system paths for hardware monitoring
|
||||
- /sys:/sys:ro # CPU/GPU temps, sensors
|
||||
- /proc:/proc # Process/CPU stats
|
||||
- /dev:/dev:ro # Disk/GPU device access
|
||||
- /var/run/docker.sock:/var/run/docker.sock # Docker API access
|
||||
- /:/root:ro # Access to for df-command
|
||||
# Application volumes
|
||||
- ./config:/app/config:ro
|
||||
- ./logs:/app/logs
|
||||
network_mode: host # Uses host network (for correct IP/interface detection)
|
||||
healthcheck:
|
||||
test: [ "CMD", "/usr/local/bin/WatcherAgent", "healthcheck" ]
|
||||
interval: 30s
|
||||
timeout: 3s
|
||||
retries: 3
|
||||
@@ -1,23 +1,20 @@
|
||||
watcher-agent:
|
||||
image: git.triggermeelmo.com/donpat1to/watcher-agent:development
|
||||
container_name: watcher-agent
|
||||
restart: always
|
||||
privileged: true # Grants full hardware access (use with caution)
|
||||
networks:
|
||||
watcher-network:
|
||||
driver: bridge
|
||||
|
||||
services:
|
||||
watcher:
|
||||
image: git.triggermeelmo.com/watcher/watcher-server:v0.1.11
|
||||
container_name: watcher
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 200M
|
||||
restart: unless-stopped
|
||||
env_file: .env
|
||||
pid: "host"
|
||||
ports:
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
# Mount critical system paths for hardware monitoring
|
||||
- /sys:/sys:ro # CPU/GPU temps, sensors
|
||||
- /proc:/proc # Process/CPU stats
|
||||
- /dev:/dev:ro # Disk/GPU device access
|
||||
- /var/run/docker.sock:/var/run/docker.sock # Docker API access
|
||||
- /:/root:ro # Access to for df-command
|
||||
# Application volumes
|
||||
- ./config:/app/config:ro
|
||||
- ./logs:/app/logs
|
||||
network_mode: host # Uses host network (for correct IP/interface detection)
|
||||
healthcheck:
|
||||
test: ["CMD", "/usr/local/bin/WatcherAgent", "healthcheck"]
|
||||
interval: 30s
|
||||
timeout: 3s
|
||||
retries: 3
|
||||
- ./watcher-volumes/data:/app/persistence
|
||||
- ./watcher-volumes/dumps:/app/wwwroot/downloads/sqlite
|
||||
- ./watcher-volumes/logs:/app/logs
|
||||
|
||||
Reference in New Issue
Block a user