From 6afd5d0fcd3e6b51583f4cbffd875c104349855b Mon Sep 17 00:00:00 2001 From: donpat1to Date: Wed, 29 Oct 2025 14:26:52 +0100 Subject: [PATCH 01/11] json as string --- WatcherAgent/src/api.rs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/WatcherAgent/src/api.rs b/WatcherAgent/src/api.rs index 2246693..cc3d3f9 100644 --- a/WatcherAgent/src/api.rs +++ b/WatcherAgent/src/api.rs @@ -193,26 +193,37 @@ pub async fn broadcast_docker_containers( server_id: u16, container_dto: &DockerRegistrationDto, ) -> Result<(), Box> { - // First get local IP println!("Preparing to broadcast docker containers..."); - // Create HTTP client for registration let client = Client::builder() .danger_accept_invalid_certs(true) .build()?; - // Prepare registration data - let mut broadcast_data = container_dto.clone(); - broadcast_data.server_id = server_id; + // Create a new struct that matches the server's expected format + #[derive(Serialize)] + struct ServiceDiscoveryRequest { + #[serde(rename = "Server_id")] + server_id: u16, + #[serde(rename = "Containers")] + containers: String, // JSON string instead of Vec + } + + // Serialize containers to JSON string + let containers_json = serde_json::to_string(&container_dto.containers) + .map_err(|e| format!("Failed to serialize containers: {}", e))?; + + let broadcast_data = ServiceDiscoveryRequest { + server_id, + containers: containers_json, + }; - // Try to register (will retry on failure) loop { println!("Attempting to broadcast containers..."); let url = format!("{}/monitoring/service-discovery", base_url); - match client.post(&url).json(&container_dto).send().await { + match client.post(&url).json(&broadcast_data).send().await { Ok(resp) if resp.status().is_success() => { println!( - "✅ Successfully broadcasted following docker container: {:?}", - container_dto + "✅ Successfully broadcasted docker containers for server {}", + server_id ); return Ok(()); } From b134be4c8864bb405ea0f9d5c2e1a946f9724033 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Wed, 29 Oct 2025 14:57:42 +0100 Subject: [PATCH 02/11] updated .env --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 9c4549d..95ca1cd 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,9 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb +.env +watcher-volumes + # RustRover # JetBrains specific template is maintained in a separate JetBrains.gitignore that can # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore From 375b4450f0e38a7ae6ee4fbe460b06f3b19f585c Mon Sep 17 00:00:00 2001 From: donpat1to Date: Wed, 29 Oct 2025 21:07:29 +0100 Subject: [PATCH 03/11] fixed json formatting --- WatcherAgent/- | 578 +++++++++++++++++++++++++++++++++ WatcherAgent/src/api.rs | 33 +- WatcherAgent/src/docker/mod.rs | 5 +- WatcherAgent/src/main.rs | 3 +- WatcherAgent/src/models.rs | 3 +- 5 files changed, 599 insertions(+), 23 deletions(-) create mode 100644 WatcherAgent/- diff --git a/WatcherAgent/- b/WatcherAgent/- new file mode 100644 index 0000000..8cf62a7 --- /dev/null +++ b/WatcherAgent/- @@ -0,0 +1,578 @@ +#!/bin/sh +# +# This script should be run via curl: +# sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" +# or via wget: +# sh -c "$(wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" +# or via fetch: +# sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" +# +# As an alternative, you can first download the install script and run it afterwards: +# wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh +# sh install.sh +# +# You can tweak the install behavior by setting variables when running the script. For +# example, to change the path to the Oh My Zsh repository: +# ZSH=~/.zsh sh install.sh +# +# Respects the following environment variables: +# ZDOTDIR - path to Zsh dotfiles directory (default: unset). See [1][2] +# [1] https://zsh.sourceforge.io/Doc/Release/Parameters.html#index-ZDOTDIR +# [2] https://zsh.sourceforge.io/Doc/Release/Files.html#index-ZDOTDIR_002c-use-of +# ZSH - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh) +# REPO - name of the GitHub repo to install from (default: ohmyzsh/ohmyzsh) +# REMOTE - full remote URL of the git repo to install (default: GitHub via HTTPS) +# BRANCH - branch to check out immediately after install (default: master) +# +# Other options: +# CHSH - 'no' means the installer will not change the default shell (default: yes) +# RUNZSH - 'no' means the installer will not run zsh after the install (default: yes) +# KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no) +# OVERWRITE_CONFIRMATION - 'no' means the installer will not ask for confirmation to overwrite the existing .zshrc (default: yes) +# +# You can also pass some arguments to the install script to set some these options: +# --skip-chsh: has the same behavior as setting CHSH to 'no' +# --unattended: sets both CHSH and RUNZSH to 'no' +# --keep-zshrc: sets KEEP_ZSHRC to 'yes' +# For example: +# sh install.sh --unattended +# or: +# sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended +# +set -e + +# Make sure important variables exist if not already defined +# +# $USER is defined by login(1) which is not always executed (e.g. containers) +# POSIX: https://pubs.opengroup.org/onlinepubs/009695299/utilities/id.html +USER=${USER:-$(id -u -n)} +# $HOME is defined at the time of login, but it could be unset. If it is unset, +# a tilde by itself (~) will not be expanded to the current user's home directory. +# POSIX: https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap08.html#tag_08_03 +HOME="${HOME:-$(getent passwd $USER 2>/dev/null | cut -d: -f6)}" +# macOS does not have getent, but this works even if $HOME is unset +HOME="${HOME:-$(eval echo ~$USER)}" + + +# Track if $ZSH was provided +custom_zsh=${ZSH:+yes} + +# Use $zdot to keep track of where the directory is for zsh dotfiles +# To check if $ZDOTDIR was provided, explicitly check for $ZDOTDIR +zdot="${ZDOTDIR:-$HOME}" + +# Default value for $ZSH +# a) if $ZDOTDIR is supplied and not $HOME: $ZDOTDIR/ohmyzsh +# b) otherwise, $HOME/.oh-my-zsh +if [ -n "$ZDOTDIR" ] && [ "$ZDOTDIR" != "$HOME" ]; then + ZSH="${ZSH:-$ZDOTDIR/ohmyzsh}" +fi +ZSH="${ZSH:-$HOME/.oh-my-zsh}" + +# Default settings +REPO=${REPO:-ohmyzsh/ohmyzsh} +REMOTE=${REMOTE:-https://github.com/${REPO}.git} +BRANCH=${BRANCH:-master} + +# Other options +CHSH=${CHSH:-yes} +RUNZSH=${RUNZSH:-yes} +KEEP_ZSHRC=${KEEP_ZSHRC:-no} +OVERWRITE_CONFIRMATION=${OVERWRITE_CONFIRMATION:-yes} + + +command_exists() { + command -v "$@" >/dev/null 2>&1 +} + +user_can_sudo() { + # Check if sudo is installed + command_exists sudo || return 1 + # Termux can't run sudo, so we can detect it and exit the function early. + case "$PREFIX" in + *com.termux*) return 1 ;; + esac + # The following command has 3 parts: + # + # 1. Run `sudo` with `-v`. Does the following: + # • with privilege: asks for a password immediately. + # • without privilege: exits with error code 1 and prints the message: + # Sorry, user may not run sudo on + # + # 2. Pass `-n` to `sudo` to tell it to not ask for a password. If the + # password is not required, the command will finish with exit code 0. + # If one is required, sudo will exit with error code 1 and print the + # message: + # sudo: a password is required + # + # 3. Check for the words "may not run sudo" in the output to really tell + # whether the user has privileges or not. For that we have to make sure + # to run `sudo` in the default locale (with `LANG=`) so that the message + # stays consistent regardless of the user's locale. + # + ! LANG= sudo -n -v 2>&1 | grep -q "may not run sudo" +} + +# The [ -t 1 ] check only works when the function is not called from +# a subshell (like in `$(...)` or `(...)`, so this hack redefines the +# function at the top level to always return false when stdout is not +# a tty. +if [ -t 1 ]; then + is_tty() { + true + } +else + is_tty() { + false + } +fi + +# This function uses the logic from supports-hyperlinks[1][2], which is +# made by Kat Marchán (@zkat) and licensed under the Apache License 2.0. +# [1] https://github.com/zkat/supports-hyperlinks +# [2] https://crates.io/crates/supports-hyperlinks +# +# Copyright (c) 2021 Kat Marchán +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +supports_hyperlinks() { + # $FORCE_HYPERLINK must be set and be non-zero (this acts as a logic bypass) + if [ -n "$FORCE_HYPERLINK" ]; then + [ "$FORCE_HYPERLINK" != 0 ] + return $? + fi + + # If stdout is not a tty, it doesn't support hyperlinks + is_tty || return 1 + + # DomTerm terminal emulator (domterm.org) + if [ -n "$DOMTERM" ]; then + return 0 + fi + + # VTE-based terminals above v0.50 (Gnome Terminal, Guake, ROXTerm, etc) + if [ -n "$VTE_VERSION" ]; then + [ $VTE_VERSION -ge 5000 ] + return $? + fi + + # If $TERM_PROGRAM is set, these terminals support hyperlinks + case "$TERM_PROGRAM" in + Hyper|iTerm.app|terminology|WezTerm|vscode) return 0 ;; + esac + + # These termcap entries support hyperlinks + case "$TERM" in + xterm-kitty|alacritty|alacritty-direct) return 0 ;; + esac + + # xfce4-terminal supports hyperlinks + if [ "$COLORTERM" = "xfce4-terminal" ]; then + return 0 + fi + + # Windows Terminal also supports hyperlinks + if [ -n "$WT_SESSION" ]; then + return 0 + fi + + # Konsole supports hyperlinks, but it's an opt-in setting that can't be detected + # https://github.com/ohmyzsh/ohmyzsh/issues/10964 + # if [ -n "$KONSOLE_VERSION" ]; then + # return 0 + # fi + + return 1 +} + +# Adapted from code and information by Anton Kochkov (@XVilka) +# Source: https://gist.github.com/XVilka/8346728 +supports_truecolor() { + case "$COLORTERM" in + truecolor|24bit) return 0 ;; + esac + + case "$TERM" in + iterm |\ + tmux-truecolor |\ + linux-truecolor |\ + xterm-truecolor |\ + screen-truecolor) return 0 ;; + esac + + return 1 +} + +fmt_link() { + # $1: text, $2: url, $3: fallback mode + if supports_hyperlinks; then + printf '\033]8;;%s\033\\%s\033]8;;\033\\\n' "$2" "$1" + return + fi + + case "$3" in + --text) printf '%s\n' "$1" ;; + --url|*) fmt_underline "$2" ;; + esac +} + +fmt_underline() { + is_tty && printf '\033[4m%s\033[24m\n' "$*" || printf '%s\n' "$*" +} + +# shellcheck disable=SC2016 # backtick in single-quote +fmt_code() { + is_tty && printf '`\033[2m%s\033[22m`\n' "$*" || printf '`%s`\n' "$*" +} + +fmt_error() { + printf '%sError: %s%s\n' "${FMT_BOLD}${FMT_RED}" "$*" "$FMT_RESET" >&2 +} + +setup_color() { + # Only use colors if connected to a terminal + if ! is_tty; then + FMT_RAINBOW="" + FMT_RED="" + FMT_GREEN="" + FMT_YELLOW="" + FMT_BLUE="" + FMT_BOLD="" + FMT_RESET="" + return + fi + + if supports_truecolor; then + FMT_RAINBOW=" + $(printf '\033[38;2;255;0;0m') + $(printf '\033[38;2;255;97;0m') + $(printf '\033[38;2;247;255;0m') + $(printf '\033[38;2;0;255;30m') + $(printf '\033[38;2;77;0;255m') + $(printf '\033[38;2;168;0;255m') + $(printf '\033[38;2;245;0;172m') + " + else + FMT_RAINBOW=" + $(printf '\033[38;5;196m') + $(printf '\033[38;5;202m') + $(printf '\033[38;5;226m') + $(printf '\033[38;5;082m') + $(printf '\033[38;5;021m') + $(printf '\033[38;5;093m') + $(printf '\033[38;5;163m') + " + fi + + FMT_RED=$(printf '\033[31m') + FMT_GREEN=$(printf '\033[32m') + FMT_YELLOW=$(printf '\033[33m') + FMT_BLUE=$(printf '\033[34m') + FMT_BOLD=$(printf '\033[1m') + FMT_RESET=$(printf '\033[0m') +} + +setup_ohmyzsh() { + # Prevent the cloned repository from having insecure permissions. Failing to do + # so causes compinit() calls to fail with "command not found: compdef" errors + # for users with insecure umasks (e.g., "002", allowing group writability). Note + # that this will be ignored under Cygwin by default, as Windows ACLs take + # precedence over umasks except for filesystems mounted with option "noacl". + umask g-w,o-w + + echo "${FMT_BLUE}Cloning Oh My Zsh...${FMT_RESET}" + + command_exists git || { + fmt_error "git is not installed" + exit 1 + } + + ostype=$(uname) + if [ -z "${ostype%CYGWIN*}" ] && git --version | grep -Eq 'msysgit|windows'; then + fmt_error "Windows/MSYS Git is not supported on Cygwin" + fmt_error "Make sure the Cygwin git package is installed and is first on the \$PATH" + exit 1 + fi + + # Manual clone with git config options to support git < v1.7.2 + git init --quiet "$ZSH" && cd "$ZSH" \ + && git config core.eol lf \ + && git config core.autocrlf false \ + && git config fsck.zeroPaddedFilemode ignore \ + && git config fetch.fsck.zeroPaddedFilemode ignore \ + && git config receive.fsck.zeroPaddedFilemode ignore \ + && git config oh-my-zsh.remote origin \ + && git config oh-my-zsh.branch "$BRANCH" \ + && git remote add origin "$REMOTE" \ + && git fetch --depth=1 origin \ + && git checkout -b "$BRANCH" "origin/$BRANCH" || { + [ ! -d "$ZSH" ] || { + cd - + rm -rf "$ZSH" 2>/dev/null + } + fmt_error "git clone of oh-my-zsh repo failed" + exit 1 + } + # Exit installation directory + cd - + + echo +} + +setup_zshrc() { + # Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones + # with datestamp of installation that moved them aside, so we never actually + # destroy a user's original zshrc + echo "${FMT_BLUE}Looking for an existing zsh config...${FMT_RESET}" + + # Must use this exact name so uninstall.sh can find it + OLD_ZSHRC="$zdot/.zshrc.pre-oh-my-zsh" + if [ -f "$zdot/.zshrc" ] || [ -h "$zdot/.zshrc" ]; then + # Skip this if the user doesn't want to replace an existing .zshrc + if [ "$KEEP_ZSHRC" = yes ]; then + echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Keeping...${FMT_RESET}" + return + fi + + if [ $OVERWRITE_CONFIRMATION != "no" ]; then + # Ask user for confirmation before backing up and overwriting + echo "${FMT_YELLOW}Found ${zdot}/.zshrc." + echo "The existing .zshrc will be backed up to .zshrc.pre-oh-my-zsh if overwritten." + echo "Make sure your .zshrc contains the following minimal configuration if you choose not to overwrite it:${FMT_RESET}" + echo "----------------------------------------" + cat "$ZSH/templates/minimal.zshrc" + echo "----------------------------------------" + printf '%sDo you want to overwrite it with the Oh My Zsh template? [Y/n]%s ' \ + "$FMT_YELLOW" "$FMT_RESET" + read -r opt + case $opt in + [Yy]*|"") ;; + [Nn]*) echo "Overwrite skipped. Existing .zshrc will be kept."; return ;; + *) echo "Invalid choice. Overwrite skipped. Existing .zshrc will be kept."; return ;; + esac + fi + + if [ -e "$OLD_ZSHRC" ]; then + OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)" + if [ -e "$OLD_OLD_ZSHRC" ]; then + fmt_error "$OLD_OLD_ZSHRC exists. Can't back up ${OLD_ZSHRC}" + fmt_error "re-run the installer again in a couple of seconds" + exit 1 + fi + mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}" + + echo "${FMT_YELLOW}Found old .zshrc.pre-oh-my-zsh." \ + "${FMT_GREEN}Backing up to ${OLD_OLD_ZSHRC}${FMT_RESET}" + fi + echo "${FMT_GREEN}Backing up to ${OLD_ZSHRC}${FMT_RESET}" + mv "$zdot/.zshrc" "$OLD_ZSHRC" + fi + + echo "${FMT_GREEN}Using the Oh My Zsh template file and adding it to $zdot/.zshrc.${FMT_RESET}" + + # Modify $ZSH variable in .zshrc directory to use the literal $ZDOTDIR or $HOME + omz="$ZSH" + if [ -n "$ZDOTDIR" ] && [ "$ZDOTDIR" != "$HOME" ]; then + omz=$(echo "$omz" | sed "s|^$ZDOTDIR/|\$ZDOTDIR/|") + fi + omz=$(echo "$omz" | sed "s|^$HOME/|\$HOME/|") + + sed "s|^export ZSH=.*$|export ZSH=\"${omz}\"|" "$ZSH/templates/zshrc.zsh-template" > "$zdot/.zshrc-omztemp" + mv -f "$zdot/.zshrc-omztemp" "$zdot/.zshrc" + + echo +} + +setup_shell() { + # Skip setup if the user wants or stdin is closed (not running interactively). + if [ "$CHSH" = no ]; then + return + fi + + # If this user's login shell is already "zsh", do not attempt to switch. + if [ "$(basename -- "$SHELL")" = "zsh" ]; then + return + fi + + # If this platform doesn't provide a "chsh" command, bail out. + if ! command_exists chsh; then + cat < "$zdot/.shell.pre-oh-my-zsh" + else + grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > "$zdot/.shell.pre-oh-my-zsh" + fi + + echo "Changing your shell to $zsh..." + + # Check if user has sudo privileges to run `chsh` with or without `sudo` + # + # This allows the call to succeed without password on systems where the + # user does not have a password but does have sudo privileges, like in + # Google Cloud Shell. + # + # On systems that don't have a user with passwordless sudo, the user will + # be prompted for the password either way, so this shouldn't cause any issues. + # + if user_can_sudo; then + sudo -k chsh -s "$zsh" "$USER" # -k forces the password prompt + else + chsh -s "$zsh" "$USER" # run chsh normally + fi + + # Check if the shell change was successful + if [ $? -ne 0 ]; then + fmt_error "chsh command unsuccessful. Change your default shell manually." + else + export SHELL="$zsh" + echo "${FMT_GREEN}Shell successfully changed to '$zsh'.${FMT_RESET}" + fi + + echo +} + +# shellcheck disable=SC2183 # printf string has more %s than arguments ($FMT_RAINBOW expands to multiple arguments) +print_success() { + printf '%s %s__ %s %s %s %s %s__ %s\n' $FMT_RAINBOW $FMT_RESET + printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $FMT_RAINBOW $FMT_RESET + printf '%s / __ \\%s/ __ \\ %s / __ `__ \\%s/ / / / %s /_ / %s/ ___/%s __ \\ %s\n' $FMT_RAINBOW $FMT_RESET + printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $FMT_RAINBOW $FMT_RESET + printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s /___/%s____/%s_/ /_/ %s\n' $FMT_RAINBOW $FMT_RESET + printf '%s %s %s %s /____/ %s %s %s %s....is now installed!%s\n' $FMT_RAINBOW $FMT_GREEN $FMT_RESET + printf '\n' + printf '\n' + printf "%s %s %s\n" "Before you scream ${FMT_BOLD}${FMT_YELLOW}Oh My Zsh!${FMT_RESET} look over the" \ + "$(fmt_code "$(fmt_link ".zshrc" "file://$zdot/.zshrc" --text)")" \ + "file to select plugins, themes, and options." + printf '\n' + printf '%s\n' "• Follow us on X: $(fmt_link @ohmyzsh https://x.com/ohmyzsh)" + printf '%s\n' "• Join our Discord community: $(fmt_link "Discord server" https://discord.gg/ohmyzsh)" + printf '%s\n' "• Get stickers, t-shirts, coffee mugs and more: $(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)" + printf '%s\n' $FMT_RESET +} + +main() { + # Run as unattended if stdin is not a tty + if [ ! -t 0 ]; then + RUNZSH=no + CHSH=no + OVERWRITE_CONFIRMATION=no + fi + + # Parse arguments + while [ $# -gt 0 ]; do + case $1 in + --unattended) RUNZSH=no; CHSH=no; OVERWRITE_CONFIRMATION=no ;; + --skip-chsh) CHSH=no ;; + --keep-zshrc) KEEP_ZSHRC=yes ;; + esac + shift + done + + setup_color + + if ! command_exists zsh; then + echo "${FMT_YELLOW}Zsh is not installed.${FMT_RESET} Please install zsh first." + exit 1 + fi + + if [ -d "$ZSH" ]; then + echo "${FMT_YELLOW}The \$ZSH folder already exists ($ZSH).${FMT_RESET}" + if [ "$custom_zsh" = yes ]; then + cat < Result<(), Box> { + // First get local IP println!("Preparing to broadcast docker containers..."); + // Create HTTP client for registration let client = Client::builder() .danger_accept_invalid_certs(true) .build()?; - // Create a new struct that matches the server's expected format - #[derive(Serialize)] - struct ServiceDiscoveryRequest { - #[serde(rename = "Server_id")] - server_id: u16, - #[serde(rename = "Containers")] - containers: String, // JSON string instead of Vec - } - - // Serialize containers to JSON string - let containers_json = serde_json::to_string(&container_dto.containers) - .map_err(|e| format!("Failed to serialize containers: {}", e))?; - - let broadcast_data = ServiceDiscoveryRequest { - server_id, - containers: containers_json, - }; + // Prepare registration data + let mut broadcast_data = container_dto.clone(); + broadcast_data.server_id = server_id; + // Try to register (will retry on failure) loop { println!("Attempting to broadcast containers..."); + + let json_body = serde_json::to_string_pretty(&broadcast_data)?; + println!("📤 JSON being posted:\n{}", json_body); + let url = format!("{}/monitoring/service-discovery", base_url); - match client.post(&url).json(&broadcast_data).send().await { + match client.post(&url).json(&container_dto).send().await { Ok(resp) if resp.status().is_success() => { println!( - "✅ Successfully broadcasted docker containers for server {}", - server_id + "✅ Successfully broadcasted following docker container: {:?}", + container_dto ); return Ok(()); } diff --git a/WatcherAgent/src/docker/mod.rs b/WatcherAgent/src/docker/mod.rs index 466a2be..9f809df 100644 --- a/WatcherAgent/src/docker/mod.rs +++ b/WatcherAgent/src/docker/mod.rs @@ -277,9 +277,12 @@ impl DockerManager { &self, ) -> Result> { let containers = self.get_containers().await?; + + let container_string = serde_json::to_value(&containers)?; + let dto = DockerRegistrationDto { server_id: 0, // This will be set by the caller - containers, // Fallback to empty array + containers: container_string, }; Ok(dto) diff --git a/WatcherAgent/src/main.rs b/WatcherAgent/src/main.rs index 77c0692..97bf156 100644 --- a/WatcherAgent/src/main.rs +++ b/WatcherAgent/src/main.rs @@ -114,10 +114,11 @@ async fn main() -> Result<(), Box> { let container_dto = if let Some(ref docker_manager) = docker_manager { docker_manager.create_registration_dto().await? } else { + println!("Fallback for failing registration"); models::DockerRegistrationDto { server_id: 0, //container_count: 0, --- IGNORE --- - containers: Vec::new(), + containers: serde_json::to_value(&"")?, } }; let _ = diff --git a/WatcherAgent/src/models.rs b/WatcherAgent/src/models.rs index 20f14f6..12019ec 100644 --- a/WatcherAgent/src/models.rs +++ b/WatcherAgent/src/models.rs @@ -12,6 +12,7 @@ use crate::docker::stats; use serde::{Deserialize, Serialize}; +use serde_json::Value; /// Registration data sent to the backend server. /// @@ -199,7 +200,7 @@ pub struct DockerRegistrationDto { /// image: docker image name /// name: container name #[serde(rename = "Containers")] - pub containers: Vec, // Vec, + pub containers: Value, // Vec, } #[derive(Debug, Serialize, Clone)] From c36b17fa053fd6810b2eb95392ed5ba3aa3f4137 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Wed, 29 Oct 2025 21:35:54 +0100 Subject: [PATCH 04/11] fixed json in api call --- WatcherAgent/src/api.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/WatcherAgent/src/api.rs b/WatcherAgent/src/api.rs index 90adc06..5d6ced2 100644 --- a/WatcherAgent/src/api.rs +++ b/WatcherAgent/src/api.rs @@ -15,13 +15,12 @@ use std::time::Duration; use crate::docker::serverclientcomm::handle_server_message; use crate::hardware::HardwareInfo; use crate::models::{ - Acknowledgment, DockerContainer, DockerMetricDto, DockerRegistrationDto, HeartbeatDto, + Acknowledgment, 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; @@ -210,7 +209,7 @@ pub async fn broadcast_docker_containers( let json_body = serde_json::to_string_pretty(&broadcast_data)?; println!("📤 JSON being posted:\n{}", json_body); - + let url = format!("{}/monitoring/service-discovery", base_url); match client.post(&url).json(&container_dto).send().await { Ok(resp) if resp.status().is_success() => { @@ -431,7 +430,8 @@ pub async fn send_docker_metrics( ) -> Result<(), Box> { let client = Client::new(); let url = format!("{}/monitoring/docker-metric", base_url); - println!("Docker Metrics: {:?}", docker_metrics); + + println!("Docker Metrics: {}", serde_json::to_string_pretty(&docker_metrics)?); match client.post(&url).json(&docker_metrics).send().await { Ok(res) => println!( From 2a4cc4b2d5141d74b4f0a756d444835e387dde85 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Wed, 29 Oct 2025 22:23:58 +0100 Subject: [PATCH 05/11] added status in docker metric collect --- WatcherAgent/src/docker/container.rs | 4 +- WatcherAgent/src/docker/mod.rs | 108 ++++++++++---------- WatcherAgent/src/docker/stats/mod.rs | 31 ++++-- WatcherAgent/src/docker/stats/status.rs | 126 ++++++++++++++++++++++++ WatcherAgent/src/models.rs | 10 +- 5 files changed, 208 insertions(+), 71 deletions(-) create mode 100644 WatcherAgent/src/docker/stats/status.rs diff --git a/WatcherAgent/src/docker/container.rs b/WatcherAgent/src/docker/container.rs index eac7c3a..87daa6a 100644 --- a/WatcherAgent/src/docker/container.rs +++ b/WatcherAgent/src/docker/container.rs @@ -172,7 +172,7 @@ pub async fn get_network_stats( docker: &Docker, container_id: &str, ) -> Result> { - let (_, net_info, _) = stats::get_single_container_stats(docker, container_id).await?; + let (_, net_info, _, _) = stats::get_single_container_stats(docker, container_id).await?; if let Some(net_info) = net_info { Ok(net_info) @@ -196,7 +196,7 @@ pub async fn get_cpu_stats( docker: &Docker, container_id: &str, ) -> Result> { - let (cpu_info, _, _) = stats::get_single_container_stats(docker, container_id).await?; + let (cpu_info, _, _, _) = stats::get_single_container_stats(docker, container_id).await?; if let Some(cpu_info) = cpu_info { Ok(cpu_info) diff --git a/WatcherAgent/src/docker/mod.rs b/WatcherAgent/src/docker/mod.rs index 9f809df..dbdd1d5 100644 --- a/WatcherAgent/src/docker/mod.rs +++ b/WatcherAgent/src/docker/mod.rs @@ -14,6 +14,7 @@ pub mod stats; use crate::models::{ DockerCollectMetricDto, DockerContainer, DockerContainerCpuDto, DockerContainerInfo, DockerContainerNetworkDto, DockerContainerRamDto, DockerMetricDto, DockerRegistrationDto, + DockerContainerStatusDto }; use bollard::Docker; use std::error::Error; @@ -129,28 +130,25 @@ impl DockerManager { /// Collects Docker metrics for all containers pub async fn collect_metrics(&self) -> Result> { let containers = self.get_containers().await?; - if let Some(first_container) = containers.first() { - println!("Debug: Testing stats for container {}", first_container.id); - let _ = self.debug_container_stats(&first_container.id).await; - } - // Get stats with proper error handling + // Get stats with status information 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, status_stats) = match stats_result { Ok(stats) => stats, Err(e) => { eprintln!("Warning: Failed to get container stats: {}", e); // Return empty stats instead of failing completely - (Vec::new(), Vec::new(), Vec::new()) + (Vec::new(), Vec::new(), Vec::new(), Vec::new()) } }; println!( - "Debug: Found {} containers, {} CPU stats, {} network stats, {} memory stats", + "Debug: Found {} containers, {} CPU stats, {} network stats, {} memory stats, {} status stats", containers.len(), cpu_stats.len(), net_stats.len(), - mem_stats.len() + mem_stats.len(), + status_stats.len(), ); let container_infos_total: Vec<_> = containers @@ -193,26 +191,49 @@ impl DockerManager { }) .cloned(); + let status = status_stats + .iter() + .find(|s| { + s.container_id + .as_ref() + .map(|id| id.starts_with(container_short_id)) + .unwrap_or(false) + }) + .cloned(); // Clone the entire ContainerStatusInfo + // Debug output for this container if cpu.is_none() || network.is_none() || ram.is_none() { println!( - "Debug: Container {} - CPU: {:?}, Network: {:?}, RAM: {:?}", + "Debug: Container {} - CPU: {:?}, Network: {:?}, RAM: {:?}, Status {:?}", container_short_id, cpu.is_some(), network.is_some(), - ram.is_some() + ram.is_some(), + status.is_some() ); } - DockerContainerInfo { - container: Some(container), - status: None, - cpu, - network, - ram, - } - }) - .collect(); + // Debug output for this container + if cpu.is_none() || network.is_none() || ram.is_none() || status.is_none() { + println!( + "Debug: Container {} - CPU: {:?}, Network: {:?}, RAM: {:?}, Status: {:?}", + container_short_id, + cpu.is_some(), + network.is_some(), + ram.is_some(), + status.is_some() + ); + } + + DockerContainerInfo { + container: Some(container), + status, + cpu, + network, + ram, + } + }) + .collect(); let container_infos: Vec = container_infos_total .into_iter() @@ -256,8 +277,17 @@ impl DockerManager { } }; + let status_dto = if let Some(status_info) = info.status { + DockerContainerStatusDto { + status: status_info.status, // Extract the status string + } + } else { + DockerContainerStatusDto { status: None } + }; + Some(DockerCollectMetricDto { id: container.id, + status: status_dto, cpu: cpu_dto, ram: ram_dto, network: network_dto, @@ -267,7 +297,7 @@ impl DockerManager { let dto = DockerMetricDto { server_id: 0, // This should be set by the caller - containers: serde_json::to_string(&container_infos)?, + containers: serde_json::to_value(&container_infos)?, }; Ok(dto) @@ -287,42 +317,6 @@ impl DockerManager { Ok(dto) } - - /// Debug function to check stats collection for a specific container - pub async fn debug_container_stats( - &self, - container_id: &str, - ) -> Result<(), Box> { - println!("=== DEBUG STATS FOR CONTAINER {} ===", container_id); - - 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); - println!("Memory Info: {:?}", mem_info); - - // Also try the individual stats functions - println!("--- Individual CPU Stats ---"); - match stats::cpu::get_single_container_cpu_stats(&self.docker, container_id).await { - Ok(cpu) => println!("CPU: {:?}", cpu), - Err(e) => println!("CPU Error: {}", e), - } - - println!("--- Individual Network Stats ---"); - match stats::network::get_single_container_network_stats(&self.docker, container_id).await { - Ok(net) => println!("Network: {:?}", net), - Err(e) => println!("Network Error: {}", e), - } - - println!("--- Individual Memory Stats ---"); - match stats::ram::get_single_container_memory_stats(&self.docker, container_id).await { - Ok(mem) => println!("Memory: {:?}", mem), - Err(e) => println!("Memory Error: {}", e), - } - - Ok(()) - } } // Keep these as utility functions if needed, but they should use DockerManager internally diff --git a/WatcherAgent/src/docker/stats/mod.rs b/WatcherAgent/src/docker/stats/mod.rs index 098ca1d..336f4b1 100644 --- a/WatcherAgent/src/docker/stats/mod.rs +++ b/WatcherAgent/src/docker/stats/mod.rs @@ -1,9 +1,19 @@ pub mod cpu; pub mod network; pub mod ram; +pub mod status; use serde::{Deserialize, Serialize}; +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct ContainerStatusInfo { + pub container_id: Option, + pub status: Option, // "running", "stopped", "paused", "exited", etc. + pub state: Option, // More detailed state information + pub started_at: Option, + pub finished_at: Option, +} + #[derive(Debug, Serialize, Deserialize, Clone)] pub struct ContainerCpuInfo { pub container_id: Option, @@ -43,33 +53,34 @@ pub async fn get_container_stats( Vec, Vec, Vec, + Vec, ), Box, > { let cpu_infos = cpu::get_all_containers_cpu_stats(docker).await?; let net_infos = network::get_all_containers_network_stats(docker).await?; let mem_infos = ram::get_all_containers_memory_stats(docker).await?; + let status_infos = status::get_all_containers_status(docker).await?; - Ok((cpu_infos, net_infos, mem_infos)) + Ok((cpu_infos, net_infos, mem_infos, status_infos)) } /// Get container statistics for a specific container pub async fn get_single_container_stats( docker: &Docker, container_id: &str, -) -> Result< - ( - Option, - Option, - Option, - ), - Box, -> { +) -> Result<( + Option, + Option, + Option, + Option, +), Box> { let cpu_info = cpu::get_single_container_cpu_stats(docker, container_id).await?; let net_info = network::get_single_container_network_stats(docker, container_id).await?; let mem_info = ram::get_single_container_memory_stats(docker, container_id).await?; + let status_info = status::get_single_container_status(docker, container_id).await?; - Ok((cpu_info, net_info, mem_info)) + Ok((cpu_info, net_info, mem_info, status_info)) } /// Get total network statistics across all containers diff --git a/WatcherAgent/src/docker/stats/status.rs b/WatcherAgent/src/docker/stats/status.rs new file mode 100644 index 0000000..846ddd0 --- /dev/null +++ b/WatcherAgent/src/docker/stats/status.rs @@ -0,0 +1,126 @@ +use super::ContainerStatusInfo; +use std::error::Error; +use bollard::Docker; +use bollard::query_parameters::{ListContainersOptions, InspectContainerOptions}; +use bollard::models::{ContainerSummaryStateEnum, ContainerStateStatusEnum}; + +/// Get status information for all containers +pub async fn get_all_containers_status( + docker: &Docker, +) -> Result, Box> { + + let containers = docker + .list_containers(Some(ListContainersOptions { + all: true, // Include stopped containers + ..Default::default() + })) + .await?; + + let mut status_infos = Vec::new(); + + for container in containers { + let id = container.id.unwrap_or_default(); + + if id.is_empty() { + continue; + } + + // Convert ContainerSummaryStateEnum to String + let status = container.state.map(|state| match state { + ContainerSummaryStateEnum::CREATED => "created".to_string(), + ContainerSummaryStateEnum::RUNNING => "running".to_string(), + ContainerSummaryStateEnum::PAUSED => "paused".to_string(), + ContainerSummaryStateEnum::RESTARTING => "restarting".to_string(), + ContainerSummaryStateEnum::REMOVING => "removing".to_string(), + ContainerSummaryStateEnum::EXITED => "exited".to_string(), + ContainerSummaryStateEnum::DEAD => "dead".to_string(), + _ => "unknown".to_string(), + }); + + // Convert timestamp from i64 to String + let started_at = container.created.map(|timestamp| timestamp.to_string()); + + status_infos.push(ContainerStatusInfo { + container_id: Some(id.clone()), + status, + state: container.status, + started_at, + finished_at: None, // Docker API doesn't provide finished_at in list + }); + } + + Ok(status_infos) +} + +/// Get status information for a specific container +pub async fn get_single_container_status( + docker: &Docker, + container_id: &str, +) -> Result, Box> { + // First try to get from list (faster) + let containers = docker + .list_containers(Some(ListContainersOptions { + all: true, + ..Default::default() + })) + .await?; + + if let Some(container) = containers.into_iter().find(|c| { + c.id.as_ref().map(|id| id == container_id).unwrap_or(false) + }) { + // Convert ContainerSummaryStateEnum to String + let status = container.state.map(|state| match state { + ContainerSummaryStateEnum::CREATED => "created".to_string(), + ContainerSummaryStateEnum::RUNNING => "running".to_string(), + ContainerSummaryStateEnum::PAUSED => "paused".to_string(), + ContainerSummaryStateEnum::RESTARTING => "restarting".to_string(), + ContainerSummaryStateEnum::REMOVING => "removing".to_string(), + ContainerSummaryStateEnum::EXITED => "exited".to_string(), + ContainerSummaryStateEnum::DEAD => "dead".to_string(), + _ => "unknown".to_string(), + }); + + // Convert timestamp from i64 to String + let started_at = container.created.map(|timestamp| timestamp.to_string()); + + return Ok(Some(ContainerStatusInfo { + container_id: Some(container_id.to_string()), + status, + state: container.status, + started_at, + finished_at: None, + })); + } + + // Fallback to inspect for more detailed info + match docker.inspect_container(container_id, None::).await { + Ok(container_details) => { + let state = container_details.state.unwrap_or_default(); + + // Convert ContainerStateStatusEnum to String + let status = state.status.map(|status_enum| match status_enum { + ContainerStateStatusEnum::CREATED => "created".to_string(), + ContainerStateStatusEnum::RUNNING => "running".to_string(), + ContainerStateStatusEnum::PAUSED => "paused".to_string(), + ContainerStateStatusEnum::RESTARTING => "restarting".to_string(), + ContainerStateStatusEnum::REMOVING => "removing".to_string(), + ContainerStateStatusEnum::EXITED => "exited".to_string(), + ContainerStateStatusEnum::DEAD => "dead".to_string(), + _ => "unknown".to_string(), + }); + + // These are already Option from the Docker API + let started_at = state.clone().started_at; + let finished_at = state.clone().finished_at; + + Ok(Some(ContainerStatusInfo { + container_id: Some(container_id.to_string()), + status, + state: Some(format!("{:?}", state)), // Convert state to string + started_at, + finished_at, + })) + } + Err(_) => Ok(None), // Container not found + } +} \ No newline at end of file diff --git a/WatcherAgent/src/models.rs b/WatcherAgent/src/models.rs index 12019ec..92e762f 100644 --- a/WatcherAgent/src/models.rs +++ b/WatcherAgent/src/models.rs @@ -219,18 +219,24 @@ pub struct DockerMetricDto { /// network: network stats /// cpu: cpu stats /// ram: ram stats - pub containers: String, // Vec, + pub containers: Value, // Vec, } #[derive(Debug, Serialize, Clone)] pub struct DockerCollectMetricDto { pub id: String, + pub status: DockerContainerStatusDto, pub cpu: DockerContainerCpuDto, pub ram: DockerContainerRamDto, pub network: DockerContainerNetworkDto, } +#[derive(Debug, Serialize, Clone)] +pub struct DockerContainerStatusDto { + pub status: Option, +} + #[derive(Debug, Serialize, Clone)] pub struct DockerContainerCpuDto { pub cpu_load: Option, @@ -251,7 +257,7 @@ pub struct DockerContainerNetworkDto { #[derive(Debug, Serialize, Clone)] pub struct DockerContainerInfo { pub container: Option, - pub status: Option, // "running";"stopped";others + pub status: Option, // "running";"stopped";others pub network: Option, pub cpu: Option, pub ram: Option, From 7d6b5165c13728d8dbffc6f35b6bb9c1839da319 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Wed, 29 Oct 2025 22:45:39 +0100 Subject: [PATCH 06/11] changed noting --- WatcherAgent/src/api.rs | 2 +- WatcherAgent/src/docker/mod.rs | 4 ++-- WatcherAgent/src/models.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/WatcherAgent/src/api.rs b/WatcherAgent/src/api.rs index 5d6ced2..ebdbfea 100644 --- a/WatcherAgent/src/api.rs +++ b/WatcherAgent/src/api.rs @@ -430,7 +430,7 @@ pub async fn send_docker_metrics( ) -> Result<(), Box> { let client = Client::new(); let url = format!("{}/monitoring/docker-metric", base_url); - + println!("Docker Metrics: {}", serde_json::to_string_pretty(&docker_metrics)?); match client.post(&url).json(&docker_metrics).send().await { diff --git a/WatcherAgent/src/docker/mod.rs b/WatcherAgent/src/docker/mod.rs index dbdd1d5..72bc249 100644 --- a/WatcherAgent/src/docker/mod.rs +++ b/WatcherAgent/src/docker/mod.rs @@ -238,7 +238,7 @@ impl DockerManager { let container_infos: Vec = container_infos_total .into_iter() .filter_map(|info| { - let container = match info.container { + let _container = match info.container { Some(c) => c, None => { eprintln!("Warning: Container info missing container data, skipping"); @@ -286,7 +286,7 @@ impl DockerManager { }; Some(DockerCollectMetricDto { - id: container.id, + server_id: 0, status: status_dto, cpu: cpu_dto, ram: ram_dto, diff --git a/WatcherAgent/src/models.rs b/WatcherAgent/src/models.rs index 92e762f..b2920fb 100644 --- a/WatcherAgent/src/models.rs +++ b/WatcherAgent/src/models.rs @@ -160,7 +160,7 @@ pub struct ServerMessage { // Define your message structure here pub message_type: String, 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. @@ -225,7 +225,7 @@ pub struct DockerMetricDto { #[derive(Debug, Serialize, Clone)] pub struct DockerCollectMetricDto { - pub id: String, + pub server_id: u16, pub status: DockerContainerStatusDto, pub cpu: DockerContainerCpuDto, pub ram: DockerContainerRamDto, From c165ee9cc235530646086b440c7a09299941a1a3 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Wed, 29 Oct 2025 23:07:34 +0100 Subject: [PATCH 07/11] renamed docker detect dto --- WatcherAgent/src/api.rs | 4 ++-- WatcherAgent/src/docker/mod.rs | 6 +++--- WatcherAgent/src/main.rs | 2 +- WatcherAgent/src/models.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/WatcherAgent/src/api.rs b/WatcherAgent/src/api.rs index ebdbfea..9130e82 100644 --- a/WatcherAgent/src/api.rs +++ b/WatcherAgent/src/api.rs @@ -15,7 +15,7 @@ use std::time::Duration; use crate::docker::serverclientcomm::handle_server_message; use crate::hardware::HardwareInfo; use crate::models::{ - Acknowledgment, DockerMetricDto, DockerRegistrationDto, HeartbeatDto, + Acknowledgment, DockerMetricDto, DockerServiceDto, HeartbeatDto, IdResponse, MetricDto, RegistrationDto, ServerMessage, }; @@ -190,7 +190,7 @@ async fn get_server_id_by_ip( pub async fn broadcast_docker_containers( base_url: &str, server_id: u16, - container_dto: &DockerRegistrationDto, + container_dto: &DockerServiceDto, ) -> Result<(), Box> { // First get local IP println!("Preparing to broadcast docker containers..."); diff --git a/WatcherAgent/src/docker/mod.rs b/WatcherAgent/src/docker/mod.rs index 72bc249..be0c2c6 100644 --- a/WatcherAgent/src/docker/mod.rs +++ b/WatcherAgent/src/docker/mod.rs @@ -13,7 +13,7 @@ pub mod stats; use crate::models::{ DockerCollectMetricDto, DockerContainer, DockerContainerCpuDto, DockerContainerInfo, - DockerContainerNetworkDto, DockerContainerRamDto, DockerMetricDto, DockerRegistrationDto, + DockerContainerNetworkDto, DockerContainerRamDto, DockerMetricDto, DockerServiceDto, DockerContainerStatusDto }; use bollard::Docker; @@ -305,12 +305,12 @@ impl DockerManager { pub async fn create_registration_dto( &self, - ) -> Result> { + ) -> Result> { let containers = self.get_containers().await?; let container_string = serde_json::to_value(&containers)?; - let dto = DockerRegistrationDto { + let dto = DockerServiceDto { server_id: 0, // This will be set by the caller containers: container_string, }; diff --git a/WatcherAgent/src/main.rs b/WatcherAgent/src/main.rs index 97bf156..a565efe 100644 --- a/WatcherAgent/src/main.rs +++ b/WatcherAgent/src/main.rs @@ -115,7 +115,7 @@ async fn main() -> Result<(), Box> { docker_manager.create_registration_dto().await? } else { println!("Fallback for failing registration"); - models::DockerRegistrationDto { + models::DockerServiceDto { server_id: 0, //container_count: 0, --- IGNORE --- containers: serde_json::to_value(&"")?, diff --git a/WatcherAgent/src/models.rs b/WatcherAgent/src/models.rs index b2920fb..b178f8a 100644 --- a/WatcherAgent/src/models.rs +++ b/WatcherAgent/src/models.rs @@ -184,7 +184,7 @@ pub struct Acknowledgment { /// - `Name`: Container name (string) /// - `Status`: Container status ("running", "stopped", etc.) #[derive(Debug, Serialize, Clone)] -pub struct DockerRegistrationDto { +pub struct DockerServiceDto { /// Unique server identifier (integer) #[serde(rename = "Server_id")] pub server_id: u16, From 6405ab16e40914af1e5a1805d1a4583f4b81f450 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Thu, 30 Oct 2025 09:52:08 +0100 Subject: [PATCH 08/11] added documentation to /docker mod.rs --- WatcherAgent/src/api.rs | 25 ++++- WatcherAgent/src/docker/container.rs | 13 --- WatcherAgent/src/docker/mod.rs | 119 ++++++++++++++++++++++-- WatcherAgent/src/docker/stats/status.rs | 35 +++++++ WatcherAgent/src/models.rs | 2 +- 5 files changed, 171 insertions(+), 23 deletions(-) diff --git a/WatcherAgent/src/api.rs b/WatcherAgent/src/api.rs index 9130e82..368119b 100644 --- a/WatcherAgent/src/api.rs +++ b/WatcherAgent/src/api.rs @@ -424,6 +424,29 @@ pub async fn send_acknowledgment( Ok(()) } +/// Sends Docker container metrics to the backend monitoring endpoint. +/// +/// This function asynchronously transmits Docker container statistics including +/// CPU usage, memory consumption, network I/O, and container status to the +/// backend server for monitoring and analysis. +/// +/// # Arguments +/// +/// * `base_url` - The base URL of the backend server (e.g., "http://localhost:8080") +/// * `docker_metrics` - Reference to a [`DockerMetricDto`] containing container metrics data +/// +/// # Returns +/// +/// * `Ok(())` - If the HTTP request was successfully sent (regardless of HTTP status code) +/// * `Err(Box)` - If JSON serialization fails or other errors occur +/// +/// # Behavior +/// +/// - Constructs the full endpoint URL: `{base_url}/monitoring/docker-metric` +/// - Serializes the metrics data to pretty JSON for debugging output +/// - Sends a POST request with JSON content-type +/// - Logs success/failure messages to stdout/stderr +/// - Always returns `Ok(())` after request attempt (does not validate HTTP response status) pub async fn send_docker_metrics( base_url: &str, docker_metrics: &DockerMetricDto, @@ -431,7 +454,7 @@ pub async fn send_docker_metrics( let client = Client::new(); let url = format!("{}/monitoring/docker-metric", base_url); - println!("Docker Metrics: {}", serde_json::to_string_pretty(&docker_metrics)?); + println!("📤 JSON being posted:\n{}", serde_json::to_string_pretty(&docker_metrics)?); match client.post(&url).json(&docker_metrics).send().await { Ok(res) => println!( diff --git a/WatcherAgent/src/docker/container.rs b/WatcherAgent/src/docker/container.rs index 87daa6a..810f160 100644 --- a/WatcherAgent/src/docker/container.rs +++ b/WatcherAgent/src/docker/container.rs @@ -154,19 +154,6 @@ pub async fn restart_container( Ok(()) } -/* -/// Extracts a Docker container ID from a string line. -/// -/// # Arguments -/// * `line` - The input string containing a container ID or related info. -/// -/// # Returns -/// * `Option` - The extracted container ID if found. -pub fn extract_client_container_id(line: &str) -> Option { - // ...existing code... -} -*/ - /// Gets network statistics for a specific container pub async fn get_network_stats( docker: &Docker, diff --git a/WatcherAgent/src/docker/mod.rs b/WatcherAgent/src/docker/mod.rs index be0c2c6..494a64b 100644 --- a/WatcherAgent/src/docker/mod.rs +++ b/WatcherAgent/src/docker/mod.rs @@ -35,7 +35,15 @@ impl Default for DockerManager { } impl DockerManager { - /// Creates a new DockerManager instance + /// Creates a new DockerManager instance with Docker connection + /// + /// Establishes a connection to the local Docker daemon using default connection settings. + /// This is the primary constructor for the Docker manager. + /// + /// # Returns + /// + /// * `Ok(Self)` - Successfully connected Docker manager instance + /// * `Err(Box)` - If Docker daemon is not running or connection fails pub fn new() -> Result> { let docker = Docker::connect_with_local_defaults() .map_err(|e| format!("Failed to connect to Docker: {}", e))?; @@ -44,13 +52,31 @@ impl DockerManager { } /// Creates a DockerManager instance with optional Docker connection + /// + /// Attempts to connect to Docker but returns None instead of an error if connection fails. + /// Useful for scenarios where Docker availability is optional. + /// + /// # Returns + /// + /// * `Some(Self)` - If Docker connection is successful + /// * `None` - If Docker connection fails or Docker daemon is not available pub fn new_optional() -> Option { Docker::connect_with_local_defaults() .map(|docker| Self { docker }) .ok() } - /// Finds the Docker container running the agent by image name + + /// Finds the Docker container running the WatcherAgent by image name + /// + /// Searches through all available containers to find the one running the agent. + /// Matches containers whose image name contains "watcher-agent". + /// + /// # Returns + /// + /// * `Ok(Some(DockerContainer))` - Agent container found with full container details + /// * `Ok(None)` - No agent container found (agent may not be running in Docker) + /// * `Err(Box)` - If container enumeration fails pub async fn get_client_container( &self, ) -> Result, Box> { @@ -67,7 +93,14 @@ impl DockerManager { })) } - /// Gets the current client version (image name) if running in Docker + /// Gets the current client version from Docker image name + /// + /// Extracts the image name (without tag) from the agent's container. + /// Returns "unknown" if the agent is not running in Docker or if version cannot be determined. + /// + /// # Returns + /// + /// * `String` - Image name portion before ':' tag, or "unknown" if not determinable pub async fn get_client_version(&self) -> String { match self.get_client_container().await { Ok(Some(container)) => container @@ -90,6 +123,13 @@ impl DockerManager { } /// Checks if Docker is available and the agent is running in a container + /// + /// Determines whether the agent is operating within a Docker container environment. + /// This is used to enable/disable Docker-specific functionality. + /// + /// # Returns + /// + /// * `bool` - True if agent is running in Docker container, false otherwise pub async fn is_dockerized(&self) -> bool { self.get_client_container() .await @@ -97,7 +137,15 @@ impl DockerManager { .unwrap_or(false) } - /// Gets all available containers as DTOs for registration + /// Gets all available Docker containers as DTOs + /// + /// Retrieves a list of all containers (running and stopped) and converts them + /// to simplified DTOs suitable for registration with the backend server. + /// + /// # Returns + /// + /// * `Ok(Vec)` - List of all containers with id, image, and name + /// * `Err(Box)` - If container enumeration fails pub async fn get_containers( &self, ) -> Result, Box> { @@ -114,12 +162,32 @@ impl DockerManager { } /// Gets the number of running containers + /// + /// Counts all containers that are currently available (both running and stopped). + /// This provides a quick overview of container density on the host. + /// + /// # Returns + /// + /// * `Ok(usize)` - Total number of containers + /// * `Err(Box)` - If container counting fails pub async fn get_container_count(&self) -> Result> { let containers = container::get_available_containers(&self.docker).await; Ok(containers.len()) } /// Restarts a specific container by ID + /// + /// Initiates a restart of the specified container. This is typically used + /// in response to backend commands for container management. + /// + /// # Arguments + /// + /// * `container_id` - The full or partial container ID to restart + /// + /// # Returns + /// + /// * `Ok(())` - Container restart successfully initiated + /// * `Err(Box)` - If container not found or restart fails pub async fn restart_container( &self, container_id: &str, @@ -127,7 +195,16 @@ impl DockerManager { container::restart_container(&self.docker, container_id).await } - /// Collects Docker metrics for all containers + /// Collects comprehensive Docker metrics for all containers + /// + /// Gathers CPU usage, memory consumption, network I/O, and status information + /// for all containers. Matches statistics to containers using container ID prefixes. + /// Returns partial data even if some statistics collection fails. + /// + /// # Returns + /// + /// * `Ok(DockerMetricDto)` - Complete metrics data for all containers + /// * `Err(Box)` - If critical failures occur pub async fn collect_metrics(&self) -> Result> { let containers = self.get_containers().await?; @@ -238,7 +315,7 @@ impl DockerManager { let container_infos: Vec = container_infos_total .into_iter() .filter_map(|info| { - let _container = match info.container { + let container = match info.container { Some(c) => c, None => { eprintln!("Warning: Container info missing container data, skipping"); @@ -286,7 +363,7 @@ impl DockerManager { }; Some(DockerCollectMetricDto { - server_id: 0, + id: container.id, status: status_dto, cpu: cpu_dto, ram: ram_dto, @@ -303,6 +380,15 @@ impl DockerManager { Ok(dto) } + /// Creates registration DTO with container information + /// + /// Prepares container data for initial registration with the backend server. + /// This includes basic container information without detailed metrics. + /// + /// # Returns + /// + /// * `Ok(DockerServiceDto)` - Container information ready for registration + /// * `Err(Box)` - If container enumeration fails pub async fn create_registration_dto( &self, ) -> Result> { @@ -322,16 +408,33 @@ impl DockerManager { // Keep these as utility functions if needed, but they should use DockerManager internally impl DockerContainer { /// Returns the container ID + /// + /// # Returns + /// + /// * `&str` - Full container ID string pub fn id(&self) -> &str { &self.id } - /// Returns the image name + /// Returns the container image name + /// + /// Returns "unknown" if the image name is not available. + /// + /// # Returns + /// + /// * `&str` - Image name or "unknown" if not available pub fn image(&self) -> &str { &self.image.as_deref().unwrap_or("unknown") } /// Returns the container name + /// + /// Returns "unknown" if the container name is not available. + /// Container names typically start with '/' in Docker. + /// + /// # Returns + /// + /// * `&str` - Container name or "unknown" if not available pub fn name(&self) -> &str { &self.name.as_deref().unwrap_or("unknown") } diff --git a/WatcherAgent/src/docker/stats/status.rs b/WatcherAgent/src/docker/stats/status.rs index 846ddd0..17221d1 100644 --- a/WatcherAgent/src/docker/stats/status.rs +++ b/WatcherAgent/src/docker/stats/status.rs @@ -5,6 +5,22 @@ use bollard::query_parameters::{ListContainersOptions, InspectContainerOptions}; use bollard::models::{ContainerSummaryStateEnum, ContainerStateStatusEnum}; /// Get status information for all containers +/// +/// # Arguments +/// +/// * `docker` - Reference to Docker client +/// +/// # Returns +/// +/// * `Ok(Vec)` - Vector of container status information +/// * `Err(Box)` - If Docker API call fails +/// +/// # Behavior +/// +/// - Lists all containers (including stopped ones) +/// - Converts container state enum to string representation +/// - Converts timestamp from i64 to string +/// - Returns basic status info (finished_at is not available in list view) pub async fn get_all_containers_status( docker: &Docker, ) -> Result, Box> { @@ -52,7 +68,26 @@ pub async fn get_all_containers_status( Ok(status_infos) } + /// Get status information for a specific container +/// +/// # Arguments +/// +/// * `docker` - Reference to Docker client +/// * `container_id` - ID of the container to inspect +/// +/// # Returns +/// +/// * `Ok(Some(ContainerStatusInfo))` - Status info if container found +/// * `Ok(None)` - If container not found +/// * `Err(Box)` - If Docker API call fails +/// +/// # Behavior +/// +/// - First tries to find container in list (faster) +/// - Falls back to container inspect for detailed info +/// - Provides more detailed information including finished_at timestamp +/// - Handles container not found case gracefully pub async fn get_single_container_status( docker: &Docker, container_id: &str, diff --git a/WatcherAgent/src/models.rs b/WatcherAgent/src/models.rs index b178f8a..0c91811 100644 --- a/WatcherAgent/src/models.rs +++ b/WatcherAgent/src/models.rs @@ -225,7 +225,7 @@ pub struct DockerMetricDto { #[derive(Debug, Serialize, Clone)] pub struct DockerCollectMetricDto { - pub server_id: u16, + pub id: String, pub status: DockerContainerStatusDto, pub cpu: DockerContainerCpuDto, pub ram: DockerContainerRamDto, From 4e28d57460632457ad6562505842113530892505 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Thu, 30 Oct 2025 09:57:24 +0100 Subject: [PATCH 09/11] added documentation to /docker/stats mod.rs --- WatcherAgent/src/docker/stats/mod.rs | 64 ++++++++++++++++++++++++++++ docker-compose.yaml | 20 --------- 2 files changed, 64 insertions(+), 20 deletions(-) delete mode 100644 docker-compose.yaml diff --git a/WatcherAgent/src/docker/stats/mod.rs b/WatcherAgent/src/docker/stats/mod.rs index 336f4b1..86a430b 100644 --- a/WatcherAgent/src/docker/stats/mod.rs +++ b/WatcherAgent/src/docker/stats/mod.rs @@ -46,6 +46,20 @@ use bollard::Docker; use std::error::Error; /// Get container statistics for all containers using an existing Docker client +/// +/// Collects comprehensive statistics for all containers including CPU usage, network I/O, +/// memory consumption, and container status. This is the primary function for gathering +/// complete container metrics in a single operation. +/// +/// # Arguments +/// +/// * `docker` - Reference to connected Docker client +/// +/// # Returns +/// +/// * `Ok((Vec, Vec, Vec, Vec))` - +/// Tuple containing vectors of CPU, network, memory, and status information for all containers +/// * `Err(Box)` - If any statistics collection fails pub async fn get_container_stats( docker: &Docker, ) -> Result< @@ -66,6 +80,20 @@ pub async fn get_container_stats( } /// Get container statistics for a specific container +/// +/// Retrieves detailed metrics for a single container identified by its ID. +/// Useful for targeted monitoring or when responding to container-specific commands. +/// +/// # Arguments +/// +/// * `docker` - Reference to connected Docker client +/// * `container_id` - The ID of the container to inspect +/// +/// # Returns +/// +/// * `Ok((Option, Option, Option, Option))` - +/// Tuple containing optional CPU, network, memory, and status information for the specified container +/// * `Err(Box)` - If statistics collection fails pub async fn get_single_container_stats( docker: &Docker, container_id: &str, @@ -84,6 +112,18 @@ pub async fn get_single_container_stats( } /// Get total network statistics across all containers +/// +/// Calculates the sum of network receive and transmit bytes across all containers. +/// This provides an overview of total network traffic generated by all containers. +/// +/// # Arguments +/// +/// * `docker` - Reference to connected Docker client +/// +/// # Returns +/// +/// * `Ok((u64, u64))` - Tuple containing total received bytes and total transmitted bytes +/// * `Err(Box)` - If network statistics collection fails pub async fn get_total_network_stats( docker: &Docker, ) -> Result<(u64, u64), Box> { @@ -91,11 +131,35 @@ pub async fn get_total_network_stats( } /// Get average CPU usage across all containers +/// +/// Calculates the average CPU usage percentage across all running containers. +/// This provides a high-level overview of container CPU utilization. +/// +/// # Arguments +/// +/// * `docker` - Reference to connected Docker client +/// +/// # Returns +/// +/// * `Ok(f64)` - Average CPU usage percentage across all containers (0.0-100.0) +/// * `Err(Box)` - If CPU statistics collection fails pub async fn get_average_cpu_usage(docker: &Docker) -> Result> { cpu::get_average_cpu_usage(docker).await } /// Get total memory usage across all containers +/// +/// Calculates the sum of memory usage across all containers. +/// This provides an overview of total memory consumption by all containers. +/// +/// # Arguments +/// +/// * `docker` - Reference to connected Docker client +/// +/// # Returns +/// +/// * `Ok(u64)` - Total memory usage in bytes across all containers +/// * `Err(Box)` - If memory statistics collection fails pub async fn get_total_memory_usage(docker: &Docker) -> Result> { ram::get_total_memory_usage(docker).await } diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index 3aac9f1..0000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,20 +0,0 @@ -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 From 4d8b5c39e5b344ed8c4fcfe8a2c0e68cc99e4af4 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Thu, 30 Oct 2025 13:33:47 +0100 Subject: [PATCH 10/11] docker stats nightmare --- WatcherAgent/src/docker/stats/cpu.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/WatcherAgent/src/docker/stats/cpu.rs b/WatcherAgent/src/docker/stats/cpu.rs index 3eab6eb..69eae23 100644 --- a/WatcherAgent/src/docker/stats/cpu.rs +++ b/WatcherAgent/src/docker/stats/cpu.rs @@ -51,19 +51,19 @@ pub async fn get_single_container_cpu_stats( if let (Some(cpu_usage), Some(pre_cpu_usage)) = (&cpu_stats.cpu_usage, &precpu_stats.cpu_usage) { - let cpu_delta = cpu_usage + let cpu_delta: f64 = cpu_usage .total_usage .unwrap_or(0) - .saturating_sub(pre_cpu_usage.total_usage.unwrap_or(0)); + .saturating_sub(pre_cpu_usage.total_usage.unwrap_or(0)) as f64; - let system_delta = cpu_stats + let system_delta: f64 = cpu_stats .system_cpu_usage .unwrap_or(0) - .saturating_sub(precpu_stats.system_cpu_usage.unwrap_or(0)); + .saturating_sub(precpu_stats.system_cpu_usage.unwrap_or(0)) as f64; let online_cpus = cpu_stats.online_cpus.unwrap_or(1); - let cpu_percent = if system_delta > 0 && online_cpus > 0 { + let cpu_percent = if system_delta > 0.0 && online_cpus > 0 { (cpu_delta as f64 / system_delta as f64) * online_cpus as f64 * 100.0 } else { 0.0 From 5d37f080755dc6edbcbefbca7a57818ae8aec427 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Sun, 2 Nov 2025 18:47:01 +0100 Subject: [PATCH 11/11] moved serde name to camleCase --- WatcherAgent/src/api.rs | 12 ++++------ WatcherAgent/src/docker/mod.rs | 9 ------- WatcherAgent/src/models.rs | 43 +++++++++++++++++++++------------- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/WatcherAgent/src/api.rs b/WatcherAgent/src/api.rs index 368119b..17dff17 100644 --- a/WatcherAgent/src/api.rs +++ b/WatcherAgent/src/api.rs @@ -207,16 +207,12 @@ pub async fn broadcast_docker_containers( loop { println!("Attempting to broadcast containers..."); - let json_body = serde_json::to_string_pretty(&broadcast_data)?; - println!("📤 JSON being posted:\n{}", json_body); + println!("📤 Docker-Services-json being posted:\n{}", serde_json::to_string_pretty(&broadcast_data)?); let url = format!("{}/monitoring/service-discovery", base_url); match client.post(&url).json(&container_dto).send().await { Ok(resp) if resp.status().is_success() => { - println!( - "✅ Successfully broadcasted following docker container: {:?}", - container_dto - ); + println!("✅ Successfully broadcasted docker services"); return Ok(()); } Ok(resp) => { @@ -284,7 +280,7 @@ pub async fn send_metrics( ) -> Result<(), Box> { let client = Client::new(); let url = format!("{}/monitoring/metric", base_url); - println!("Metrics: {:?}", metrics); + println!("📤 System-Metrics-json being posted:\n{}", serde_json::to_string_pretty(&metrics)?); match client.post(&url).json(&metrics).send().await { Ok(res) => println!( @@ -454,7 +450,7 @@ pub async fn send_docker_metrics( let client = Client::new(); let url = format!("{}/monitoring/docker-metric", base_url); - println!("📤 JSON being posted:\n{}", serde_json::to_string_pretty(&docker_metrics)?); + println!("📤 Docker-Metrics-json being posted:\n{}", serde_json::to_string_pretty(&docker_metrics)?); match client.post(&url).json(&docker_metrics).send().await { Ok(res) => println!( diff --git a/WatcherAgent/src/docker/mod.rs b/WatcherAgent/src/docker/mod.rs index 494a64b..662e1fb 100644 --- a/WatcherAgent/src/docker/mod.rs +++ b/WatcherAgent/src/docker/mod.rs @@ -219,15 +219,6 @@ impl DockerManager { } }; - println!( - "Debug: Found {} containers, {} CPU stats, {} network stats, {} memory stats, {} status stats", - containers.len(), - cpu_stats.len(), - net_stats.len(), - mem_stats.len(), - status_stats.len(), - ); - let container_infos_total: Vec<_> = containers .into_iter() .map(|container| { diff --git a/WatcherAgent/src/models.rs b/WatcherAgent/src/models.rs index 0c91811..d9e53bd 100644 --- a/WatcherAgent/src/models.rs +++ b/WatcherAgent/src/models.rs @@ -63,31 +63,31 @@ pub struct MetricDto { pub server_id: u16, #[serde(rename = "ipAddress")] pub ip_address: String, - #[serde(rename = "cpu_Load")] + #[serde(rename = "cpuLoad")] pub cpu_load: f64, - #[serde(rename = "cpu_Temp")] + #[serde(rename = "cpuTemp")] pub cpu_temp: f64, - #[serde(rename = "gpu_Load")] + #[serde(rename = "gpuLoad")] pub gpu_load: f64, - #[serde(rename = "gpu_Temp")] + #[serde(rename = "gpuTemp")] pub gpu_temp: f64, - #[serde(rename = "gpu_Vram_Size")] + #[serde(rename = "gpuVramSize")] pub gpu_vram_size: f64, - #[serde(rename = "gpu_Vram_Load")] + #[serde(rename = "gpuVramLoad")] pub gpu_vram_load: f64, - #[serde(rename = "ram_Load")] + #[serde(rename = "ramLoad")] pub ram_load: f64, - #[serde(rename = "ram_Size")] + #[serde(rename = "ramSize")] pub ram_size: f64, - #[serde(rename = "disk_Size")] + #[serde(rename = "diskSize")] pub disk_size: f64, - #[serde(rename = "disk_Usage")] + #[serde(rename = "diskUsage")] pub disk_usage: f64, - #[serde(rename = "disk_Temp")] + #[serde(rename = "diskTemp")] pub disk_temp: f64, - #[serde(rename = "net_In")] + #[serde(rename = "netIn")] pub net_rx: f64, - #[serde(rename = "net_Out")] + #[serde(rename = "netOut")] pub net_tx: f64, } @@ -128,7 +128,7 @@ pub struct IdResponse { /// - `ip_address`: IPv4 or IPv6 address (string) #[derive(Serialize)] pub struct HeartbeatDto { - #[serde(rename = "IpAddress")] + #[serde(rename = "ipAddress")] pub ip_address: String, } @@ -142,10 +142,15 @@ pub struct HeartbeatDto { /// - `ip_address`: IPv4 or IPv6 address (string) #[derive(Serialize, Debug)] pub struct HardwareDto { + #[serde(rename = "cpuType")] pub cpu_type: String, + #[serde(rename = "cpuCore")] pub cpu_cores: i32, + #[serde(rename = "gpuType")] pub gpu_type: String, + #[serde(rename = "ramSize")] pub ram_size: f64, + #[serde(rename = "ipAddress")] pub ip_address: String, } @@ -186,7 +191,7 @@ pub struct Acknowledgment { #[derive(Debug, Serialize, Clone)] pub struct DockerServiceDto { /// Unique server identifier (integer) - #[serde(rename = "Server_id")] + #[serde(rename = "serverId")] pub server_id: u16, /// Number of currently running containers // pub container_count: usize, --- IGNORE --- @@ -199,12 +204,13 @@ pub struct DockerServiceDto { /// id: unique container ID (first 12 hex digits) /// image: docker image name /// name: container name - #[serde(rename = "Containers")] + #[serde(rename = "containers")] pub containers: Value, // Vec, } #[derive(Debug, Serialize, Clone)] pub struct DockerMetricDto { + #[serde(rename = "serverId")] pub server_id: u16, /// json stringified array of DockerContainer /// @@ -219,6 +225,7 @@ pub struct DockerMetricDto { /// network: network stats /// cpu: cpu stats /// ram: ram stats + #[serde(rename = "containers")] pub containers: Value, // Vec, } @@ -239,18 +246,22 @@ pub struct DockerContainerStatusDto { #[derive(Debug, Serialize, Clone)] pub struct DockerContainerCpuDto { + #[serde(rename = "cpuLoad")] pub cpu_load: Option, } #[derive(Debug, Serialize, Clone)] pub struct DockerContainerRamDto { + #[serde(rename = "ramLoad")] pub ram_load: Option, } #[derive(Debug, Serialize, Clone)] pub struct DockerContainerNetworkDto { + #[serde(rename = "netIn")] pub net_in: Option, + #[serde(rename = "netOut")] pub net_out: Option, }