157 lines
3.9 KiB
Rust
157 lines
3.9 KiB
Rust
use std::net::Ipv4Addr;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// # an Error enum (next will be deleted and replaced)
|
|
pub enum CustomError {
|
|
Fatal,
|
|
}
|
|
#[derive(Debug, PartialEq)]
|
|
pub enum ConfigActuality {
|
|
Local,
|
|
Remote,
|
|
}
|
|
|
|
/// # struct for the 1st level in json conf file
|
|
/// > (needed in serialization and deserialization)
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct Processes {
|
|
// #[serde(rename="id")]
|
|
// runner_id: usize,
|
|
#[serde(rename = "dateOfCreation")]
|
|
pub date_of_creation: String,
|
|
#[serde(rename = "configServer")]
|
|
pub config_server: String,
|
|
#[serde(default)]
|
|
pub processes: Vec<TrackingProcess>,
|
|
}
|
|
|
|
/// # struct for each process to contain info, such as name, path and dependencies
|
|
/// > (needed in serialization and deserialization)
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct TrackingProcess {
|
|
pub name: String,
|
|
pub path: String,
|
|
pub dependencies: Dependencies,
|
|
}
|
|
|
|
/// # struct for processes' dependencies including files and services
|
|
/// > (needed in serialization and deserialization)
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct Dependencies {
|
|
#[serde(default)]
|
|
pub files: Vec<Files>,
|
|
#[serde(default)]
|
|
pub services: Vec<Services>,
|
|
}
|
|
|
|
/// # struct for containing file object with its triggers to manipulate in daemons
|
|
/// > (needed in serialization and deserialization)
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct Files {
|
|
pub filename: String,
|
|
pub src: String,
|
|
pub triggers: FIleTriggers,
|
|
}
|
|
|
|
/// # struct for containing service object with its triggers to manipulate in daemons
|
|
/// > (needed in serialization and deserialization)
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct Services {
|
|
pub hostname: String,
|
|
pub port: u32,
|
|
pub triggers: ServiceTriggers,
|
|
}
|
|
|
|
/// # struct for instancing each service's policies such as on lost or time to wait till reachable
|
|
/// > (needed in serialization and deserialization)
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct ServiceTriggers {
|
|
pub wait: u32,
|
|
pub delay: u32,
|
|
#[serde(rename = "onLost")]
|
|
pub on_lost: String,
|
|
}
|
|
|
|
/// # struct for instancing each file's policies such as on-delete or onupdate events
|
|
/// > (needed in serialization and deserialization)
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct FIleTriggers {
|
|
#[serde(rename = "onDelete")]
|
|
pub on_delete: String,
|
|
#[serde(rename = "onChange")]
|
|
pub on_change: String,
|
|
}
|
|
|
|
///
|
|
///
|
|
#[derive(Debug, Clone)]
|
|
pub struct Metrics {
|
|
pub container_metrics : ContainerMetrics,
|
|
pub processes_metrics : Vec<ProcessMetrics>,
|
|
// pub net_metrics : Vec<PacketInfo>,
|
|
}
|
|
impl Metrics {
|
|
pub fn new(cm: ContainerMetrics, prm: Vec<ProcessMetrics>) -> Self {
|
|
Metrics {
|
|
container_metrics : cm,
|
|
processes_metrics : prm,
|
|
// net_metrics : net,
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
///
|
|
///
|
|
#[derive(Debug, Clone)]
|
|
pub struct ContainerMetrics {
|
|
pub cpu_load : f32,
|
|
pub ram_load : f32,
|
|
// pub net_activity : ???
|
|
pub processes : Vec<String>,
|
|
}
|
|
|
|
impl ContainerMetrics {
|
|
pub fn new(cpu: f32, ram: f32, subsystems: Vec<String>,) -> Self{
|
|
ContainerMetrics {
|
|
cpu_load : cpu,
|
|
ram_load : ram,
|
|
processes : subsystems,
|
|
}
|
|
}
|
|
}
|
|
|
|
///
|
|
///
|
|
#[derive(Debug, Clone)]
|
|
pub struct ProcessMetrics {
|
|
pub cpu_load : f32,
|
|
pub ram_load : f32,
|
|
}
|
|
|
|
impl ProcessMetrics {
|
|
pub fn new(cpu: f32, ram: f32) -> Self {
|
|
ProcessMetrics {
|
|
cpu_load : cpu,
|
|
ram_load : ram,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct PacketInfo {
|
|
protocol : String,
|
|
dst_ip : Ipv4Addr,
|
|
src_ip : Ipv4Addr,
|
|
size : usize,
|
|
}
|
|
impl PacketInfo {
|
|
pub fn new(prt: String, dest: Ipv4Addr, src: Ipv4Addr, size_of_packet: usize) -> Self {
|
|
PacketInfo {
|
|
protocol : prt,
|
|
dst_ip : dest,
|
|
src_ip : src,
|
|
size : size_of_packet,
|
|
}
|
|
}
|
|
} |