added tablespace info, top query processes, add date/time, ords config and db parameters

This commit is contained in:
zulqarnainhabib 2024-10-18 11:57:46 +05:00
parent 0c59f9f5c5
commit 32cca430c3
6 changed files with 242 additions and 18 deletions

View File

@ -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
}
]
}

View File

@ -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
}
]
}

View File

@ -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
}
]
}

40
src/scripts/processfinder.sh Executable file
View File

@ -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

25
src/scripts/showdbparameter.sh Executable file
View File

@ -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 <<EOF >> \"$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"

79
src/scripts/tablespaceUsage.sh Executable file
View File

@ -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 <<EOF >> \"$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"