Overview
This guide demonstrates how to implement three critical monitoring scripts for Oracle Internet Directory (OID) and set up their automated execution schedule. Each script serves a distinct monitoring purpose and runs at different intervals.
Monitoring Implementation
1. Basic Service Monitoring Script (monitor_oid.sh)
cat << 'EOF' > $DOMAIN_HOME/monitor_oid.sh
#!/bin/bash
ORACLE_HOME=/u01/oracle/Middleware/OID_Home
DOMAIN_HOME=/u01/oracle/config/domains/oid_domain
LOG_FILE=$DOMAIN_HOME/servers/OID/logs/oid1/oid_monitor.log
echo "=== OID Monitoring Report $(date) ===" >> $LOG_FILE
echo "1. Process Status:" >> $LOG_FILE
$ORACLE_HOME/bin/oidctl status >> $LOG_FILE 2>&1
echo "2. Connection Test:" >> $LOG_FILE
$ORACLE_HOME/bin/ldapbind -h localhost -p 3060 -D cn=orcladmin -q >> $LOG_FILE 2>&1
echo "3. Resource Usage:" >> $LOG_FILE
ps -o pid,ppid,%cpu,%mem,cmd -p $(pgrep -f oidldapd) >> $LOG_FILE 2>&1
echo "=== End Report ===" >> $LOG_FILE
EOF
chmod 750 $DOMAIN_HOME/monitor_oid.sh
Shell
복사
What This Script Monitors:
1.
Process Status
•
Checks if OID processes are running
•
Verifies process health
•
Shows parent-child process relationships
2.
Connection Tests
•
Tests basic LDAP connectivity
•
Verifies authentication
•
Checks response times
3.
Resource Usage
•
Basic CPU and memory metrics
•
Process-specific resource consumption
•
Quick health indicators
How to Interpret Results:
•
Normal State:
◦
All processes show "ONLINE"
◦
LDAP bind successful
◦
Resource usage within normal ranges
•
Problem Indicators:
◦
"OFFLINE" status
◦
Connection failures
◦
Excessive resource usage
2. Comprehensive Resource Monitoring Script (monitor_resources.sh)
Create $DOMAIN_HOME/monitor_resource.sh with the following content for frequent monitoring:
#!/bin/bash
DOMAIN_HOME=/u01/oracle/config/domains/oid_domain
LOG_DIR=$DOMAIN_HOME/servers/OID/logs/oid1/resources
mkdir -p $LOG_DIR
TIMESTAMP=$(date '+%Y-%m-%d_%H:%M:%S')
# Function to calculate percentage
calc_percentage() {
echo "scale=2; $1 * 100 / $2" | bc
}
# Resource monitoring header
echo "=== OID Resource Usage Report - $TIMESTAMP ===" > $LOG_DIR/resource_${TIMESTAMP}.log
# CPU Monitoring
echo -e "\n=== CPU Usage ===" >> $LOG_DIR/resource_${TIMESTAMP}.log
CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}')
echo "Current CPU Usage: ${CPU_USAGE}%" >> $LOG_DIR/resource_${TIMESTAMP}.log
# CPU Load Average
LOAD_AVG=$(uptime | awk -F'load average:' '{print $2}')
echo "Load Average: ${LOAD_AVG}" >> $LOG_DIR/resource_${TIMESTAMP}.log
# Memory Monitoring
echo -e "\n=== Memory Usage ===" >> $LOG_DIR/resource_${TIMESTAMP}.log
free -m | grep "Mem:" | while read line; do
TOTAL_MEM=$(echo $line | awk '{print $2}')
USED_MEM=$(echo $line | awk '{print $3}')
FREE_MEM=$(echo $line | awk '{print $4}')
USAGE_PCT=$(calc_percentage $USED_MEM $TOTAL_MEM)
echo "Total Memory: ${TOTAL_MEM}MB" >> $LOG_DIR/resource_${TIMESTAMP}.log
echo "Used Memory: ${USED_MEM}MB (${USAGE_PCT}%)" >> $LOG_DIR/resource_${TIMESTAMP}.log
echo "Free Memory: ${FREE_MEM}MB" >> $LOG_DIR/resource_${TIMESTAMP}.log
done
# Disk I/O Monitoring
echo -e "\n=== Disk I/O ===" >> $LOG_DIR/resource_${TIMESTAMP}.log
iostat -x 1 2 | grep -A 1 "Device" | tail -n 1 >> $LOG_DIR/resource_${TIMESTAMP}.log
# OID Process Memory Usage
echo -e "\n=== OID Process Memory Usage ===" >> $LOG_DIR/resource_${TIMESTAMP}.log
ps aux | grep [o]idldapd | awk '{print "PID: " $2 ", Memory: " $6 "KB, CPU: " $3 "%"}' >> $LOG_DIR/resource_${TIMESTAMP}.log
# OID Specific Monitoring
echo -e "\n=== OID Service Status ===" >> $LOG_DIR/resource_${TIMESTAMP}.log
# Check OID processes
$ORACLE_HOME/bin/oidctl status >> $LOG_DIR/resource_${TIMESTAMP}.log 2>&1
# LDAP Connection Monitoring
echo -e "\n=== LDAP Connection Status ===" >> $LOG_DIR/resource_${TIMESTAMP}.log
# Non-SSL connections (3060)
NONSSL_CONN=$(netstat -an | grep ":3060" | grep ESTABLISHED | wc -l)
# SSL connections (3131)
SSL_CONN=$(netstat -an | grep ":3131" | grep ESTABLISHED | wc -l)
echo "Non-SSL Connections: $NONSSL_CONN" >> $LOG_DIR/resource_${TIMESTAMP}.log
echo "SSL Connections: $SSL_CONN" >> $LOG_DIR/resource_${TIMESTAMP}.log
echo "Total LDAP Connections: $((NONSSL_CONN + SSL_CONN))" >> $LOG_DIR/resource_${TIMESTAMP}.log
# OID Database Status
echo -e "\n=== OID Database Status ===" >> $LOG_DIR/resource_${TIMESTAMP}.log
sqlplus -S "/ as sysdba" << EOF >> $LOG_DIR/resource_${TIMESTAMP}.log
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
SELECT 'ODS Tablespace Usage: ' ||
ROUND(used_percent,2) || '%'
FROM dba_tablespace_usage_metrics
WHERE tablespace_name LIKE '%ODS%';
SELECT 'Active ODS Sessions: ' || COUNT(*)
FROM v\$session
WHERE username LIKE '%ODS%'
AND status = 'ACTIVE';
EXIT;
EOF
# Alert Thresholds
CPU_THRESHOLD=80
MEM_THRESHOLD=85
DISK_THRESHOLD=90
LDAP_CONN_THRESHOLD=1000
OID_MEM_THRESHOLD=4194304 # 4GB in KB
# Check thresholds and generate alerts
if [ $(echo "$CPU_USAGE > $CPU_THRESHOLD" | bc) -eq 1 ]; then
echo "ALERT: CPU usage above ${CPU_THRESHOLD}%" >> $LOG_DIR/alerts.log
fi
free -m | grep "Mem:" | awk '{print ($3/$2)*100}' | while read MEM_USAGE; do
if [ $(echo "$MEM_USAGE > $MEM_THRESHOLD" | bc) -eq 1 ]; then
echo "ALERT: Memory usage above ${MEM_THRESHOLD}%" >> $LOG_DIR/alerts.log
fi
done
df -h | grep -vE '^tmpfs|^devtmpfs' | awk '{print $5}' | sed 's/%//g' | while read DISK_USAGE; do
if [ "$DISK_USAGE" -gt "$DISK_THRESHOLD" ]; then
echo "ALERT: Disk usage above ${DISK_THRESHOLD}%" >> $LOG_DIR/alerts.log
fi
done
# OID specific alerts
TOTAL_CONN=$((NONSSL_CONN + SSL_CONN))
if [ $TOTAL_CONN -gt $LDAP_CONN_THRESHOLD ]; then
echo "ALERT: Total LDAP connections ($TOTAL_CONN) above threshold ($LDAP_CONN_THRESHOLD)" >> $LOG_DIR/alerts.log
fi
ps aux | grep [o]idldapd | awk '{if ($6 > '"$OID_MEM_THRESHOLD"') print "ALERT: OID process memory usage above 4GB"}' >> $LOG_DIR/alerts.log
# Recommended Resource Allocation
echo -e "\n=== Recommended Resource Allocation ===" >> $LOG_DIR/resource_${TIMESTAMP}.log
echo "Minimum Memory Requirements:" >> $LOG_DIR/resource_${TIMESTAMP}.log
echo "- OID Process: 4GB" >> $LOG_DIR/resource_${TIMESTAMP}.log
echo "- WebLogic Server: 2GB" >> $LOG_DIR/resource_${TIMESTAMP}.log
echo "- Operating System: 2GB" >> $LOG_DIR/resource_${TIMESTAMP}.log
echo "Total Recommended Memory: 8GB minimum" >> $LOG_DIR/resource_${TIMESTAMP}.log
# Keep only last 24 hours of detailed logs
find $LOG_DIR -name "resource_*.log" -mmin +1440 -delete
Bash
복사
Key Monitoring Areas:
1.
CPU Monitoring
# CPU usage check
CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}')
Shell
복사
•
Why important: CPU bottlenecks affect LDAP operation speed
•
Warning threshold: 80% sustained usage
•
Action needed: Consider adding cores or optimization
2.
Memory Monitoring
free -m | grep "Mem:" | while read line; do
TOTAL_MEM=$(echo $line | awk '{print $2}')
USED_MEM=$(echo $line | awk '{print $3}')
# ... [rest of memory monitoring code]
Shell
복사
•
Critical for: LDAP cache and operation performance
•
Warning signs:
◦
High swap usage
◦
Low free memory
◦
OID process memory growth
3.
LDAP Connection Monitoring
NONSSL_CONN=$(netstat -an | grep ":3060" | grep ESTABLISHED | wc -l)
SSL_CONN=$(netstat -an | grep ":3131" | grep ESTABLISHED | wc -l)
Shell
복사
•
Purpose: Track active client connections
•
Key metrics:
◦
Total connections
◦
SSL vs non-SSL ratio
◦
Connection duration
4.
Database Status
SELECT 'ODS Tablespace Usage: ' || ROUND(used_percent,2) || '%'
FROM dba_tablespace_usage_metrics
WHERE tablespace_name LIKE '%ODS%';
SQL
복사
•
Monitors: Database resource utilization
•
Critical aspects:
◦
Tablespace usage
◦
Active sessions
◦
Performance metrics
3. Daily Summary Generation Script (generate_daily_summary.sh)
Create $DOMAIN_HOME/generate_daily_summary.sh with the following content for daily summary:
#!/bin/bash
DOMAIN_HOME=/u01/oracle/config/domains/oid_domain
LOG_DIR=$DOMAIN_HOME/servers/OID/logs/oid1/resources
SUMMARY_DIR=$LOG_DIR/daily_summary
mkdir -p $SUMMARY_DIR
DATE=$(date '+%Y-%m-%d')
YESTERDAY=$(date -d "yesterday" '+%Y-%m-%d')
# Create summary file with header
echo "=== OID Daily Resource Summary - $YESTERDAY ===" > $SUMMARY_DIR/summary_${YESTERDAY}.log
echo "Report Generation Time: $(date '+%Y-%m-%d %H:%M:%S')" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
echo "Period: ${YESTERDAY} 00:00:00 - 23:59:59" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
# System Resource Summary
echo -e "\n=== System Resource Summary ===" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
# CPU Summary
echo -e "\n--- CPU Usage ---" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
grep "CPU Usage" $LOG_DIR/resource_${YESTERDAY}*.log | \
awk -F': ' '{sum+=$2; count++} END {
printf "Average CPU Usage: %.2f%%\n", sum/count
}' >> $SUMMARY_DIR/summary_${YESTERDAY}.log
# Load Average Summary
echo -e "\n--- Load Average ---" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
grep "Load Average:" $LOG_DIR/resource_${YESTERDAY}*.log | \
awk -F': ' '{sum1+=$2; sum5+=$3; sum15+=$4; count++} END {
printf "Average Load: %.2f (1min), %.2f (5min), %.2f (15min)\n",
sum1/count, sum5/count, sum15/count
}' >> $SUMMARY_DIR/summary_${YESTERDAY}.log
# Memory Summary
echo -e "\n--- Memory Usage ---" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
grep "Used Memory:" $LOG_DIR/resource_${YESTERDAY}*.log | \
awk -F'[(%]' '{sum+=$2; count++} END {
printf "Average Memory Usage: %.2f%%\n", sum/count
}' >> $SUMMARY_DIR/summary_${YESTERDAY}.log
# OID Specific Summary
echo -e "\n=== OID Service Summary ===" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
# OID Process Memory Summary
echo -e "\n--- OID Process Memory Usage ---" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
grep "Memory:" $LOG_DIR/resource_${YESTERDAY}*.log | \
awk '{sum+=$3; count++} END {
printf "Average OID Process Memory: %.2f GB\n", (sum/count)/1024/1024
}' >> $SUMMARY_DIR/summary_${YESTERDAY}.log
# LDAP Connection Summary
echo -e "\n--- LDAP Connection Summary ---" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
echo "Non-SSL Connections:" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
grep "Non-SSL Connections:" $LOG_DIR/resource_${YESTERDAY}*.log | \
awk -F': ' '{sum+=$2; count++} END {
printf " Average: %.2f\n", sum/count
printf " Maximum: %d\n", max
}' >> $SUMMARY_DIR/summary_${YESTERDAY}.log
echo "SSL Connections:" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
grep "SSL Connections:" $LOG_DIR/resource_${YESTERDAY}*.log | \
awk -F': ' '{sum+=$2; count++} END {
printf " Average: %.2f\n", sum/count
printf " Maximum: %d\n", max
}' >> $SUMMARY_DIR/summary_${YESTERDAY}.log
# Database Status Summary
echo -e "\n--- Database Usage Summary ---" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
grep "ODS Tablespace Usage:" $LOG_DIR/resource_${YESTERDAY}*.log | \
awk -F': ' '{sum+=$2; count++} END {
printf "Average ODS Tablespace Usage: %.2f%%\n", sum/count
}' >> $SUMMARY_DIR/summary_${YESTERDAY}.log
grep "Active ODS Sessions:" $LOG_DIR/resource_${YESTERDAY}*.log | \
awk -F': ' '{sum+=$2; count++} END {
printf "Average Active ODS Sessions: %.2f\n", sum/count
}' >> $SUMMARY_DIR/summary_${YESTERDAY}.log
# Peak Usage Summary
echo -e "\n=== Peak Resource Usage ===" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
echo "System Resources:" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
echo "- Peak CPU:" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
grep "CPU Usage" $LOG_DIR/resource_${YESTERDAY}*.log | sort -nr -k3 | head -1 >> $SUMMARY_DIR/summary_${YESTERDAY}.log
echo "- Peak Memory:" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
grep "Used Memory:" $LOG_DIR/resource_${YESTERDAY}*.log | sort -nr -k3 | head -1 >> $SUMMARY_DIR/summary_${YESTERDAY}.log
echo "OID Resources:" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
echo "- Peak OID Process Memory:" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
grep "Memory:" $LOG_DIR/resource_${YESTERDAY}*.log | sort -nr -k3 | head -1 >> $SUMMARY_DIR/summary_${YESTERDAY}.log
echo "- Peak LDAP Connections:" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
grep "Total LDAP Connections:" $LOG_DIR/resource_${YESTERDAY}*.log | sort -nr -k4 | head -1 >> $SUMMARY_DIR/summary_${YESTERDAY}.log
# Alert Analysis
echo -e "\n=== Alert Analysis ===" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
echo "Alert Summary by Type:" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
grep "ALERT:" $LOG_DIR/alerts.log | grep ${YESTERDAY} | \
awk -F': ' '{print $2}' | sort | uniq -c | \
awk '{printf "- %s occurrences: %s\n", $1, substr($0, length($1)+2)}' \
>> $SUMMARY_DIR/summary_${YESTERDAY}.log
# Recommendations
echo -e "\n=== Recommendations ===" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
ALERT_COUNT=$(grep "ALERT:" $LOG_DIR/alerts.log | grep ${YESTERDAY} | wc -l)
if [ $ALERT_COUNT -gt 0 ]; then
echo "Based on today's alerts:" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
if grep -q "CPU usage above" $LOG_DIR/alerts.log; then
echo "- Consider reviewing CPU intensive processes" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
fi
if grep -q "Memory usage above" $LOG_DIR/alerts.log; then
echo "- Review memory allocation and usage patterns" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
fi
if grep -q "LDAP connections" $LOG_DIR/alerts.log; then
echo "- Review LDAP connection pooling configuration" >> $SUMMARY_DIR/summary_${YESTERDAY}.log
fi
fi
# Keep 30 days of summary logs
find $SUMMARY_DIR -name "summary_*.log" -mtime +30 -delete
# Compress older logs (older than 7 days)
find $SUMMARY_DIR -name "summary_*.log" -mtime +7 -exec gzip {} \;
Bash
복사
Report Sections and Their Importance:
1.
System Resource Summary
•
What it shows: Average and peak resource usage
•
Why important: Capacity planning and trend analysis
•
Key indicators:
◦
CPU utilization patterns
◦
Memory usage trends
◦
I/O performance
2.
OID-Specific Metrics
•
LDAP operation statistics
•
Connection patterns
•
Resource usage by OID processes
3.
Alert Analysis
•
Types of alerts triggered
•
Frequency patterns
•
Correlation with system events
Automated Scheduling
To set up the monitoring schedule, add the following entries to the crontab:
# Edit crontab for the oracle user
crontab -e
# Add monitoring schedule
* * * * * $DOMAIN_HOME/scripts/monitor_oid.sh # Every minute
*/5 * * * * $DOMAIN_HOME/scripts/monitor_resources.sh # Every 5 minutes
0 0 * * * $DOMAIN_HOME/scripts/generate_daily_summary.sh # Daily at midnight
Shell
복사
Script Location and Permissions
# Create scripts directory
mkdir -p $DOMAIN_HOME/scripts/
# Move scripts to directory
mv $DOMAIN_HOME/monitor_oid.sh $DOMAIN_HOME/scripts/
mv $DOMAIN_HOME/monitor_resources.sh $DOMAIN_HOME/scripts/
mv $DOMAIN_HOME/generate_daily_summary.sh $DOMAIN_HOME/scripts/
# Set proper permissions
chmod 750 $DOMAIN_HOME/scripts/monitor_*.sh
chmod 750 $DOMAIN_HOME/scripts/generate_daily_summary.sh
chown oracle:oinstall $DOMAIN_HOME/scripts/*.sh
Bash
복사
Verification Steps
# Check script permissions
ls -l $DOMAIN_HOME/scripts/
# Verify cron configuration
crontab -l
# Monitor log files
tail -f $DOMAIN_HOME/servers/OID/logs/oid1/oid_monitor.log
Bash
복사
Best Practices
1.
Log Management
•
Implement log rotation
•
Regular cleanup of old logs
•
Monitor disk space usage
2.
Security
•
Maintain proper file permissions
•
Secure script access
•
Protect monitoring data
3.
Monitoring
•
Regular review of monitoring effectiveness
•
Adjust thresholds as needed
•
Validate alert mechanisms
Next Steps
•
Review and customize monitoring thresholds
•
Set up email notifications for alerts
•
Implement log rotation policies
•
Schedule regular monitoring review sessions
Note: Adjust monitoring intervals and thresholds based on your system requirements and performance characteristics.