Compare commits
2
Commits
9333334b7b
...
84946ed0c6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84946ed0c6 | ||
|
|
514e13660c |
@@ -143,8 +143,10 @@ if [[ "$SHOW_STATUS" == true ]]; then
|
|||||||
echo "━━━ System Logs ━━━"
|
echo "━━━ System Logs ━━━"
|
||||||
for f in "${LOG_FILES[@]}"; do
|
for f in "${LOG_FILES[@]}"; do
|
||||||
if [[ -f "$f" ]]; then
|
if [[ -f "$f" ]]; then
|
||||||
size=$(du -sh "$f" 2>/dev/null | cut -f1)
|
# One traversal, then formatted — this used to run du twice over the same path,
|
||||||
size_mb=$(du -sm "$f" 2>/dev/null | cut -f1)
|
# once for the display string and once for the comparison.
|
||||||
|
size_mb=$(dir_size_mb "$f") || size_mb=0
|
||||||
|
size=$(format_mb "$size_mb")
|
||||||
threshold="${LOG_MIN_SIZE_MB:-10}"
|
threshold="${LOG_MIN_SIZE_MB:-10}"
|
||||||
if [[ "${size_mb:-0}" -ge "$threshold" ]]; then
|
if [[ "${size_mb:-0}" -ge "$threshold" ]]; then
|
||||||
echo " $ICON_WARN $f — $size (above ${threshold}MB threshold — would clear)"
|
echo " $ICON_WARN $f — $size (above ${threshold}MB threshold — would clear)"
|
||||||
@@ -161,7 +163,7 @@ if [[ "$SHOW_STATUS" == true ]]; then
|
|||||||
if [[ -d /var/lib/docker/containers ]]; then
|
if [[ -d /var/lib/docker/containers ]]; then
|
||||||
find /var/lib/docker/containers/ -name "*-json.log" 2>/dev/null | \
|
find /var/lib/docker/containers/ -name "*-json.log" 2>/dev/null | \
|
||||||
while IFS= read -r logfile; do
|
while IFS= read -r logfile; do
|
||||||
size_mb=$(du -sm "$logfile" 2>/dev/null | cut -f1)
|
size_mb=$(dir_size_mb "$logfile") || size_mb=0
|
||||||
container_id=$(basename "$(dirname "$logfile")" | cut -c1-12)
|
container_id=$(basename "$(dirname "$logfile")" | cut -c1-12)
|
||||||
container_name=$(docker inspect --format '{{.Name}}' "$container_id" \
|
container_name=$(docker inspect --format '{{.Name}}' "$container_id" \
|
||||||
2>/dev/null | tr -d '/' || echo "$container_id")
|
2>/dev/null | tr -d '/' || echo "$container_id")
|
||||||
@@ -204,9 +206,12 @@ for logfile in "${LOG_FILES[@]}"; do
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
size_bytes=$(stat -c%s "$logfile" 2>/dev/null || echo 0)
|
# Same basis as the dry-run preview above. This measured stat -c%s (apparent size) while the
|
||||||
size_mb=$(( size_bytes / 1048576 ))
|
# preview measured du (allocated blocks), so a file sitting on LOG_MIN_SIZE_MB could be shown
|
||||||
size_h=$(du -sh "$logfile" 2>/dev/null | cut -f1)
|
# as under the threshold and then cleared, or the reverse. A dry run that disagrees with the
|
||||||
|
# real run about what it will touch is worse than no dry run.
|
||||||
|
size_mb=$(dir_size_mb "$logfile") || size_mb=0
|
||||||
|
size_h=$(format_mb "$size_mb")
|
||||||
threshold="${LOG_MIN_SIZE_MB:-10}"
|
threshold="${LOG_MIN_SIZE_MB:-10}"
|
||||||
|
|
||||||
if [[ "$size_mb" -lt "$threshold" ]]; then
|
if [[ "$size_mb" -lt "$threshold" ]]; then
|
||||||
@@ -239,9 +244,10 @@ else
|
|||||||
while IFS= read -r logfile; do
|
while IFS= read -r logfile; do
|
||||||
[[ -z "$logfile" ]] && continue
|
[[ -z "$logfile" ]] && continue
|
||||||
|
|
||||||
size_bytes=$(stat -c%s "$logfile" 2>/dev/null || echo 0)
|
# du basis, matching the "top 10 by size" listing above — that ranked and previewed on
|
||||||
size_mb=$(( size_bytes / 1048576 ))
|
# du while this cleared on stat, so the two could disagree about the same file.
|
||||||
size_h=$(du -sh "$logfile" 2>/dev/null | cut -f1)
|
size_mb=$(dir_size_mb "$logfile") || size_mb=0
|
||||||
|
size_h=$(format_mb "$size_mb")
|
||||||
threshold="${LOG_DOCKER_MAX_MB:-100}"
|
threshold="${LOG_DOCKER_MAX_MB:-100}"
|
||||||
|
|
||||||
# Get container name for display
|
# Get container name for display
|
||||||
|
|||||||
@@ -396,6 +396,59 @@ kb_to_gb() {
|
|||||||
awk "BEGIN {printf \"%.${decimals}f\", $kb / 1048576}"
|
awk "BEGIN {printf \"%.${decimals}f\", $kb / 1048576}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ── Disk probes ───────────────────────────────────────────────────────────────────────────────
|
||||||
|
# Everything below reports MEGABYTES, matching vv_df() in Plugin/unraid/include/common.php. The
|
||||||
|
# two languages answer the same question and must answer it in the same unit; a page and a script
|
||||||
|
# disagreeing about a threshold is the harder bug to see.
|
||||||
|
#
|
||||||
|
# These exist because the bash side had no disk helper at all — 46 call sites across 19 files
|
||||||
|
# each reached for df or du directly, in six different flag styles (df -BG, df -P, df -h, du -sh,
|
||||||
|
# du -sm, du -sk). That is not a preference, it is six chances for a unit mismatch.
|
||||||
|
#
|
||||||
|
# du measures ALLOCATED BLOCKS; stat -c%s measures APPARENT SIZE. They differ on sparse files and
|
||||||
|
# by up to a block elsewhere. dir_size_mb() is the du basis. If a caller needs apparent size it
|
||||||
|
# wants stat, and should say so — not quietly pick the other one.
|
||||||
|
|
||||||
|
# Filesystem capacity for the path's mount, in MB.
|
||||||
|
# Usage: disk_df /mnt/user → "size_mb used_mb free_mb" (empty if it cannot be read)
|
||||||
|
disk_df() {
|
||||||
|
local path="${1:-/}"
|
||||||
|
[[ -e "$path" ]] || return 1
|
||||||
|
df -BM --output=size,used,avail "$path" 2>/dev/null | tail -1 | tr -dc '0-9 \n' | awk 'NF==3'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Free megabytes on the filesystem holding a path. Empty and non-zero if undeterminable —
|
||||||
|
# never 0, which a caller would read as "full" and act on.
|
||||||
|
# Usage: free=$(disk_free_mb /mnt/cache) || warn "could not read free space"
|
||||||
|
disk_free_mb() {
|
||||||
|
local out
|
||||||
|
out=$(disk_df "${1:-/}") || return 1
|
||||||
|
[[ -z "$out" ]] && return 1
|
||||||
|
awk '{print $3}' <<< "$out"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Size of a file or directory in MB, du basis. Empty and non-zero if unreadable.
|
||||||
|
# Usage: mb=$(dir_size_mb "$path") || mb=0
|
||||||
|
dir_size_mb() {
|
||||||
|
local path="$1" out
|
||||||
|
[[ -e "$path" ]] || return 1
|
||||||
|
out=$(du -sm "$path" 2>/dev/null | cut -f1)
|
||||||
|
[[ -z "$out" ]] && return 1
|
||||||
|
echo "$out"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Human-readable string from a megabyte count — so a caller that already has MB never runs a
|
||||||
|
# second traversal just to print it. format_bytes() is the byte-input equivalent.
|
||||||
|
# Usage: format_mb 2048 → 2.0GB
|
||||||
|
format_mb() {
|
||||||
|
local mb=${1:-0}
|
||||||
|
if (( mb >= 1024 )); then
|
||||||
|
awk "BEGIN {printf \"%.1fGB\", $mb / 1024}"
|
||||||
|
else
|
||||||
|
echo "${mb}MB"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# ==============================================================================================
|
# ==============================================================================================
|
||||||
# ── ARG PARSER ────────────────────────────────────────────────────────────────────────────────
|
# ── ARG PARSER ────────────────────────────────────────────────────────────────────────────────
|
||||||
# ==============================================================================================
|
# ==============================================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user