Files
hana-scripts/hana_queue.sh
Tomi Eckert 7495ebcd78 refactor(monitoring): remove hardcoded tool paths
Remove SAPCONTROL_PATH and HDBSQL_PATH variables from configuration.
Update scripts to rely on the system PATH environment variable when
executing as the <sid>adm user. Remove redundant existence checks for
these commands.
2026-03-12 22:24:02 +01:00

52 lines
1.8 KiB
Bash

#!/bin/bash
# =============================================================================
# SAP HANA Statement Queue Monitoring Script
# Checks for queued SQL statements
# =============================================================================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
SCRIPT_NAME="hana_queue"
# 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 statement queue check..."
# SQL Query for statement queue
STATEMENT_QUEUE_SQL="SELECT COUNT(*) FROM M_SERVICE_THREADS WHERE THREAD_TYPE = 'SqlExecutor' AND THREAD_STATE = 'Queueing';"
# Execute SQL query
queue_count=$(execute_hana_sql_query "$STATEMENT_QUEUE_SQL")
sql_status=$?
if [ $sql_status -ne 0 ]; then
log_message "$SCRIPT_NAME" "ERROR: Failed to execute queue query."
send_alert "$SCRIPT_NAME" "HANA Queue Error" "Failed to execute queue query."
exit 1
fi
# Validate queue count is a number
if ! [[ "$queue_count" =~ ^[0-9]+$ ]]; then
log_message "$SCRIPT_NAME" "WARNING: Could not retrieve HANA statement queue count. Got: '${queue_count}'."
send_alert "$SCRIPT_NAME" "HANA Monitor Warning" "Could not retrieve statement queue count."
exit 1
fi
log_message "$SCRIPT_NAME" "Current statement queue length: ${queue_count}"
# Alert immediately if queue exceeds threshold
if [ "$queue_count" -gt "$STATEMENT_QUEUE_THRESHOLD" ]; then
send_alert "$SCRIPT_NAME" "HANA Statement Queue" "Statement queue count is ${queue_count}, which exceeds threshold of ${STATEMENT_QUEUE_THRESHOLD}."
exit 1
fi
log_message "$SCRIPT_NAME" "Statement queue is normal. Current count: ${queue_count}."
log_message "$SCRIPT_NAME" "Statement queue check complete."