Compare commits
2 Commits
v0.1.31
...
c165ee9cc2
| Author | SHA1 | Date | |
|---|---|---|---|
| c165ee9cc2 | |||
| 7d6b5165c1 |
@@ -15,7 +15,7 @@ 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,
|
Acknowledgment, DockerMetricDto, DockerServiceDto, HeartbeatDto,
|
||||||
IdResponse, MetricDto, RegistrationDto, ServerMessage,
|
IdResponse, MetricDto, RegistrationDto, ServerMessage,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ async fn get_server_id_by_ip(
|
|||||||
pub async fn broadcast_docker_containers(
|
pub async fn broadcast_docker_containers(
|
||||||
base_url: &str,
|
base_url: &str,
|
||||||
server_id: u16,
|
server_id: u16,
|
||||||
container_dto: &DockerRegistrationDto,
|
container_dto: &DockerServiceDto,
|
||||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
// First get local IP
|
// First get local IP
|
||||||
println!("Preparing to broadcast docker containers...");
|
println!("Preparing to broadcast docker containers...");
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ pub mod stats;
|
|||||||
|
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
DockerCollectMetricDto, DockerContainer, DockerContainerCpuDto, DockerContainerInfo,
|
DockerCollectMetricDto, DockerContainer, DockerContainerCpuDto, DockerContainerInfo,
|
||||||
DockerContainerNetworkDto, DockerContainerRamDto, DockerMetricDto, DockerRegistrationDto,
|
DockerContainerNetworkDto, DockerContainerRamDto, DockerMetricDto, DockerServiceDto,
|
||||||
DockerContainerStatusDto
|
DockerContainerStatusDto
|
||||||
};
|
};
|
||||||
use bollard::Docker;
|
use bollard::Docker;
|
||||||
@@ -238,7 +238,7 @@ impl DockerManager {
|
|||||||
let container_infos: Vec<DockerCollectMetricDto> = container_infos_total
|
let container_infos: Vec<DockerCollectMetricDto> = container_infos_total
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|info| {
|
.filter_map(|info| {
|
||||||
let container = match info.container {
|
let _container = match info.container {
|
||||||
Some(c) => c,
|
Some(c) => c,
|
||||||
None => {
|
None => {
|
||||||
eprintln!("Warning: Container info missing container data, skipping");
|
eprintln!("Warning: Container info missing container data, skipping");
|
||||||
@@ -286,7 +286,7 @@ impl DockerManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Some(DockerCollectMetricDto {
|
Some(DockerCollectMetricDto {
|
||||||
id: container.id,
|
server_id: 0,
|
||||||
status: status_dto,
|
status: status_dto,
|
||||||
cpu: cpu_dto,
|
cpu: cpu_dto,
|
||||||
ram: ram_dto,
|
ram: ram_dto,
|
||||||
@@ -305,12 +305,12 @@ impl DockerManager {
|
|||||||
|
|
||||||
pub async fn create_registration_dto(
|
pub async fn create_registration_dto(
|
||||||
&self,
|
&self,
|
||||||
) -> Result<DockerRegistrationDto, Box<dyn Error + Send + Sync>> {
|
) -> Result<DockerServiceDto, Box<dyn Error + Send + Sync>> {
|
||||||
let containers = self.get_containers().await?;
|
let containers = self.get_containers().await?;
|
||||||
|
|
||||||
let container_string = serde_json::to_value(&containers)?;
|
let container_string = serde_json::to_value(&containers)?;
|
||||||
|
|
||||||
let dto = DockerRegistrationDto {
|
let dto = DockerServiceDto {
|
||||||
server_id: 0, // This will be set by the caller
|
server_id: 0, // This will be set by the caller
|
||||||
containers: container_string,
|
containers: container_string,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
|||||||
docker_manager.create_registration_dto().await?
|
docker_manager.create_registration_dto().await?
|
||||||
} else {
|
} else {
|
||||||
println!("Fallback for failing registration");
|
println!("Fallback for failing registration");
|
||||||
models::DockerRegistrationDto {
|
models::DockerServiceDto {
|
||||||
server_id: 0,
|
server_id: 0,
|
||||||
//container_count: 0, --- IGNORE ---
|
//container_count: 0, --- IGNORE ---
|
||||||
containers: serde_json::to_value(&"")?,
|
containers: serde_json::to_value(&"")?,
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ pub struct ServerMessage {
|
|||||||
// Define your message structure here
|
// Define your message structure here
|
||||||
pub message_type: String,
|
pub message_type: String,
|
||||||
pub data: serde_json::Value,
|
pub data: serde_json::Value,
|
||||||
pub message_id: String, // Add an ID for acknowledgment
|
pub message_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Acknowledgment payload sent to the backend server for command messages.
|
/// Acknowledgment payload sent to the backend server for command messages.
|
||||||
@@ -184,7 +184,7 @@ pub struct Acknowledgment {
|
|||||||
/// - `Name`: Container name (string)
|
/// - `Name`: Container name (string)
|
||||||
/// - `Status`: Container status ("running", "stopped", etc.)
|
/// - `Status`: Container status ("running", "stopped", etc.)
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
pub struct DockerRegistrationDto {
|
pub struct DockerServiceDto {
|
||||||
/// Unique server identifier (integer)
|
/// Unique server identifier (integer)
|
||||||
#[serde(rename = "Server_id")]
|
#[serde(rename = "Server_id")]
|
||||||
pub server_id: u16,
|
pub server_id: u16,
|
||||||
@@ -225,7 +225,7 @@ pub struct DockerMetricDto {
|
|||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
|
|
||||||
pub struct DockerCollectMetricDto {
|
pub struct DockerCollectMetricDto {
|
||||||
pub id: String,
|
pub server_id: u16,
|
||||||
pub status: DockerContainerStatusDto,
|
pub status: DockerContainerStatusDto,
|
||||||
pub cpu: DockerContainerCpuDto,
|
pub cpu: DockerContainerCpuDto,
|
||||||
pub ram: DockerContainerRamDto,
|
pub ram: DockerContainerRamDto,
|
||||||
|
|||||||
Reference in New Issue
Block a user