Last active
August 29, 2015 14:03
-
-
Save bageljp/02cf321652729a359441 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#------------------------------------------------------------------------------------------------------------------------ | |
# cron setting: | |
# */3 * * * * /root/resource.bash > /dev/null 2>&1 | |
#------------------------------------------------------------------------------------------------------------------------ | |
#------------------------------------------------------------------------------------------------------------------------ | |
# ENVIRONMENT | |
#------------------------------------------------------------------------------------------------------------------------ | |
DIR_LOG="/tmp/`basename $0 .bash`" | |
LOGFILE="${DIR_LOG}/`basename $0 .bash`.log" | |
STAT_INTERVAL=1 | |
STAT_CONT=5 | |
#------------------------------------------------------------------------------------------------------------------------ | |
# FUNCTION | |
#------------------------------------------------------------------------------------------------------------------------ | |
func_top() { | |
DIR_LOG_FUNC="${DIR_LOG}/top/" | |
LOGFILE_FUNC="${DIR_LOG_FUNC}/`date +%Y%m%d`.log" | |
[ ! -d ${DIR_LOG_FUNC} ] && mkdir -p ${DIR_LOG_FUNC} | |
echo "### TOP : `date +'%Y/%m/%d %H:%M:%S'` ###" >> ${LOGFILE_FUNC}_top 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_top 2>&1 | |
top -b -n 1 >> ${LOGFILE_FUNC}_top 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_top 2>&1 | |
return 0 | |
} | |
func_iotop() { | |
DIR_LOG_FUNC="${DIR_LOG}/iotop/" | |
LOGFILE_FUNC="${DIR_LOG_FUNC}/`date +%Y%m%d`.log" | |
[ ! -d ${DIR_LOG_FUNC} ] && mkdir -p ${DIR_LOG_FUNC} | |
echo "### IOTOP : `date +'%Y/%m/%d %H:%M:%S'` ###" >> ${LOGFILE_FUNC}_iotop 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_iotop 2>&1 | |
iotop -bt -n 1 >> ${LOGFILE_FUNC}_iotop 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_iotop 2>&1 | |
return 0 | |
} | |
func_ps() { | |
DIR_LOG_FUNC="${DIR_LOG}/ps/" | |
LOGFILE_FUNC="${DIR_LOG_FUNC}/`date +%Y%m%d`.log" | |
[ ! -d ${DIR_LOG_FUNC} ] && mkdir -p ${DIR_LOG_FUNC} | |
echo "### PS : `date +'%Y/%m/%d %H:%M:%S'` ###" >> ${LOGFILE_FUNC}_ps 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_ps 2>&1 | |
ps auxww >> ${LOGFILE_FUNC}_ps 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_ps 2>&1 | |
return 0 | |
} | |
func_ps_child() { | |
DIR_LOG_FUNC="${DIR_LOG}/ps_child/" | |
LOGFILE_FUNC="${DIR_LOG_FUNC}/`date +%Y%m%d`.log" | |
[ ! -d ${DIR_LOG_FUNC} ] && mkdir -p ${DIR_LOG_FUNC} | |
echo "### PS CHILD : `date +'%Y/%m/%d %H:%M:%S'` ###" >> ${LOGFILE_FUNC}_ps_child 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_ps_child 2>&1 | |
ps -aef >> ${LOGFILE_FUNC}_ps_child 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_ps_child 2>&1 | |
return 0 | |
} | |
func_vmstat() { | |
DIR_LOG_FUNC="${DIR_LOG}/vmstat/" | |
LOGFILE_FUNC="${DIR_LOG_FUNC}/`date +%Y%m%d`.log" | |
[ ! -d ${DIR_LOG_FUNC} ] && mkdir -p ${DIR_LOG_FUNC} | |
echo "### VMSTAT : `date +'%Y/%m/%d %H:%M:%S'` ###" >> ${LOGFILE_FUNC}_vmstat 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_vmstat 2>&1 | |
vmstat ${STAT_INTERVAL} ${STAT_CONT} >> ${LOGFILE_FUNC}_vmstat 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_vmstat 2>&1 | |
return 0 | |
} | |
func_mpstat() { | |
DIR_LOG_FUNC="${DIR_LOG}/mpstat/" | |
LOGFILE_FUNC="${DIR_LOG_FUNC}/`date +%Y%m%d`.log" | |
[ ! -d ${DIR_LOG_FUNC} ] && mkdir -p ${DIR_LOG_FUNC} | |
echo "### MPSTAT : `date +'%Y/%m/%d %H:%M:%S'` ###" >> ${LOGFILE_FUNC}_mpstat 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_mpstat 2>&1 | |
mpstat -P ALL ${STAT_INTERVAL} ${STAT_CONT} >> ${LOGFILE_FUNC}_mpstat 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_mpstat 2>&1 | |
return 0 | |
} | |
func_iostat() { | |
DIR_LOG_FUNC="${DIR_LOG}/iostat/" | |
LOGFILE_FUNC="${DIR_LOG_FUNC}/`date +%Y%m%d`.log" | |
[ ! -d ${DIR_LOG_FUNC} ] && mkdir -p ${DIR_LOG_FUNC} | |
echo "### IOSTAT : `date +'%Y/%m/%d %H:%M:%S'` ###" >> ${LOGFILE_FUNC}_iostat 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_iostat 2>&1 | |
iostat -kx ${STAT_INTERVAL} ${STAT_CONT} >> ${LOGFILE_FUNC}_iostat 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_iostat 2>&1 | |
return 0 | |
} | |
func_pidstat() { | |
DIR_LOG_FUNC="${DIR_LOG}/pidstat/" | |
LOGFILE_FUNC="${DIR_LOG_FUNC}/`date +%Y%m%d`.log" | |
[ ! -d ${DIR_LOG_FUNC} ] && mkdir -p ${DIR_LOG_FUNC} | |
echo "### PIDSTAT : `date +'%Y/%m/%d %H:%M:%S'` ###" >> ${LOGFILE_FUNC}_pidstat 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_pidstat 2>&1 | |
pidstat -u >> ${LOGFILE_FUNC}_pidstat 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_pidstat 2>&1 | |
return 0 | |
} | |
func_netstat() { | |
DIR_LOG_FUNC="${DIR_LOG}/netstat/" | |
LOGFILE_FUNC="${DIR_LOG_FUNC}/`date +%Y%m%d`.log" | |
[ ! -d ${DIR_LOG_FUNC} ] && mkdir -p ${DIR_LOG_FUNC} | |
echo "### NETSTAT : `date +'%Y/%m/%d %H:%M:%S'` ###" >> ${LOGFILE_FUNC}_netstat 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_netstat 2>&1 | |
netstat -s ${STAT_INTERVAL} ${STAT_CONT} >> ${LOGFILE_FUNC}_netstat 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_netstat 2>&1 | |
return 0 | |
} | |
func_dstat() { | |
DIR_LOG_FUNC="${DIR_LOG}/dstat/" | |
LOGFILE_FUNC="${DIR_LOG_FUNC}/`date +%Y%m%d`.log" | |
[ ! -d ${DIR_LOG_FUNC} ] && mkdir -p ${DIR_LOG_FUNC} | |
echo "### DSTAT : `date +'%Y/%m/%d %H:%M:%S'` ###" >> ${LOGFILE_FUNC}_dstat 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_dstat 2>&1 | |
dstat -tplycmsdnf ${STAT_INTERVAL} ${STAT_CONT} >> ${LOGFILE_FUNC}_dstat 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_dstat 2>&1 | |
return 0 | |
} | |
func_dstat_ps() { | |
DIR_LOG_FUNC="${DIR_LOG}/dstat_ps/" | |
LOGFILE_FUNC="${DIR_LOG_FUNC}/`date +%Y%m%d`.log" | |
[ ! -d ${DIR_LOG_FUNC} ] && mkdir -p ${DIR_LOG_FUNC} | |
echo "### DSTAT PROCESS : `date +'%Y/%m/%d %H:%M:%S'` ###" >> ${LOGFILE_FUNC}_dstat_ps 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_dstat_ps 2>&1 | |
dstat --top-cpu --top-cputime --top-cputime-avg --top-mem --top-oom --top-bio --top-io --top-latency --top-latency-avg ${STAT_INTERVAL} ${STAT_CONT} >> ${LOGFILE_FUNC}_dstat_ps 2>&1 | |
echo "=============================================================================" >> ${LOGFILE_FUNC}_dstat_ps 2>&1 | |
return 0 | |
} | |
#------------------------------------------------------------------------------------------------------------------------ | |
# MAIN | |
#------------------------------------------------------------------------------------------------------------------------ | |
[ ! -d ${DIR_LOG} ] && mkdir -p ${DIR_LOG} | |
echo "### START : `date +'%Y/%m/%d %H:%M:%S'` ###" >> ${LOGFILE} 2>&1 | |
func_top | |
func_iotop | |
func_ps | |
func_ps_child | |
func_vmstat | |
func_mpstat | |
func_iostat | |
func_pidstat | |
func_netstat | |
func_dstat | |
func_dstat_ps | |
echo "### END : `date +'%Y/%m/%d %H:%M:%S'` ###" >> ${LOGFILE} 2>&1 | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment