From 32cca430c3e05d10ccc39beba029111c1774e4c9 Mon Sep 17 00:00:00 2001 From: zulqarnainhabib Date: Fri, 18 Oct 2024 11:57:46 +0500 Subject: [PATCH] added tablespace info, top query processes, add date/time, ords config and db parameters --- src/config_11g.json | 32 +++++++++++--- src/config_18c.json | 32 +++++++++++--- src/config_23ai.json | 52 +++++++++++++++++++--- src/scripts/processfinder.sh | 40 +++++++++++++++++ src/scripts/showdbparameter.sh | 25 +++++++++++ src/scripts/tablespaceUsage.sh | 79 ++++++++++++++++++++++++++++++++++ 6 files changed, 242 insertions(+), 18 deletions(-) create mode 100755 src/scripts/processfinder.sh create mode 100755 src/scripts/showdbparameter.sh create mode 100755 src/scripts/tablespaceUsage.sh diff --git a/src/config_11g.json b/src/config_11g.json index b4de83a..2f23ec8 100644 --- a/src/config_11g.json +++ b/src/config_11g.json @@ -8,20 +8,40 @@ { "comm": "df -h", "tag": "df" + }, + { + "comm": "/opt/ticket-ai/src/scripts/processfinder.sh;sleep 5;cat /tmp/findsql.tmp", + "tag": "processfinder" + }, + { + "comm": "/opt/ticket-ai/src/scripts/tablespaceUsage.sh;sleep 5;cat /tmp/tablespace_usage.tmp", + "tag": "tablespaceusage" + }, + { + "comm": "/opt/ticket-ai/src/scripts/showdbparameter.sh;sleep 2;cat /tmp/database_parameters.tmp", + "tag": "tablespaceusage" + }, + { + "comm": "cat /opt/ords/config/databases/default/pool.xml", + "tag": "ordsconfig" + }, + { + "comm": "echo Current Date and time on server: ; date", + "tag": "datetime" } ], "logs": [ { "log_file": "/opt/tomcat/logs/catalina.out", - "lines": 300 + "lines": 150 }, { "log_file": "/u01/app/oracle/diag/rdbms/xe/XE/trace/alert_XE.log", - "lines": 100 + "lines": 50 }, { "log_file": "/var/log/messages", - "lines": 50 + "lines": 25 } ] }, @@ -39,15 +59,15 @@ "logs": [ { "log_file": "/opt/tomcat/logs/catalina.out", - "lines": 300 + "lines": 150 }, { "log_file": "/u01/app/oracle/diag/rdbms/xe/XE/trace/alert_XE.log", - "lines": 100 + "lines": 50 }, { "log_file": "/var/log/messages", - "lines": 50 + "lines": 25 } ] } diff --git a/src/config_18c.json b/src/config_18c.json index f3e2b22..4af2d34 100644 --- a/src/config_18c.json +++ b/src/config_18c.json @@ -8,20 +8,40 @@ { "comm": "df -h", "tag": "df" + }, + { + "comm": "/opt/ticket-ai/src/scripts/processfinder.sh;sleep 5;cat /tmp/findsql.tmp", + "tag": "processfinder" + }, + { + "comm": "/opt/ticket-ai/src/scripts/tablespaceUsage.sh;sleep 5;cat /tmp/tablespace_usage.tmp", + "tag": "tablespaceusage" + }, + { + "comm": "/opt/ticket-ai/src/scripts/showdbparameter.sh;sleep 2;cat /tmp/database_parameters.tmp", + "tag": "tablespaceusage" + }, + { + "comm": "cat /opt/ords/config/databases/default/pool.xml", + "tag": "ordsconfig" + }, + { + "comm": "echo Current Date and time on server: ; date", + "tag": "datetime" } ], "logs": [ { "log_file": "/opt/tomcat/logs/catalina.out", - "lines": 300 + "lines": 150 }, { "log_file": "/opt/oracle/diag/rdbms/xe/XE/trace/alert_XE.log", - "lines": 100 + "lines": 50 }, { "log_file": "/var/log/messages", - "lines": 50 + "lines": 25 } ] }, @@ -39,15 +59,15 @@ "logs": [ { "log_file": "/opt/tomcat/logs/catalina.out", - "lines": 300 + "lines": 150 }, { "log_file": "/opt/oracle/diag/rdbms/xe/XE/trace/alert_XE.log", - "lines": 100 + "lines": 50 }, { "log_file": "/var/log/messages", - "lines": 50 + "lines": 25 } ] } diff --git a/src/config_23ai.json b/src/config_23ai.json index 0042fb0..5fd875e 100644 --- a/src/config_23ai.json +++ b/src/config_23ai.json @@ -8,20 +8,40 @@ { "comm": "df -h", "tag": "df" + }, + { + "comm": "/opt/ticket-ai/src/scripts/processfinder.sh;sleep 5;cat /tmp/findsql.tmp", + "tag": "processfinder" + }, + { + "comm": "/opt/ticket-ai/src/scripts/tablespaceUsage.sh;sleep 5;cat /tmp/tablespace_usage.tmp", + "tag": "tablespaceusage" + }, + { + "comm": "/opt/ticket-ai/src/scripts/showdbparameter.sh;sleep 2;cat /tmp/database_parameters.tmp", + "tag": "tablespaceusage" + }, + { + "comm": "cat /opt/ords/config/databases/default/pool.xml", + "tag": "ordsconfig" + }, + { + "comm": "echo Current Date and time on server: ; date", + "tag": "datetime" } ], "logs": [ { "log_file": "/opt/tomcat/logs/catalina.out", - "lines": 300 + "lines": 150 }, { "log_file": "/opt/oracle/diag/rdbms/free/FREE/trace/alert_FREE.log", - "lines": 100 + "lines": 50 }, { "log_file": "/var/log/messages", - "lines": 50 + "lines": 25 } ] }, @@ -34,20 +54,40 @@ { "comm": "df -h", "tag": "df" + }, + { + "comm": "/opt/ticket-ai/src/scripts/processfinder.sh;sleep 5;cat /tmp/findsql.tmp", + "tag": "processfinder" + }, + { + "comm": "/opt/ticket-ai/src/scripts/tablespaceUsage.sh;sleep 5;cat /tmp/tablespace_usage.tmp", + "tag": "tablespaceusage" + }, + { + "comm": "/opt/ticket-ai/src/scripts/showdbparameter.sh;sleep 2;cat /tmp/database_parameters.tmp", + "tag": "tablespaceusage" + }, + { + "comm": "cat /opt/ords/config/databases/default/pool.xml", + "tag": "ordsconfig" + }, + { + "comm": "echo Current Date and time on server: ; date", + "tag": "datetime" } ], "logs": [ { "log_file": "/opt/tomcat/logs/catalina.out", - "lines": 300 + "lines": 150 }, { "log_file": "/opt/oracle/diag/rdbms/free/FREE/trace/alert_FREE.log", - "lines": 100 + "lines": 50 }, { "log_file": "/var/log/messages", - "lines": 50 + "lines": 25 } ] } diff --git a/src/scripts/processfinder.sh b/src/scripts/processfinder.sh new file mode 100755 index 0000000..98604df --- /dev/null +++ b/src/scripts/processfinder.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Define the CPU usage threshold +CPU_THRESHOLD=90 + +# File path for output +OUTPUT_FILE="/tmp/findsql.tmp" + +# Capture the PIDs of Oracle processes consuming over the specified CPU threshold +pid=($(top -b -n 1 | awk -v threshold="$CPU_THRESHOLD" '$12 ~ /^oracle/ && $9 > threshold {print $1}')) +echo $pid + +# Check if there are any PIDs in the array +if [ ${#pid[@]} -gt 0 ]; then + echo "Following may be the SQL statements consuming top CPU" > "$OUTPUT_FILE" + chown oracle "$OUTPUT_FILE" + + # Construct a comma-separated list of PIDs + pid_list=$(IFS=,; echo "${pid[*]}") + + # Execute the SQL command as the oracle user + su - oracle -s /bin/bash -c " + sqlplus -s / as sysdba <<'EOF' >> \"$OUTPUT_FILE\" + whenever sqlerror exit sql.sqlcode; + set echo off + set heading on + + select DISTINCT + s.CLIENT_IDENTIFIER, s.schemaname, s.module, s.action, q.sql_id, q.sql_text + from v\$session s, v\$process p, v\$sql q + where s.paddr = p.addr + and p.spid IN ($pid_list) + and q.sql_text is not null + and s.sql_id = q.sql_id(+); + exit; +EOF + " +else + echo "No Oracle processes consuming significant CPU" > "$OUTPUT_FILE" +fi diff --git a/src/scripts/showdbparameter.sh b/src/scripts/showdbparameter.sh new file mode 100755 index 0000000..3b3feb5 --- /dev/null +++ b/src/scripts/showdbparameter.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# File path for output +OUTPUT_FILE="/tmp/database_parameters.tmp" +> "$OUTPUT_FILE" # Clear the output file before starting + +chown oracle $OUTPUT_FILE + +# Execute the query to retrieve all database parameters +su - oracle -s /bin/bash -c " + sqlplus -s / as sysdba <> \"$OUTPUT_FILE\" + whenever sqlerror exit sql.sqlcode; + set echo on + set heading on + set linesize 150 + set pagesize 100 + + show parameters; + + exit; +EOF +" + +# Notify user about the location of the output file +echo "Database parameters have been saved to $OUTPUT_FILE" diff --git a/src/scripts/tablespaceUsage.sh b/src/scripts/tablespaceUsage.sh new file mode 100755 index 0000000..ccb7e78 --- /dev/null +++ b/src/scripts/tablespaceUsage.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +# File paths for output +OUTPUT_FILE="/tmp/tablespace_usage.tmp" +PDB_LIST_FILE="/tmp/pdb_list.tmp" +> "$OUTPUT_FILE" # Clear the output file before starting + +# Function to execute the tablespace usage query in a specific container +run_query() { + local container_name="$1" + su - oracle -s /bin/bash -c " + sqlplus -s / as sysdba <> \"$OUTPUT_FILE\" + whenever sqlerror exit sql.sqlcode; + set echo off + set heading on + set linesize 150 + + -- Switch to the specified container + ALTER SESSION SET CONTAINER = $container_name; + + -- Print the container name for clarity + PROMPT Tablespace usage for container: $container_name; + + SELECT a.tablespace_name, + c.bytes/1024/1024 allocated, + round(c.bytes/1024/1024 - nvl(b.bytes,0)/1024/1024, 2) used, + round(nvl(b.bytes,0)/1024/1024, 2) free, + ROUND(((c.bytes - nvl(b.bytes,0)) / c.bytes) * 100, 2) PCT_USED + FROM dba_tablespaces a, + (SELECT tablespace_name, SUM(bytes) bytes + FROM dba_free_space + GROUP BY tablespace_name) b, + (SELECT COUNT(1) datafiles, SUM(bytes) bytes, tablespace_name + FROM dba_data_files + GROUP BY tablespace_name) c + WHERE b.tablespace_name(+) = a.tablespace_name + AND c.tablespace_name(+) = a.tablespace_name + AND a.tablespace_name NOT LIKE 'UNDO%' + AND a.tablespace_name NOT LIKE 'TEMP%' + ORDER BY tablespace_name; + + exit; +EOF + " +} + +# Run the query for the CDB (root container) +echo "Gathering tablespace usage for CDB (root container)..." >> "$OUTPUT_FILE" +run_query 'CDB\$ROOT' + +# Get a list of all PDBs, excluding PDB$SEED, and write to a temporary file +su - oracle -s /bin/bash -c " + sqlplus -s / as sysdba <<'EOF' + set heading off + set feedback off + set pagesize 0 + spool $PDB_LIST_FILE + SELECT NAME FROM v\$pdbs WHERE NAME NOT IN ('PDB\$SEED'); + spool off + exit; +EOF +" + +# Verify that the PDB_LIST_FILE was created and contains data +if [[ -f "$PDB_LIST_FILE" && -s "$PDB_LIST_FILE" ]]; then + # Read each valid PDB name from the temporary file + while IFS= read -r PDB; do + PDB=$(echo "$PDB" | xargs) # Trim any leading/trailing whitespace + if [[ -n "$PDB" ]]; then + echo "Gathering tablespace usage for PDB: $PDB..." >> "$OUTPUT_FILE" + run_query "$PDB" + fi + done < "$PDB_LIST_FILE" +else + echo "No PDBs found or could not access v\$pdbs view" >> "$OUTPUT_FILE" +fi + +# Clean up the temporary file +rm -f "$PDB_LIST_FILE"