Skip to content

Instantly share code, notes, and snippets.

@filviu
Created August 18, 2014 08:49
Show Gist options
  • Save filviu/bbcacaf027af8328d656 to your computer and use it in GitHub Desktop.
Save filviu/bbcacaf027af8328d656 to your computer and use it in GitHub Desktop.
Simple script that collects some logs that can help in debugging server issues
#!/bin/bash
# output folder
OUT="/var/log/debug-logs"
# date format
DATE="date +%Y-%m-%d_%H:%M:%S"
# set the log file to "" and no logs will be recorded for that
APACHE_LOG="apache_status.log"
TOP_LOG="top_status.log"
PS_LOG="ps_status.log"
IOTOP_LOG="iotop_status.log"
MYSQL_LOG="mysql_status.log"
APACHE="elinks -dump http://localhost/server-status"
TOP="top -b -n1 -M | head -40"
PS="ps auxf | head -1; ps auxf --sort pcpu | tail -40"
IOTOP="iotop -b -n1 -ko | grep -v 'K/s -[0-9]\|% -[0-9]' | head -20 "
MYSQLCMD="mysql --table -u query_monitor -pmonitorpassword -e 'show processlist;' | grep -v 'processlist\|Sleep'"
function log_header() {
LOG=$1
echo >> $LOG
echo >> $LOG
date "+%Y-%m-%d %H:%M:%S ================================================================================" >> $LOG
echo >> $LOG
}
function log_footer() {
LOG=$1
echo >> $LOG
echo "====================================================================================================" >> $LOG
}
if [ ! -d $OUT ]; then
echo "Destination folder is missing"
exit 1
fi
if [ ! -z "$APACHE_LOG" ]; then
log_header $OUT/$APACHE_LOG
eval $APACHE >> $OUT/$APACHE_LOG
log_footer $OUT/$APACHE_LOG
fi
if [ ! -z "$TOP_LOG" ]; then
log_header $OUT/$TOP_LOG
eval $TOP >> $OUT/$TOP_LOG
log_footer $OUT/$TOP_LOG
fi
if [ ! -z "$PS_LOG" ]; then
log_header $OUT/$PS_LOG
eval $PS >> $OUT/$PS_LOG
log_footer $OUT/$PS_LOG
fi
if [ ! -z "$IOTOP_LOG" ]; then
log_header $OUT/$IOTOP_LOG
eval $IOTOP >> $OUT/$IOTOP_LOG
log_footer $OUT/$IOTOP_LOG
fi
if [ ! -z "$MYSQL_LOG" ]; then
log_header $OUT/$MYSQL_LOG
eval $MYSQLCMD >> $OUT/$MYSQL_LOG
log_footer $OUT/$MYSQL_LOG
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment