mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-05 14:35:35 +00:00
Fixed <1GB Ram issue with it throwing integer error
This commit is contained in:
@@ -683,11 +683,21 @@ get_hardware_info() {
|
|||||||
|
|
||||||
# Memory Information
|
# Memory Information
|
||||||
if command -v free >/dev/null 2>&1; then
|
if command -v free >/dev/null 2>&1; then
|
||||||
ram_installed=$(free -g | grep "^Mem:" | awk '{print $2}')
|
# Use free -m to get MB, then convert to GB with decimal precision
|
||||||
swap_size=$(free -g | grep "^Swap:" | awk '{print $2}')
|
ram_installed=$(free -m | grep "^Mem:" | awk '{printf "%.2f", $2/1024}')
|
||||||
|
swap_size=$(free -m | grep "^Swap:" | awk '{printf "%.2f", $2/1024}')
|
||||||
elif [[ -f /proc/meminfo ]]; then
|
elif [[ -f /proc/meminfo ]]; then
|
||||||
ram_installed=$(grep "MemTotal" /proc/meminfo | awk '{print int($2/1024/1024)}')
|
# Convert KB to GB with decimal precision
|
||||||
swap_size=$(grep "SwapTotal" /proc/meminfo | awk '{print int($2/1024/1024)}')
|
ram_installed=$(grep "MemTotal" /proc/meminfo | awk '{printf "%.2f", $2/1048576}')
|
||||||
|
swap_size=$(grep "SwapTotal" /proc/meminfo | awk '{printf "%.2f", $2/1048576}')
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure minimum value of 0.01GB to prevent 0 values
|
||||||
|
if (( $(echo "$ram_installed < 0.01" | bc -l) )); then
|
||||||
|
ram_installed="0.01"
|
||||||
|
fi
|
||||||
|
if (( $(echo "$swap_size < 0" | bc -l) )); then
|
||||||
|
swap_size="0"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Disk Information
|
# Disk Information
|
||||||
|
|||||||
@@ -281,12 +281,12 @@ router.post(
|
|||||||
.withMessage("CPU cores must be a positive integer"),
|
.withMessage("CPU cores must be a positive integer"),
|
||||||
body("ramInstalled")
|
body("ramInstalled")
|
||||||
.optional()
|
.optional()
|
||||||
.isInt({ min: 1 })
|
.isFloat({ min: 0.01 })
|
||||||
.withMessage("RAM installed must be a positive integer"),
|
.withMessage("RAM installed must be a positive number"),
|
||||||
body("swapSize")
|
body("swapSize")
|
||||||
.optional()
|
.optional()
|
||||||
.isInt({ min: 0 })
|
.isFloat({ min: 0 })
|
||||||
.withMessage("Swap size must be a non-negative integer"),
|
.withMessage("Swap size must be a non-negative number"),
|
||||||
body("diskDetails")
|
body("diskDetails")
|
||||||
.optional()
|
.optional()
|
||||||
.isArray()
|
.isArray()
|
||||||
|
|||||||
Reference in New Issue
Block a user