Compare commits
16 Commits
v0.1.24
...
2a4cc4b2d5
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a4cc4b2d5 | |||
| c36b17fa05 | |||
| 375b4450f0 | |||
| b134be4c88 | |||
| 6afd5d0fcd | |||
| e02914516d | |||
| bf90d3ceb9 | |||
| a8ccb0521a | |||
| c90a276dca | |||
| dc4c23f9d9 | |||
| 3182d57539 | |||
| 8c1ef7f9f6 | |||
| 16020eea50 | |||
| 432a798210 | |||
| a095444222 | |||
| 5e7bc3df54 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -17,6 +17,9 @@ Cargo.lock
|
|||||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
*.pdb
|
*.pdb
|
||||||
|
|
||||||
|
.env
|
||||||
|
watcher-volumes
|
||||||
|
|
||||||
# RustRover
|
# RustRover
|
||||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
# 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
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
|||||||
578
WatcherAgent/-
Normal file
578
WatcherAgent/-
Normal file
@@ -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 <username> may not run sudo on <hostname>
|
||||||
|
#
|
||||||
|
# 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 <<EOF
|
||||||
|
I can't change your shell automatically because this system does not have chsh.
|
||||||
|
${FMT_BLUE}Please manually change your default shell to zsh${FMT_RESET}
|
||||||
|
EOF
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${FMT_BLUE}Time to change your default shell to zsh:${FMT_RESET}"
|
||||||
|
|
||||||
|
# Prompt for user choice on changing the default login shell
|
||||||
|
printf '%sDo you want to change your default shell to zsh? [Y/n]%s ' \
|
||||||
|
"$FMT_YELLOW" "$FMT_RESET"
|
||||||
|
read -r opt
|
||||||
|
case $opt in
|
||||||
|
[Yy]*|"") ;;
|
||||||
|
[Nn]*) echo "Shell change skipped."; return ;;
|
||||||
|
*) echo "Invalid choice. Shell change skipped."; return ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Check if we're running on Termux
|
||||||
|
case "$PREFIX" in
|
||||||
|
*com.termux*) termux=true; zsh=zsh ;;
|
||||||
|
*) termux=false ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ "$termux" != true ]; then
|
||||||
|
# Test for the right location of the "shells" file
|
||||||
|
if [ -f /etc/shells ]; then
|
||||||
|
shells_file=/etc/shells
|
||||||
|
elif [ -f /usr/share/defaults/etc/shells ]; then # Solus OS
|
||||||
|
shells_file=/usr/share/defaults/etc/shells
|
||||||
|
else
|
||||||
|
fmt_error "could not find /etc/shells file. Change your default shell manually."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get the path to the right zsh binary
|
||||||
|
# 1. Use the most preceding one based on $PATH, then check that it's in the shells file
|
||||||
|
# 2. If that fails, get a zsh path from the shells file, then check it actually exists
|
||||||
|
if ! zsh=$(command -v zsh) || ! grep -qx "$zsh" "$shells_file"; then
|
||||||
|
if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -n 1) || [ ! -f "$zsh" ]; then
|
||||||
|
fmt_error "no zsh binary found or not present in '$shells_file'"
|
||||||
|
fmt_error "change your default shell manually."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# We're going to change the default shell, so back up the current one
|
||||||
|
if [ -n "$SHELL" ]; then
|
||||||
|
echo "$SHELL" > "$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 <<EOF
|
||||||
|
|
||||||
|
You ran the installer with the \$ZSH setting or the \$ZSH variable is
|
||||||
|
exported. You have 3 options:
|
||||||
|
|
||||||
|
1. Unset the ZSH variable when calling the installer:
|
||||||
|
$(fmt_code "ZSH= sh install.sh")
|
||||||
|
2. Install Oh My Zsh to a directory that doesn't exist yet:
|
||||||
|
$(fmt_code "ZSH=path/to/new/ohmyzsh/folder sh install.sh")
|
||||||
|
3. (Caution) If the folder doesn't contain important information,
|
||||||
|
you can just remove it with $(fmt_code "rm -r $ZSH")
|
||||||
|
|
||||||
|
EOF
|
||||||
|
else
|
||||||
|
echo "You'll need to remove it if you want to reinstall."
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create ZDOTDIR folder structure if it doesn't exist
|
||||||
|
if [ -n "$ZDOTDIR" ]; then
|
||||||
|
mkdir -p "$ZDOTDIR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
setup_ohmyzsh
|
||||||
|
setup_zshrc
|
||||||
|
setup_shell
|
||||||
|
|
||||||
|
print_success
|
||||||
|
|
||||||
|
if [ $RUNZSH = no ]; then
|
||||||
|
echo "${FMT_YELLOW}Run zsh to try it out.${FMT_RESET}"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec zsh -l
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
@@ -12,12 +12,11 @@
|
|||||||
/// These functions are called from the main agent loop and background tasks. All network operations are asynchronous and robust to transient failures.
|
/// These functions are called from the main agent loop and background tasks. All network operations are asynchronous and robust to transient failures.
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::docker::container;
|
|
||||||
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, IdResponse, MetricDto,
|
Acknowledgment, DockerMetricDto, DockerRegistrationDto, HeartbeatDto,
|
||||||
RegistrationDto, ServerMessage,
|
IdResponse, MetricDto, RegistrationDto, ServerMessage,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
@@ -153,11 +152,46 @@ async fn get_server_id_by_ip(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Broadcasts Docker container information to the monitoring server for service discovery.
|
||||||
|
///
|
||||||
|
/// This function sends the current Docker container configuration to the server
|
||||||
|
/// to register available containers and enable service monitoring. It will
|
||||||
|
/// continuously retry until successful, making it suitable for initial
|
||||||
|
/// registration scenarios.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `base_url` - The base URL of the monitoring server API (e.g., "https://monitoring.example.com")
|
||||||
|
/// * `server_id` - The ID of the server to associate the containers with
|
||||||
|
/// * `container_dto` - Mutable reference to Docker container information for broadcast
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// * `Ok(())` - When container information is successfully broadcasted to the server
|
||||||
|
/// * `Err(Box<dyn Error + Send + Sync>)` - If an unrecoverable error occurs (though the function typically retries on transient failures)
|
||||||
|
///
|
||||||
|
/// # Behavior
|
||||||
|
///
|
||||||
|
/// This function operates in a retry loop with the following characteristics:
|
||||||
|
///
|
||||||
|
/// - **Retry Logic**: Attempts broadcast every 10 seconds until successful
|
||||||
|
/// - **Mutation**: Modifies the `container_dto` to set the `server_id` before sending
|
||||||
|
/// - **TLS**: Accepts invalid TLS certificates for development environments
|
||||||
|
/// - **Logging**: Provides detailed console output about broadcast attempts and results
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This function may return an error in the following cases:
|
||||||
|
///
|
||||||
|
/// * **HTTP Client Creation**: Failed to create HTTP client with TLS configuration
|
||||||
|
/// * **Network Issues**: Persistent connection failures to the backend server
|
||||||
|
/// * **Server Errors**: Backend returns non-success HTTP status codes repeatedly
|
||||||
|
/// * **JSON Serialization**: Cannot serialize container data (should be rare with proper DTOs)
|
||||||
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: &mut DockerRegistrationDto,
|
container_dto: &DockerRegistrationDto,
|
||||||
) -> Result<(u16, String), 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...");
|
||||||
// Create HTTP client for registration
|
// Create HTTP client for registration
|
||||||
@@ -166,16 +200,24 @@ pub async fn broadcast_docker_containers(
|
|||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
// Prepare registration data
|
// Prepare registration data
|
||||||
let container_dto = container_dto;
|
let mut broadcast_data = container_dto.clone();
|
||||||
container_dto.server_id = server_id;
|
broadcast_data.server_id = server_id;
|
||||||
|
|
||||||
// Try to register (will retry on failure)
|
// Try to register (will retry on failure)
|
||||||
loop {
|
loop {
|
||||||
println!("Attempting to broadcast containers...");
|
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);
|
let url = format!("{}/monitoring/service-discovery", base_url);
|
||||||
match client.post(&url).json(&container_dto).send().await {
|
match client.post(&url).json(&container_dto).send().await {
|
||||||
Ok(resp) if resp.status().is_success() => {
|
Ok(resp) if resp.status().is_success() => {
|
||||||
println!("✅ Successfully broadcasted docker container.");
|
println!(
|
||||||
|
"✅ Successfully broadcasted following docker container: {:?}",
|
||||||
|
container_dto
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
let status = resp.status();
|
let status = resp.status();
|
||||||
@@ -388,7 +430,8 @@ pub async fn send_docker_metrics(
|
|||||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let url = format!("{}/monitoring/docker-metric", base_url);
|
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 {
|
match client.post(&url).json(&docker_metrics).send().await {
|
||||||
Ok(res) => println!(
|
Ok(res) => println!(
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ pub async fn get_network_stats(
|
|||||||
docker: &Docker,
|
docker: &Docker,
|
||||||
container_id: &str,
|
container_id: &str,
|
||||||
) -> Result<ContainerNetworkInfo, Box<dyn Error + Send + Sync>> {
|
) -> Result<ContainerNetworkInfo, Box<dyn Error + Send + Sync>> {
|
||||||
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 {
|
if let Some(net_info) = net_info {
|
||||||
Ok(net_info)
|
Ok(net_info)
|
||||||
@@ -196,7 +196,7 @@ pub async fn get_cpu_stats(
|
|||||||
docker: &Docker,
|
docker: &Docker,
|
||||||
container_id: &str,
|
container_id: &str,
|
||||||
) -> Result<ContainerCpuInfo, Box<dyn Error + Send + Sync>> {
|
) -> Result<ContainerCpuInfo, Box<dyn Error + Send + Sync>> {
|
||||||
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 {
|
if let Some(cpu_info) = cpu_info {
|
||||||
Ok(cpu_info)
|
Ok(cpu_info)
|
||||||
|
|||||||
@@ -14,6 +14,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, DockerRegistrationDto,
|
||||||
|
DockerContainerStatusDto
|
||||||
};
|
};
|
||||||
use bollard::Docker;
|
use bollard::Docker;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
@@ -129,27 +130,104 @@ impl DockerManager {
|
|||||||
/// Collects Docker metrics for all containers
|
/// Collects Docker metrics for all containers
|
||||||
pub async fn collect_metrics(&self) -> Result<DockerMetricDto, Box<dyn Error + Send + Sync>> {
|
pub async fn collect_metrics(&self) -> Result<DockerMetricDto, Box<dyn Error + Send + Sync>> {
|
||||||
let containers = self.get_containers().await?;
|
let containers = self.get_containers().await?;
|
||||||
let (cpu_stats, net_stats, mem_stats) = stats::get_container_stats(&self.docker).await?;
|
|
||||||
|
// Get stats with status information
|
||||||
|
let stats_result = stats::get_container_stats(&self.docker).await;
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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
|
let container_infos_total: Vec<_> = containers
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|container| {
|
.map(|container| {
|
||||||
|
// Use short ID for matching (first 12 chars)
|
||||||
|
let container_short_id = if container.id.len() > 12 {
|
||||||
|
&container.id[..12]
|
||||||
|
} else {
|
||||||
|
&container.id
|
||||||
|
};
|
||||||
|
|
||||||
let cpu = cpu_stats
|
let cpu = cpu_stats
|
||||||
.iter()
|
.iter()
|
||||||
.find(|c| c.container_id == Some(container.id.clone()))
|
.find(|c| {
|
||||||
|
c.container_id
|
||||||
|
.as_ref()
|
||||||
|
.map(|id| id.starts_with(container_short_id))
|
||||||
|
.unwrap_or(false)
|
||||||
|
})
|
||||||
.cloned();
|
.cloned();
|
||||||
|
|
||||||
let network = net_stats
|
let network = net_stats
|
||||||
.iter()
|
.iter()
|
||||||
.find(|n| n.container_id == Some(container.id.clone()))
|
.find(|n| {
|
||||||
|
n.container_id
|
||||||
|
.as_ref()
|
||||||
|
.map(|id| id.starts_with(container_short_id))
|
||||||
|
.unwrap_or(false)
|
||||||
|
})
|
||||||
.cloned();
|
.cloned();
|
||||||
|
|
||||||
let ram = mem_stats
|
let ram = mem_stats
|
||||||
.iter()
|
.iter()
|
||||||
.find(|m| m.container_id == Some(container.id.clone()))
|
.find(|m| {
|
||||||
|
m.container_id
|
||||||
|
.as_ref()
|
||||||
|
.map(|id| id.starts_with(container_short_id))
|
||||||
|
.unwrap_or(false)
|
||||||
|
})
|
||||||
.cloned();
|
.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: {:?}, Status {:?}",
|
||||||
|
container_short_id,
|
||||||
|
cpu.is_some(),
|
||||||
|
network.is_some(),
|
||||||
|
ram.is_some(),
|
||||||
|
status.is_some()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 {
|
DockerContainerInfo {
|
||||||
container: Some(container),
|
container: Some(container),
|
||||||
status: None, // Status can be fetched if needed
|
status,
|
||||||
cpu,
|
cpu,
|
||||||
network,
|
network,
|
||||||
ram,
|
ram,
|
||||||
@@ -159,44 +237,67 @@ impl DockerManager {
|
|||||||
|
|
||||||
let container_infos: Vec<DockerCollectMetricDto> = container_infos_total
|
let container_infos: Vec<DockerCollectMetricDto> = container_infos_total
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|info| DockerCollectMetricDto {
|
.filter_map(|info| {
|
||||||
id: Some(info.container.unwrap().id).unwrap_or("".to_string()),
|
let container = match info.container {
|
||||||
cpu: info
|
Some(c) => c,
|
||||||
.cpu
|
None => {
|
||||||
.unwrap()
|
eprintln!("Warning: Container info missing container data, skipping");
|
||||||
.cpu_usage_percent
|
return None;
|
||||||
.map(|load| DockerContainerCpuDto {
|
}
|
||||||
cpu_load: Some(load),
|
};
|
||||||
|
|
||||||
|
// Safely handle CPU data with defaults
|
||||||
|
let cpu_dto = if let Some(cpu) = info.cpu {
|
||||||
|
DockerContainerCpuDto {
|
||||||
|
cpu_load: cpu.cpu_usage_percent,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DockerContainerCpuDto { cpu_load: None }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Safely handle RAM data with defaults
|
||||||
|
let ram_dto = if let Some(ram) = info.ram {
|
||||||
|
DockerContainerRamDto {
|
||||||
|
ram_load: ram.memory_usage_percent,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DockerContainerRamDto { ram_load: None }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Safely handle network data with defaults
|
||||||
|
let network_dto = if let Some(net) = info.network {
|
||||||
|
DockerContainerNetworkDto {
|
||||||
|
net_in: net.rx_bytes.map(|bytes| bytes as f64),
|
||||||
|
net_out: net.tx_bytes.map(|bytes| bytes as f64),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DockerContainerNetworkDto {
|
||||||
|
net_in: None,
|
||||||
|
net_out: None,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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,
|
||||||
})
|
})
|
||||||
.unwrap_or(DockerContainerCpuDto { cpu_load: None }),
|
|
||||||
ram: info
|
|
||||||
.ram
|
|
||||||
.unwrap()
|
|
||||||
.memory_usage_percent
|
|
||||||
.map(|load| DockerContainerRamDto {
|
|
||||||
cpu_load: Some(load),
|
|
||||||
})
|
|
||||||
.unwrap_or(DockerContainerRamDto { cpu_load: None }),
|
|
||||||
network: DockerContainerNetworkDto {
|
|
||||||
net_in: info
|
|
||||||
.network
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.rx_bytes
|
|
||||||
.map(|bytes| bytes as f64)
|
|
||||||
.or(Some(0.0)),
|
|
||||||
net_out: info
|
|
||||||
.network
|
|
||||||
.unwrap()
|
|
||||||
.tx_bytes
|
|
||||||
.map(|bytes| bytes as f64)
|
|
||||||
.or(Some(0.0)),
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let dto = DockerMetricDto {
|
let dto = DockerMetricDto {
|
||||||
server_id: 0,
|
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)
|
Ok(dto)
|
||||||
@@ -206,10 +307,12 @@ impl DockerManager {
|
|||||||
&self,
|
&self,
|
||||||
) -> Result<DockerRegistrationDto, Box<dyn Error + Send + Sync>> {
|
) -> Result<DockerRegistrationDto, 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 dto = DockerRegistrationDto {
|
let dto = DockerRegistrationDto {
|
||||||
server_id: 0,
|
server_id: 0, // This will be set by the caller
|
||||||
//container_count,
|
containers: container_string,
|
||||||
containers: serde_json::to_string(&containers)?,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(dto)
|
Ok(dto)
|
||||||
|
|||||||
@@ -1,9 +1,19 @@
|
|||||||
pub mod cpu;
|
pub mod cpu;
|
||||||
pub mod network;
|
pub mod network;
|
||||||
pub mod ram;
|
pub mod ram;
|
||||||
|
pub mod status;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct ContainerStatusInfo {
|
||||||
|
pub container_id: Option<String>,
|
||||||
|
pub status: Option<String>, // "running", "stopped", "paused", "exited", etc.
|
||||||
|
pub state: Option<String>, // More detailed state information
|
||||||
|
pub started_at: Option<String>,
|
||||||
|
pub finished_at: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ContainerCpuInfo {
|
pub struct ContainerCpuInfo {
|
||||||
pub container_id: Option<String>,
|
pub container_id: Option<String>,
|
||||||
@@ -43,33 +53,34 @@ pub async fn get_container_stats(
|
|||||||
Vec<ContainerCpuInfo>,
|
Vec<ContainerCpuInfo>,
|
||||||
Vec<ContainerNetworkInfo>,
|
Vec<ContainerNetworkInfo>,
|
||||||
Vec<ContainerMemoryInfo>,
|
Vec<ContainerMemoryInfo>,
|
||||||
|
Vec<ContainerStatusInfo>,
|
||||||
),
|
),
|
||||||
Box<dyn Error + Send + Sync>,
|
Box<dyn Error + Send + Sync>,
|
||||||
> {
|
> {
|
||||||
let cpu_infos = cpu::get_all_containers_cpu_stats(docker).await?;
|
let cpu_infos = cpu::get_all_containers_cpu_stats(docker).await?;
|
||||||
let net_infos = network::get_all_containers_network_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 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
|
/// Get container statistics for a specific container
|
||||||
pub async fn get_single_container_stats(
|
pub async fn get_single_container_stats(
|
||||||
docker: &Docker,
|
docker: &Docker,
|
||||||
container_id: &str,
|
container_id: &str,
|
||||||
) -> Result<
|
) -> Result<(
|
||||||
(
|
|
||||||
Option<ContainerCpuInfo>,
|
Option<ContainerCpuInfo>,
|
||||||
Option<ContainerNetworkInfo>,
|
Option<ContainerNetworkInfo>,
|
||||||
Option<ContainerMemoryInfo>,
|
Option<ContainerMemoryInfo>,
|
||||||
),
|
Option<ContainerStatusInfo>,
|
||||||
Box<dyn Error + Send + Sync>,
|
), Box<dyn Error + Send + Sync>> {
|
||||||
> {
|
|
||||||
let cpu_info = cpu::get_single_container_cpu_stats(docker, container_id).await?;
|
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 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 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
|
/// Get total network statistics across all containers
|
||||||
|
|||||||
126
WatcherAgent/src/docker/stats/status.rs
Normal file
126
WatcherAgent/src/docker/stats/status.rs
Normal file
@@ -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<Vec<ContainerStatusInfo>, Box<dyn Error + Send + Sync>> {
|
||||||
|
|
||||||
|
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<Option<ContainerStatusInfo>, Box<dyn Error + Send + Sync>> {
|
||||||
|
// 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::<InspectContainerOptions>).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<String> 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,10 +31,8 @@ pub mod hardware;
|
|||||||
pub mod metrics;
|
pub mod metrics;
|
||||||
pub mod models;
|
pub mod models;
|
||||||
|
|
||||||
use bollard::Docker;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
|
|
||||||
/// Awaits a spawned asynchronous task and flattens its nested `Result` type.
|
/// Awaits a spawned asynchronous task and flattens its nested `Result` type.
|
||||||
@@ -116,10 +114,11 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
|||||||
let container_dto = if let Some(ref docker_manager) = docker_manager {
|
let container_dto = if let Some(ref docker_manager) = docker_manager {
|
||||||
docker_manager.create_registration_dto().await?
|
docker_manager.create_registration_dto().await?
|
||||||
} else {
|
} else {
|
||||||
|
println!("Fallback for failing registration");
|
||||||
models::DockerRegistrationDto {
|
models::DockerRegistrationDto {
|
||||||
server_id: 0,
|
server_id: 0,
|
||||||
//container_count: 0, --- IGNORE ---
|
//container_count: 0, --- IGNORE ---
|
||||||
containers: "[]".to_string(),
|
containers: serde_json::to_value(&"")?,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let _ =
|
let _ =
|
||||||
@@ -153,7 +152,13 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
|||||||
let docker_manager = docker_manager.as_ref().cloned().unwrap();
|
let docker_manager = docker_manager.as_ref().cloned().unwrap();
|
||||||
async move {
|
async move {
|
||||||
let mut collector = metrics::Collector::new(server_id, ip, docker_manager);
|
let mut collector = metrics::Collector::new(server_id, ip, docker_manager);
|
||||||
collector.run(&server_url).await
|
if let Err(e) = collector.run(&server_url).await {
|
||||||
|
eprintln!("Metrics collection error: {}", e);
|
||||||
|
// Don't panic, just return the error
|
||||||
|
Err(e)
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
use crate::docker::stats;
|
use crate::docker::stats;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
/// Registration data sent to the backend server.
|
/// Registration data sent to the backend server.
|
||||||
///
|
///
|
||||||
@@ -182,12 +183,10 @@ pub struct Acknowledgment {
|
|||||||
/// - `image`: Docker image name (string)
|
/// - `image`: Docker image name (string)
|
||||||
/// - `Name`: Container name (string)
|
/// - `Name`: Container name (string)
|
||||||
/// - `Status`: Container status ("running", "stopped", etc.)
|
/// - `Status`: Container status ("running", "stopped", etc.)
|
||||||
/// - `_net_in`: Network receive rate in **bytes per second (B/s)**
|
|
||||||
/// - `_net_out`: Network transmit rate in **bytes per second (B/s)**
|
|
||||||
/// - `_cpu_load`: CPU usage as a percentage (**0.0–100.0**)
|
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
pub struct DockerRegistrationDto {
|
pub struct DockerRegistrationDto {
|
||||||
/// Unique server identifier (integer)
|
/// Unique server identifier (integer)
|
||||||
|
#[serde(rename = "Server_id")]
|
||||||
pub server_id: u16,
|
pub server_id: u16,
|
||||||
/// Number of currently running containers
|
/// Number of currently running containers
|
||||||
// pub container_count: usize, --- IGNORE ---
|
// pub container_count: usize, --- IGNORE ---
|
||||||
@@ -200,7 +199,8 @@ pub struct DockerRegistrationDto {
|
|||||||
/// id: unique container ID (first 12 hex digits)
|
/// id: unique container ID (first 12 hex digits)
|
||||||
/// image: docker image name
|
/// image: docker image name
|
||||||
/// name: container name
|
/// name: container name
|
||||||
pub containers: String, // Vec<DockerContainer>,
|
#[serde(rename = "Containers")]
|
||||||
|
pub containers: Value, // Vec<DockerContainer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
@@ -219,18 +219,24 @@ pub struct DockerMetricDto {
|
|||||||
/// network: network stats
|
/// network: network stats
|
||||||
/// cpu: cpu stats
|
/// cpu: cpu stats
|
||||||
/// ram: ram stats
|
/// ram: ram stats
|
||||||
pub containers: String, // Vec<DockerContainerInfo>,
|
pub containers: Value, // Vec<DockerContainerInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
|
|
||||||
pub struct DockerCollectMetricDto {
|
pub struct DockerCollectMetricDto {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
pub status: DockerContainerStatusDto,
|
||||||
pub cpu: DockerContainerCpuDto,
|
pub cpu: DockerContainerCpuDto,
|
||||||
pub ram: DockerContainerRamDto,
|
pub ram: DockerContainerRamDto,
|
||||||
pub network: DockerContainerNetworkDto,
|
pub network: DockerContainerNetworkDto,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Clone)]
|
||||||
|
pub struct DockerContainerStatusDto {
|
||||||
|
pub status: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
pub struct DockerContainerCpuDto {
|
pub struct DockerContainerCpuDto {
|
||||||
pub cpu_load: Option<f64>,
|
pub cpu_load: Option<f64>,
|
||||||
@@ -238,7 +244,7 @@ pub struct DockerContainerCpuDto {
|
|||||||
|
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
pub struct DockerContainerRamDto {
|
pub struct DockerContainerRamDto {
|
||||||
pub cpu_load: Option<f64>,
|
pub ram_load: Option<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
@@ -251,7 +257,7 @@ pub struct DockerContainerNetworkDto {
|
|||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
pub struct DockerContainerInfo {
|
pub struct DockerContainerInfo {
|
||||||
pub container: Option<DockerContainer>,
|
pub container: Option<DockerContainer>,
|
||||||
pub status: Option<String>, // "running";"stopped";others
|
pub status: Option<stats::ContainerStatusInfo>, // "running";"stopped";others
|
||||||
pub network: Option<stats::ContainerNetworkInfo>,
|
pub network: Option<stats::ContainerNetworkInfo>,
|
||||||
pub cpu: Option<stats::ContainerCpuInfo>,
|
pub cpu: Option<stats::ContainerCpuInfo>,
|
||||||
pub ram: Option<stats::ContainerMemoryInfo>,
|
pub ram: Option<stats::ContainerMemoryInfo>,
|
||||||
@@ -260,6 +266,8 @@ pub struct DockerContainerInfo {
|
|||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
pub struct DockerContainer {
|
pub struct DockerContainer {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
#[serde(default)]
|
||||||
pub image: Option<String>,
|
pub image: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
pub name: Option<String>,
|
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:
|
networks:
|
||||||
image: git.triggermeelmo.com/donpat1to/watcher-agent:development
|
watcher-network:
|
||||||
container_name: watcher-agent
|
driver: bridge
|
||||||
restart: always
|
|
||||||
privileged: true # Grants full hardware access (use with caution)
|
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
|
env_file: .env
|
||||||
pid: "host"
|
ports:
|
||||||
|
- "5000:5000"
|
||||||
volumes:
|
volumes:
|
||||||
# Mount critical system paths for hardware monitoring
|
- ./watcher-volumes/data:/app/persistence
|
||||||
- /sys:/sys:ro # CPU/GPU temps, sensors
|
- ./watcher-volumes/dumps:/app/wwwroot/downloads/sqlite
|
||||||
- /proc:/proc # Process/CPU stats
|
- ./watcher-volumes/logs:/app/logs
|
||||||
- /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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user