diff --git a/.gitignore b/.gitignore index b34bd16..40dd2ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ /target .idea -Dockerfile Cargo.lock -settings.json hagent_test.sock \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index a4c69c0..5b477a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,24 +1,12 @@ -[package] -name = "runner-rs" -version = "0.10.11" -edition = "2021" +[workspace] +resolver = "2" +members = [ + "noxis-rs", + "noxis-cli", +] [profile.dev] debug = true [profile.test] debug = false - -[dependencies] -anyhow = "1.0.93" -chrono = "0.4.38" -clap = { version = "4.5.21", features = ["derive"] } -env_logger = "0.11.3" -inotify = "0.10.2" -log = "0.4.22" -pcap = "2.2.0" -redis = "0.25.4" -serde = { version = "1.0.203", features = ["derive"] } -serde_json = "1.0.118" -sysinfo = "0.32.0" -tokio = { version = "1.38.0", features = ["full", "time"] } diff --git a/README.md b/README.md index b4fa045..0c966aa 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# runner-rs ( with amd64 and riscv64 support ) +# Monitor "Noxis" ( with amd64 and riscv64 support ) ![Logo](https://blog.desdelinux.net/wp-content/uploads/2023/07/rust-logo.png) in-container integrating util to handle processes runtime @@ -8,6 +8,9 @@ in-container integrating util to handle processes runtime - `rustup (>=1.27.1)` - `gcc-riscv64-unknown-elf` - `build-essential` +- `gcc-riscv64-linux-gnu` +- `binutils-riscv64-linux-gnu` + ## Setting up Download and execute rustup.sh @@ -29,7 +32,7 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh cd runner-rs/ && rustup target add riscv64gc-unknown-linux-gnu && rustup target add x86_64-unknown-linux-gnu ~~~ > [!NOTE] -> Cargo is configured to build an app for amd64/linux defaultly. RISC-based compilation is optional. +> Cargo is configured to build an app for amd64/linux defaultly. RISCV-based compilation is optional. 3.1. Release build of app for amd64/linux diff --git a/noxis-cli/Cargo.toml b/noxis-cli/Cargo.toml new file mode 100644 index 0000000..bbc575a --- /dev/null +++ b/noxis-cli/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "noxis-cli" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/noxis-cli/src/main.rs b/noxis-cli/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/noxis-cli/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/noxis-rs/Cargo.toml b/noxis-rs/Cargo.toml new file mode 100644 index 0000000..ed2f9c3 --- /dev/null +++ b/noxis-rs/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "noxis-rs" +version = "0.10.11" +edition = "2021" + +[dependencies] +anyhow = "1.0.93" +chrono = "0.4.38" +clap = { version = "4.5.21", features = ["derive"] } +env_logger = "0.11.3" +inotify = "0.10.2" +log = "0.4.22" +pcap = "2.2.0" +redis = "0.25.4" +serde = { version = "1.0.203", features = ["derive"] } +serde_json = "1.0.118" +sysinfo = "0.32.0" +tokio = { version = "1.38.0", features = ["full", "time"] } diff --git a/Dockerfile b/noxis-rs/Dockerfile similarity index 100% rename from Dockerfile rename to noxis-rs/Dockerfile diff --git a/settings.json b/noxis-rs/settings.json similarity index 100% rename from settings.json rename to noxis-rs/settings.json diff --git a/src/lib.rs b/noxis-rs/src/lib.rs similarity index 100% rename from src/lib.rs rename to noxis-rs/src/lib.rs diff --git a/src/main.rs b/noxis-rs/src/main.rs similarity index 100% rename from src/main.rs rename to noxis-rs/src/main.rs diff --git a/src/options.rs b/noxis-rs/src/options.rs similarity index 100% rename from src/options.rs rename to noxis-rs/src/options.rs diff --git a/src/options/config.rs b/noxis-rs/src/options/config.rs similarity index 100% rename from src/options/config.rs rename to noxis-rs/src/options/config.rs diff --git a/src/options/logger.rs b/noxis-rs/src/options/logger.rs similarity index 100% rename from src/options/logger.rs rename to noxis-rs/src/options/logger.rs diff --git a/src/options/preboot.rs b/noxis-rs/src/options/preboot.rs similarity index 100% rename from src/options/preboot.rs rename to noxis-rs/src/options/preboot.rs diff --git a/src/options/signals.rs b/noxis-rs/src/options/signals.rs similarity index 100% rename from src/options/signals.rs rename to noxis-rs/src/options/signals.rs diff --git a/src/utils.rs b/noxis-rs/src/utils.rs similarity index 100% rename from src/utils.rs rename to noxis-rs/src/utils.rs diff --git a/src/utils/files.rs b/noxis-rs/src/utils/files.rs similarity index 100% rename from src/utils/files.rs rename to noxis-rs/src/utils/files.rs diff --git a/src/utils/hagent.rs b/noxis-rs/src/utils/hagent.rs similarity index 100% rename from src/utils/hagent.rs rename to noxis-rs/src/utils/hagent.rs diff --git a/src/utils/metrics.rs b/noxis-rs/src/utils/metrics.rs similarity index 100% rename from src/utils/metrics.rs rename to noxis-rs/src/utils/metrics.rs diff --git a/src/utils/prcs.rs b/noxis-rs/src/utils/prcs.rs similarity index 100% rename from src/utils/prcs.rs rename to noxis-rs/src/utils/prcs.rs diff --git a/src/utils/services.rs b/noxis-rs/src/utils/services.rs similarity index 100% rename from src/utils/services.rs rename to noxis-rs/src/utils/services.rs diff --git a/temp-process b/noxis-rs/temp-process similarity index 100% rename from temp-process rename to noxis-rs/temp-process diff --git a/tests/examples/dep-file b/noxis-rs/tests/examples/dep-file similarity index 100% rename from tests/examples/dep-file rename to noxis-rs/tests/examples/dep-file diff --git a/tests/examples/freeze-check b/noxis-rs/tests/examples/freeze-check similarity index 100% rename from tests/examples/freeze-check rename to noxis-rs/tests/examples/freeze-check diff --git a/tests/examples/invalid_config.json b/noxis-rs/tests/examples/invalid_config.json similarity index 100% rename from tests/examples/invalid_config.json rename to noxis-rs/tests/examples/invalid_config.json diff --git a/tests/examples/none.json b/noxis-rs/tests/examples/none.json similarity index 100% rename from tests/examples/none.json rename to noxis-rs/tests/examples/none.json diff --git a/tests/examples/pidof-prc b/noxis-rs/tests/examples/pidof-prc similarity index 100% rename from tests/examples/pidof-prc rename to noxis-rs/tests/examples/pidof-prc diff --git a/tests/examples/restart-prc b/noxis-rs/tests/examples/restart-prc similarity index 100% rename from tests/examples/restart-prc rename to noxis-rs/tests/examples/restart-prc diff --git a/tests/examples/run.sh b/noxis-rs/tests/examples/run.sh similarity index 100% rename from tests/examples/run.sh rename to noxis-rs/tests/examples/run.sh diff --git a/tests/examples/save-conf.json b/noxis-rs/tests/examples/save-conf.json similarity index 100% rename from tests/examples/save-conf.json rename to noxis-rs/tests/examples/save-conf.json diff --git a/tests/examples/settings.json b/noxis-rs/tests/examples/settings.json similarity index 100% rename from tests/examples/settings.json rename to noxis-rs/tests/examples/settings.json diff --git a/tests/examples/tmp-prc b/noxis-rs/tests/examples/tmp-prc similarity index 100% rename from tests/examples/tmp-prc rename to noxis-rs/tests/examples/tmp-prc diff --git a/tests/start_stop.rs b/noxis-rs/tests/start_stop.rs similarity index 100% rename from tests/start_stop.rs rename to noxis-rs/tests/start_stop.rs diff --git a/src/options/structs.rs b/src/options/structs.rs deleted file mode 100644 index 65c1a19..0000000 --- a/src/options/structs.rs +++ /dev/null @@ -1,291 +0,0 @@ -#![allow(dead_code)] - -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 -/// ## for storing main config data -/// -/// > (needed in serialization and deserialization) -/// -/// *depends on* : `TrackingProcess` -/// -/// ``` json -/// { -/// -> "dateOfCreation": "1721381809104", -/// -> "configServer": "localhost", -/// -> "processes": [ -/// { ... -/// ``` -#[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, -} - -/// # Struct for the 2nd level in json conf file -/// ## for each process to contain info, such as name, path and dependencies -/// -/// > (needed in serialization and deserialization) -/// -/// *depends on* : `Dependencies` -/// -/// ``` json -/// ... -/// "processes": [ -/// -> { -/// -> "name": "temp-process", -/// -> "path": "/home/user/monitor/runner-rs/temp-process", -/// -> "dependencies": { ... } -/// -> }, ... -/// ] -/// ... -/// ``` -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct TrackingProcess { - pub name: String, - pub path: String, - pub dependencies: Dependencies, -} - -/// # Struct for the 3d level in json conf file -/// ## for processes' dependencies including files and services -/// -/// > (needed in serialization and deserialization) -/// -/// *depends on* : `Files`, `Services` -/// -/// ``` json -/// ... -/// "path": "/home/user/monitor/runner-rs/temp-process", -/// -> "dependencies": { -/// -> "files": [ ... ], -/// -> "services": [ ... ] -/// -> } -/// ... -/// ``` -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct Dependencies { - #[serde(default)] - pub files: Vec, - #[serde(default)] - pub services: Vec, -} - -/// # Struct for the 4th level in json conf file -/// ## for containing file object with its triggers to manipulate in daemons -/// -/// > (needed in serialization and deserialization) -/// -/// *depends on* : `FileTriggers` -/// -/// ``` json -/// ... -/// "files": [ -/// -> { -/// -> "filename": "dep-file", -/// -> "src": "/home/user/monitor/runner-rs/tests/examples/", -/// -> "triggers": { ... } -/// -> } , -/// ... -/// ], ... -/// ``` -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct Files { - pub filename: String, - pub src: String, - pub triggers: FileTriggers, -} - -/// # Struct for the 4th level in json conf file -/// ## for containing service object with its triggers to manipulate in daemons -/// -/// > (needed in serialization and deserialization) -/// -/// *depends on* : `ServiceTriggers` -/// -/// ``` json -/// ... -/// "services": [ -/// -> { -/// -> "hostname" : "ya.ru", -/// -> "port" : 443, -/// -> "triggers": { ... } -/// -> } , -/// ... -/// ], ... -/// ``` -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct Services { - pub hostname: String, - pub port: u32, - pub triggers: ServiceTriggers, -} - -/// # Struct for the 5th level in json conf file -/// ## for instancing each service's policies such as on lost or time to wait till reachable -/// -/// > (needed in serialization and deserialization) -/// -/// *depends on* : - -/// -/// ``` json -/// ... -/// "port": 443, -/// -> "triggers": { -/// -> "wait": 10, -/// -> "delay": 2, -/// -> "onLost": "hold" -/// -> } -/// ... -/// ``` -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct ServiceTriggers { - pub wait: u32, - pub delay: u32, - #[serde(rename = "onLost")] - pub on_lost: String, -} - -/// # Struct for the 5th level in json conf file -/// ## for instancing each file's policies such as on-delete or onupdate events -/// -/// > (needed in serialization and deserialization) -/// -/// *depends on* : - -/// -/// ``` json -/// ... -/// "src": "/home/user/monitor/runner-rs/tests/examples/", -/// -> "triggers": { -/// -> "onDelete": "stop", -/// -> "onChange": "stay" -/// -> } -/// ... -/// ``` -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct FileTriggers { - #[serde(rename = "onDelete")] - pub on_delete: String, - #[serde(rename = "onChange")] - pub on_change: String, -} - -/// # Metrics struct -/// ## for gathering all system metrics (from container + each process) -/// -/// > (needed in hagent communication, `?...?`) -/// -/// *depends on* : `ContainerMetrics`, `ProcessMetrics` -/// -#[derive(Debug, Clone, Serialize,)] -pub struct Metrics { - pub container_metrics : ContainerMetrics, - pub processes_metrics : Vec, - // pub net_metrics : Vec, -} -/// ## Metrics struct's constructor -impl Metrics { - pub fn new(cm: ContainerMetrics, prm: Vec) -> Self { - Metrics { - container_metrics : cm, - processes_metrics : prm, - // net_metrics : net, - } - } -} - - -/// # Container metrics struct -/// ## for gathering all container metrics -/// -/// > (needed in gathering metrics) -/// -/// *depends on* : - -/// -#[derive(Debug, Clone, Serialize)] -pub struct ContainerMetrics { - container_id : String, - cpu_load : f32, - ram_load : f32, - // pub net_activity : ??? - processes : Vec, -} -/// ## Container struct's constructor -impl ContainerMetrics { - pub fn new(container_id : &str, cpu: f32, ram: f32, subsystems: Vec,) -> Self{ - ContainerMetrics { - container_id : String::from(container_id), - cpu_load : cpu, - ram_load : ram, - processes : subsystems, - } - } -} - -/// # Process metrics struct -/// ## for gathering each process's all metrics -/// -/// > (needed in gathering metrics) -/// -/// *depends on* : - -/// -#[derive(Debug, Clone, Serialize)] -pub struct ProcessMetrics { - pub process_name : String, - cpu_load : f32, - ram_load : f32, -} -/// ## Process struct's constructor -impl ProcessMetrics { - pub fn new(process_name :&str, cpu: f32, ram: f32) -> Self { - ProcessMetrics { - process_name : String::from(process_name), - cpu_load : cpu, - ram_load : ram, - } - } -} - -/// # Packet info struct -/// ## for gathering info about container's net activity -/// -/// > (needed in gathering metrics) -/// -/// *depends on* : - -/// -#[derive(Debug, Clone, Serialize)] -pub struct PacketInfo { - protocol : String, - dst_ip : Ipv4Addr, - src_ip : Ipv4Addr, - size : usize, -} -/// ## PacketInfo's constructor -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, - } - } -} \ No newline at end of file