#!/bin/bash
# Define logfile and other variables
LOGFILE="/path/to/mongod.log" # Path to MongoDB log file
OUTPUT_FILE="/path/to/output.log" # Path where the output will be saved
# Record the date
echo "===== Date: $(date) =====" >> $OUTPUT_FILE
# Record just the first line of w output (system uptime, users, and load average)
echo "===== System Uptime, Users, and Load Average (w command) =====" >> $OUTPUT_FILE
w | head -n 1 >> $OUTPUT_FILE
# Record only the %user value from iostat
echo "===== I/O Statistics (%user from iostat command) =====" >> $OUTPUT_FILE
iostat | awk '/^ / {getline; print "User CPU: " $1 "%"}' >> $OUTPUT_FILE
# Capture top processes, filtering for MongoDB (mongod)
echo "===== Top Processes (top command) - Filter for mongod =====" >> $OUTPUT_FILE
top -b -n 1 | grep mongod >> $OUTPUT_FILE
# Filter MongoDB log for specific information (e.g., errors, warnings)
echo "===== MongoDB Logfile Filter =====" >> $OUTPUT_FILE
grep -E "ERROR|WARN" $LOGFILE >> $OUTPUT_FILE
# Optionally add a separator for clarity in the output
echo "===================================================" >> $OUTPUT_FILE
Comments
Post a Comment