- Remove consecutive breach tracking for statement queue (immediate alerts) - Consolidate script initialization into init_script() function - Remove unused helper functions (send_ok, run_as_hana_user, get_mount_point) - Flatten sld_watchdog.sh structure by removing main() wrapper - Remove state directory and lock directory configuration from hana.conf - Simplify alert messages to include threshold values This continues the simplification effort from previous commits by removing stateful tracking mechanisms and streamlining the monitoring logic for easier maintenance.
94 lines
3.2 KiB
Bash
94 lines
3.2 KiB
Bash
#!/bin/bash
|
|
# =============================================================================
|
|
# SAP HANA Log Segment Monitoring Script
|
|
# Checks log segment states (Truncated, Free)
|
|
# =============================================================================
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
|
SCRIPT_NAME="hana_log_segments"
|
|
|
|
# Load configuration
|
|
source "${SCRIPT_DIR}/hana.conf"
|
|
source "${SCRIPT_DIR}/hana_lib.sh"
|
|
|
|
# Acquire lock
|
|
if ! acquire_lock "$SCRIPT_NAME"; then
|
|
exit 1
|
|
fi
|
|
trap 'release_lock "$SCRIPT_NAME"' EXIT
|
|
|
|
log_message "$SCRIPT_NAME" "Starting log segment check..."
|
|
|
|
# Check if hdbsql is available
|
|
if [ ! -x "$HDBSQL_PATH" ]; then
|
|
log_message "$SCRIPT_NAME" "ERROR: hdbsql not found or not executable at ${HDBSQL_PATH}"
|
|
send_alert "$SCRIPT_NAME" "HANA Monitor Error" "hdbsql not found or not executable at ${HDBSQL_PATH}"
|
|
exit 1
|
|
fi
|
|
|
|
# SQL Query for log segments
|
|
SQL_QUERY="SELECT b.host, b.service_name, a.state, count(*) FROM PUBLIC.M_LOG_SEGMENTS a JOIN PUBLIC.M_SERVICES b ON (a.host = b.host AND a.port = b.port) GROUP BY b.host, b.service_name, a.state;"
|
|
|
|
# Execute SQL query
|
|
sql_output=$(execute_hana_sql "$SQL_QUERY")
|
|
sql_status=$?
|
|
|
|
if [ $sql_status -ne 0 ]; then
|
|
log_message "$SCRIPT_NAME" "ERROR: The hdbsql command failed."
|
|
send_alert "$SCRIPT_NAME" "HANA Monitor Error" "The hdbsql command failed."
|
|
exit 1
|
|
fi
|
|
|
|
# Parse SQL output
|
|
total_segments=0
|
|
truncated_segments=0
|
|
free_segments=0
|
|
|
|
while IFS= read -r line; do
|
|
# Skip empty lines and header
|
|
if [[ -z "$line" || "$line" == *"STATE"* || "$line" == *"host"* ]]; then
|
|
continue
|
|
fi
|
|
|
|
cleaned_line=$(echo "$line" | tr -d '"')
|
|
state=$(echo "$cleaned_line" | awk -F',' '{print $3}' | xargs)
|
|
count=$(echo "$cleaned_line" | awk -F',' '{print $4}' | xargs)
|
|
|
|
# Validate count is a number
|
|
if ! [[ "$count" =~ ^[0-9]+$ ]]; then
|
|
continue
|
|
fi
|
|
|
|
total_segments=$((total_segments + count))
|
|
if [[ "$state" == "Truncated" ]]; then
|
|
truncated_segments=$((truncated_segments + count))
|
|
elif [[ "$state" == "Free" ]]; then
|
|
free_segments=$((free_segments + count))
|
|
fi
|
|
done <<< "$sql_output"
|
|
|
|
log_message "$SCRIPT_NAME" "Total Segments: ${total_segments}"
|
|
log_message "$SCRIPT_NAME" "Truncated Segments: ${truncated_segments}"
|
|
log_message "$SCRIPT_NAME" "Free Segments: ${free_segments}"
|
|
|
|
if [ $total_segments -eq 0 ]; then
|
|
log_message "$SCRIPT_NAME" "WARNING: No log segments found."
|
|
send_alert "$SCRIPT_NAME" "HANA Log Segment Warning" "No log segments found."
|
|
exit 1
|
|
fi
|
|
|
|
# Calculate percentages
|
|
truncated_percentage=$((truncated_segments * 100 / total_segments))
|
|
free_percentage=$((free_segments * 100 / total_segments))
|
|
|
|
# Check thresholds and alert
|
|
if [ $truncated_percentage -gt $TRUNCATED_PERCENTAGE_THRESHOLD ]; then
|
|
send_alert "$SCRIPT_NAME" "HANA Log Segment" "${truncated_percentage}% of log segments are 'Truncated' (threshold: ${TRUNCATED_PERCENTAGE_THRESHOLD}%)."
|
|
fi
|
|
|
|
if [ $free_percentage -lt $FREE_PERCENTAGE_THRESHOLD ]; then
|
|
send_alert "$SCRIPT_NAME" "HANA Log Segment" "Only ${free_percentage}% of log segments are 'Free' (threshold: ${FREE_PERCENTAGE_THRESHOLD}%)."
|
|
fi
|
|
|
|
log_message "$SCRIPT_NAME" "Log segment check complete."
|