update to zfs snapshot to ignore specified pools
This commit is contained in:
@@ -10,6 +10,9 @@
|
|||||||
# Output goes to both console and ZFS_REPORT_LOG for later review.
|
# Output goes to both console and ZFS_REPORT_LOG for later review.
|
||||||
# Notifies if any warning thresholds are exceeded.
|
# Notifies if any warning thresholds are exceeded.
|
||||||
#
|
#
|
||||||
|
# Pools listed in ZFS_REPORT_IGNORE_POOLS are excluded from health reporting.
|
||||||
|
# Useful for pools expected to run at high usage (docker, cache etc.)
|
||||||
|
#
|
||||||
# All configuration in Master.conf under ZFS Memory Snapshot section.
|
# All configuration in Master.conf under ZFS Memory Snapshot section.
|
||||||
# Supports --dry-run (preview only, no log write) and --status.
|
# Supports --dry-run (preview only, no log write) and --status.
|
||||||
# -----------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------
|
||||||
@@ -40,6 +43,16 @@ fi
|
|||||||
|
|
||||||
success "Running as root"
|
success "Running as root"
|
||||||
|
|
||||||
|
# Build ignore list for quick lookup
|
||||||
|
declare -A IGNORE_POOL_MAP
|
||||||
|
for pool in "${ZFS_REPORT_IGNORE_POOLS[@]}"; do
|
||||||
|
[[ -n "$pool" ]] && IGNORE_POOL_MAP["$pool"]=1
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ${#ZFS_REPORT_IGNORE_POOLS[@]} -gt 0 ]]; then
|
||||||
|
info "Ignoring pools: ${ZFS_REPORT_IGNORE_POOLS[*]}"
|
||||||
|
fi
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------
|
||||||
# ━━━ $ICON_SUMMARY Status ━━━
|
# ━━━ $ICON_SUMMARY Status ━━━
|
||||||
# -----------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------
|
||||||
@@ -51,6 +64,7 @@ if [[ "$SHOW_STATUS" == true ]]; then
|
|||||||
echo "$ICON_MEM Free RAM warn: ${ZFS_REPORT_FREE_WARN_GB}GB"
|
echo "$ICON_MEM Free RAM warn: ${ZFS_REPORT_FREE_WARN_GB}GB"
|
||||||
echo "$ICON_MEM Avail RAM warn: ${ZFS_REPORT_AVAIL_WARN_GB}GB"
|
echo "$ICON_MEM Avail RAM warn: ${ZFS_REPORT_AVAIL_WARN_GB}GB"
|
||||||
echo "$ICON_CONTAINERS Docker top: $ZFS_REPORT_DOCKER_TOP"
|
echo "$ICON_CONTAINERS Docker top: $ZFS_REPORT_DOCKER_TOP"
|
||||||
|
echo "$ICON_ZFS Ignore pools: ${ZFS_REPORT_IGNORE_POOLS[*]:-none}"
|
||||||
echo "$ICON_GEAR Dry Run: $DRY_RUN"
|
echo "$ICON_GEAR Dry Run: $DRY_RUN"
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━"
|
echo "━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
exit 0
|
exit 0
|
||||||
@@ -80,24 +94,50 @@ echo "━━━ $ICON_ZFS ZFS Pool Health ━━━"
|
|||||||
if ! command -v zpool >/dev/null 2>&1; then
|
if ! command -v zpool >/dev/null 2>&1; then
|
||||||
warn "ZFS not available on this system — skipping pool checks"
|
warn "ZFS not available on this system — skipping pool checks"
|
||||||
else
|
else
|
||||||
|
# Pool status — filtered to key lines, ignoring specified pools
|
||||||
info "Pool status:"
|
info "Pool status:"
|
||||||
zpool status 2>/dev/null | grep -E "pool:|state:|status:|errors:|scan:" | while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
|
# Extract pool name from "pool: poolname" lines
|
||||||
|
if [[ "$line" =~ ^[[:space:]]*pool:[[:space:]]*(.+) ]]; then
|
||||||
|
CURRENT_POOL="${BASH_REMATCH[1]// /}"
|
||||||
|
fi
|
||||||
|
# Skip lines belonging to ignored pools
|
||||||
|
[[ -n "${IGNORE_POOL_MAP[$CURRENT_POOL]:-}" ]] && continue
|
||||||
echo " $line"
|
echo " $line"
|
||||||
done
|
done < <(zpool status 2>/dev/null | grep -E "pool:|state:|status:|errors:|scan:")
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
# Pool list — filter out ignored pools
|
||||||
info "Pool overview:"
|
info "Pool overview:"
|
||||||
zpool list 2>/dev/null | while IFS= read -r line; do
|
zpool list 2>/dev/null | while IFS= read -r line; do
|
||||||
|
# Always show header line
|
||||||
|
if [[ "$line" == NAME* ]]; then
|
||||||
|
echo " $line"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
# Extract pool name (first field)
|
||||||
|
pool_name=$(echo "$line" | awk '{print $1}')
|
||||||
|
[[ -n "${IGNORE_POOL_MAP[$pool_name]:-}" ]] && continue
|
||||||
echo " $line"
|
echo " $line"
|
||||||
done
|
done
|
||||||
|
|
||||||
UNHEALTHY=$(zpool list -H -o health 2>/dev/null | grep -v ONLINE || true)
|
# Check for unhealthy pools — excluding ignored ones
|
||||||
|
UNHEALTHY=$(zpool list -H -o name,health 2>/dev/null | while IFS=$'\t' read -r name health; do
|
||||||
|
[[ -n "${IGNORE_POOL_MAP[$name]:-}" ]] && continue
|
||||||
|
[[ "$health" != "ONLINE" ]] && echo "$name: $health"
|
||||||
|
done)
|
||||||
|
|
||||||
if [[ -n "$UNHEALTHY" ]]; then
|
if [[ -n "$UNHEALTHY" ]]; then
|
||||||
error "One or more ZFS pools are NOT ONLINE"
|
error "One or more ZFS pools are NOT ONLINE: $UNHEALTHY"
|
||||||
WARNINGS+=("ZFS pool unhealthy")
|
WARNINGS+=("ZFS pool unhealthy: $UNHEALTHY")
|
||||||
else
|
else
|
||||||
success "All ZFS pools are ONLINE"
|
success "All monitored ZFS pools are ONLINE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Show ignored pools
|
||||||
|
if [[ ${#ZFS_REPORT_IGNORE_POOLS[@]} -gt 0 ]]; then
|
||||||
|
info "Ignored pools (not reported): ${ZFS_REPORT_IGNORE_POOLS[*]}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -130,7 +170,7 @@ else
|
|||||||
warn "ARC utilization ${ARC_PCT}% — above ${ZFS_REPORT_ARC_WARN_PCT}% threshold"
|
warn "ARC utilization ${ARC_PCT}% — above ${ZFS_REPORT_ARC_WARN_PCT}% threshold"
|
||||||
WARNINGS+=("ARC high: ${ARC_PCT}%")
|
WARNINGS+=("ARC high: ${ARC_PCT}%")
|
||||||
else
|
else
|
||||||
success "ARC utilization ${ARC_PCT}% — within threshold"
|
success "ARC utilization ${ARC_PCT}% — within threshold (${ZFS_REPORT_ARC_WARN_PCT}%)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
@@ -167,14 +207,14 @@ if [[ "$FREE_GB" -lt "$ZFS_REPORT_FREE_WARN_GB" ]]; then
|
|||||||
warn "Free RAM ${FREE_HUMAN} — below ${ZFS_REPORT_FREE_WARN_GB}GB threshold"
|
warn "Free RAM ${FREE_HUMAN} — below ${ZFS_REPORT_FREE_WARN_GB}GB threshold"
|
||||||
WARNINGS+=("Low free RAM: ${FREE_HUMAN}")
|
WARNINGS+=("Low free RAM: ${FREE_HUMAN}")
|
||||||
else
|
else
|
||||||
success "Free RAM ${FREE_HUMAN} — within threshold"
|
success "Free RAM ${FREE_HUMAN} — within threshold (${ZFS_REPORT_FREE_WARN_GB}GB)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$AVAIL_GB" -lt "$ZFS_REPORT_AVAIL_WARN_GB" ]]; then
|
if [[ "$AVAIL_GB" -lt "$ZFS_REPORT_AVAIL_WARN_GB" ]]; then
|
||||||
warn "Available RAM ${AVAIL_HUMAN} — below ${ZFS_REPORT_AVAIL_WARN_GB}GB threshold"
|
warn "Available RAM ${AVAIL_HUMAN} — below ${ZFS_REPORT_AVAIL_WARN_GB}GB threshold"
|
||||||
WARNINGS+=("Low available RAM: ${AVAIL_HUMAN}")
|
WARNINGS+=("Low available RAM: ${AVAIL_HUMAN}")
|
||||||
else
|
else
|
||||||
success "Available RAM ${AVAIL_HUMAN} — within threshold"
|
success "Available RAM ${AVAIL_HUMAN} — within threshold (${ZFS_REPORT_AVAIL_WARN_GB}GB)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------
|
||||||
@@ -217,6 +257,8 @@ echo ""
|
|||||||
echo "━━━━━ $ICON_SUMMARY ZFS REPORT SUMMARY ━━━━━"
|
echo "━━━━━ $ICON_SUMMARY ZFS REPORT SUMMARY ━━━━━"
|
||||||
echo "$ICON_TIME Duration: $(format_duration $((END - START)))"
|
echo "$ICON_TIME Duration: $(format_duration $((END - START)))"
|
||||||
echo "$ICON_ZFS Log: $ZFS_REPORT_LOG"
|
echo "$ICON_ZFS Log: $ZFS_REPORT_LOG"
|
||||||
|
[[ ${#ZFS_REPORT_IGNORE_POOLS[@]} -gt 0 ]] && \
|
||||||
|
echo "$ICON_ZFS Ignored: ${ZFS_REPORT_IGNORE_POOLS[*]}"
|
||||||
echo ""
|
echo ""
|
||||||
if [[ ${#WARNINGS[@]} -eq 0 ]]; then
|
if [[ ${#WARNINGS[@]} -eq 0 ]]; then
|
||||||
success "Report complete — no warnings"
|
success "Report complete — no warnings"
|
||||||
|
|||||||
Reference in New Issue
Block a user