Tuesday, June 14, 2016
For High CPU Utilization Process

ps -eo pcpu,pid,user,args | sort -k1 -r | head -10

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10


For Used Memory

free | awk 'FNR == 3 {print $3/($3+$4)*100}'

free -m|awk 'FNR == 2 {print $3*100/$2}'


For Free memory

free | awk 'FNR == 3 {print $4/($3+$4)*100}'


For High Memmory Utilization Process

ps aux --sort -rss | head


For avarage load on Server

uptime | sed 's/.*load average: //'


For Zomebee process

ps axo stat,ppid,pid,comm | grep -w defunct

ps aux --sort -rss| grep -w defunct

ps aux | grep 'Z'

For strace PID

strace -p PID -o output.file

For Sleeping process list

ps -eo pid,cmd,etime | sort -k 1 -r | head -10


For Only Cpu Utilization

mpstat 1 1 | awk '$3 ~ /CPU/ { for(i=1;i<=NF;i++) { if ($i ~ /%idle/) field=i } } $3 ~ /all/ { printf("%d",100 - $field) }'


Server Resource Monitor Script

#!/bin/bash
#This script will moniter the server load and if pne minute load avg. on the server is more that 30 if will collect the information of Last 3 Login, Current Users Login, CPU consuming processes, Memory consuming processes And mail to the provided email address
#NOTE : This will only mail if one minute load average is more than 30
EMAIL="arvindrsawant@gmail.com"
#EMAIL1="2ndemail id"
LIMIT=30
HOSTNAME=$(hostname)
TIMESTAMP=$(date "+%Y.%m.%d")
TIME=$(date "+%H%M")
REPORT_DIR="/home/load/$TIMESTAMP"
REPORT="$REPORT_DIR/load-"$TIME".log"
SUBJECT="Alert: Heavy Load on Server "$HOSTNAME" "
mkdir -p $REPORT_DIR
echo -e "Current Load on "$HOSTNAME" : \n" >> $REPORT
uptime | sed 's/.*load average: //' >> $REPORT
currnetload=$(uptime | sed 's/.*load average: //' | awk -F, '{print $1}' | cut -f1 -d".")
if [[ $currnetload -gt $LIMIT ]];
        then
echo -e "\n Free Memory On "$HOSTNAME" : \n">> "$REPORT"
free -m >> $REPORT
echo -e "\n Last 3 Login Users On "$HOSTNAME" : \n">> "$REPORT"
last -a |head -3 >> $REPORT
echo -e "\n Current Login Users On "$HOSTNAME" : \n" >> $REPORT
w | tail -n +2 >> "$REPORT"
echo -e "\n CPU consuming processes on "$HOSTNAME" : \n" >> $REPORT
ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10 >> "$REPORT"
echo -e "\n Memory consuming processes on "$HOSTNAME" : \n" >> $REPORT
ps aux --sort -rss | head >> "$REPORT"
echo -e "\n Disk consuming  on "$HOSTNAME" : \n" >> $REPORT
df -h >> "$REPORT"
echo -e "\n Used Memory  on "$HOSTNAME" : \n" >> $REPORT
free | awk 'FNR == 3 {print $3/($3+$4)*100}' >> "$REPORT"
echo -e "\n free Memory  on "$HOSTNAME" : \n" >> $REPORT
free | awk 'FNR == 3 {print $4/($3+$4)*100}' >> "$REPORT"
echo -e "\n Zombie Process  on "$HOSTNAME" : \n" >> $REPORT
ps aux --sort -rss| grep -w defunct >> "$REPORT"
echo -e "\n Sleeping Process list  on "$HOSTNAME" : \n" >> $REPORT
ps -eo pid,cmd,etime | sort -k 1 -r | head -10 >> "$REPORT"
cat $REPORT | mail -s "$SUBJECT" "$EMAIL" "$EMAIL1" "$EMAIL2" "$EMAIL3"
fi

0 comments:

Post a Comment