From 9da3ba8f79f9d96e7d403ad5097aaa5c58d37872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=92=E7=84=B6Hang?= Date: Mon, 3 Nov 2014 17:22:46 +0800 Subject: [PATCH 1/7] add show-cpu-and-memory.sh --- show-cpu-and-memory.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 show-cpu-and-memory.sh diff --git a/show-cpu-and-memory.sh b/show-cpu-and-memory.sh new file mode 100644 index 00000000..c8c210eb --- /dev/null +++ b/show-cpu-and-memory.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# @Function +# Show every process's memory and cpu usage +# +# @Usage +# $ ./show-cpu-and-memory.sh +# +# @author Bryant Hang + +for i in `ps -ef | egrep -v "awk|$0" | awk '/'$1'/{print $2}'` +do + mem=`cat /proc/$i/status 2> /dev/null | grep VmRSS | awk '{print $2" " $3}'` + cpu=`top -n 1 -b | awk '$1=='$i'{print $9}'` + + echo 'pid: '$i', memory: '$mem', cpu:'$cpu +done \ No newline at end of file From c39bc079769efafe937c90b5fd03fe06aa3a3d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=92=E7=84=B6Hang?= Date: Mon, 3 Nov 2014 17:55:17 +0800 Subject: [PATCH 2/7] refactor show-cpu-and-memory.sh: fix check pid --- show-cpu-and-memory.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/show-cpu-and-memory.sh b/show-cpu-and-memory.sh index c8c210eb..28c28218 100644 --- a/show-cpu-and-memory.sh +++ b/show-cpu-and-memory.sh @@ -9,6 +9,11 @@ for i in `ps -ef | egrep -v "awk|$0" | awk '/'$1'/{print $2}'` do + # not pid + if [[ $i == *[!0-9]* ]]; then + continue + fi + mem=`cat /proc/$i/status 2> /dev/null | grep VmRSS | awk '{print $2" " $3}'` cpu=`top -n 1 -b | awk '$1=='$i'{print $9}'` From 7b4cbe6d0912f9743bd190c1a3cbb0e005248c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=92=E7=84=B6Hang?= Date: Mon, 3 Nov 2014 18:28:42 +0800 Subject: [PATCH 3/7] refactor --- show-cpu-and-memory.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show-cpu-and-memory.sh b/show-cpu-and-memory.sh index 28c28218..1839ec03 100644 --- a/show-cpu-and-memory.sh +++ b/show-cpu-and-memory.sh @@ -17,5 +17,5 @@ do mem=`cat /proc/$i/status 2> /dev/null | grep VmRSS | awk '{print $2" " $3}'` cpu=`top -n 1 -b | awk '$1=='$i'{print $9}'` - echo 'pid: '$i', memory: '$mem', cpu:'$cpu + echo 'pid: '$i', memory: '$mem', cpu:'$cpu'%' done \ No newline at end of file From 11fb8a451e2f859d098204068044f15fa589bdb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=92=E7=84=B6Hang?= Date: Mon, 3 Nov 2014 19:19:05 +0800 Subject: [PATCH 4/7] add monitro-host.sh and refacote show-cpu-and-memory.sh --- monitor-host.sh | 40 ++++++++++++++++++++++++++++++++++++++++ show-cpu-and-memory.sh | 17 +++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 monitor-host.sh diff --git a/monitor-host.sh b/monitor-host.sh new file mode 100644 index 00000000..c12f5945 --- /dev/null +++ b/monitor-host.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# @Function +# monitor host:network io memory cpu +# +# @Usage +# $ 0 * * * * ./monitor-host.sh +# +# @author Bryant Hang + +DELAY=10 +COUNT=60 + +LOG_PATH='monitor_path' + +if ! [ -d $monitor_log_path ]; then + mkdir -p $monitor_log_path +fi + +cur_date="`date +%Y%m%d`" + +top_log_path=$LOG_PATH'/top_'$cur_date'.log' +memory_log_path=$LOG_PATH'/memory_'$cur_date'.log' +cpu_log_path=$LOG_PATH'/cpu_'$cur_date'.log' +io_log_path=$LOG_PATH'/io_'$cur_date'.log' +network_log_path=$LOG_PATH'/network_'$cur_date'.log' + +# total performance check +top -b -d $delay -n $count > top_log_path 2>&1 & + +# memory check +vmstat $delay $count > memory_log_path 2>&1 & + +# cpu check +sar -u $delay $count > cpu_log_path 2>&1 & + +# IO check +iostat $delay $count > io_log_path 2>&1 & + +# network check +sar -n DEV $delay $count > network_log_path 2>&1 & \ No newline at end of file diff --git a/show-cpu-and-memory.sh b/show-cpu-and-memory.sh index 1839ec03..a3fd5e71 100644 --- a/show-cpu-and-memory.sh +++ b/show-cpu-and-memory.sh @@ -1,13 +1,26 @@ #!/bin/bash # @Function -# Show every process's memory and cpu usage +# Show total and every process's memory and cpu usage # # @Usage # $ ./show-cpu-and-memory.sh # # @author Bryant Hang +cur_date="`date +%Y%m%d`" -for i in `ps -ef | egrep -v "awk|$0" | awk '/'$1'/{print $2}'` +total_mem="`free -m | grep 'Mem'`" +total_cpu="`top -n 1 | grep 'Cpu'`" + +echo '**********'$cur_date'**********' + +echo + +echo $total_mem +echo $total_cpu + +echo + +for i in `ps -ef | grep -v "awk|$0" | awk '{print $2}'` do # not pid if [[ $i == *[!0-9]* ]]; then From da64af64d79b2379f0995ab47e0e1f72291fe277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=92=E7=84=B6Hang?= Date: Mon, 3 Nov 2014 23:14:27 +0800 Subject: [PATCH 5/7] refactor --- monitor-host.sh | 12 ++++++------ show-cpu-and-memory.sh | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/monitor-host.sh b/monitor-host.sh index c12f5945..d1f4164b 100644 --- a/monitor-host.sh +++ b/monitor-host.sh @@ -3,7 +3,7 @@ # monitor host:network io memory cpu # # @Usage -# $ 0 * * * * ./monitor-host.sh +# $ ./monitor-host.sh # # @author Bryant Hang @@ -25,16 +25,16 @@ io_log_path=$LOG_PATH'/io_'$cur_date'.log' network_log_path=$LOG_PATH'/network_'$cur_date'.log' # total performance check -top -b -d $delay -n $count > top_log_path 2>&1 & +top -b -d $DELAY -n $COUNT > top_log_path 2>&1 & # memory check -vmstat $delay $count > memory_log_path 2>&1 & +vmstat $DELAY $COUNT > memory_log_path 2>&1 & # cpu check -sar -u $delay $count > cpu_log_path 2>&1 & +sar -u $DELAY $COUNT > cpu_log_path 2>&1 & # IO check -iostat $delay $count > io_log_path 2>&1 & +iostat $DELAY $COUNT > io_log_path 2>&1 & # network check -sar -n DEV $delay $count > network_log_path 2>&1 & \ No newline at end of file +sar -n DEV $DELAY $COUNT > network_log_path 2>&1 & \ No newline at end of file diff --git a/show-cpu-and-memory.sh b/show-cpu-and-memory.sh index a3fd5e71..f8187dc8 100644 --- a/show-cpu-and-memory.sh +++ b/show-cpu-and-memory.sh @@ -13,12 +13,12 @@ total_cpu="`top -n 1 | grep 'Cpu'`" echo '**********'$cur_date'**********' -echo +echo '' echo $total_mem echo $total_cpu -echo +echo '' for i in `ps -ef | grep -v "awk|$0" | awk '{print $2}'` do From de7b7170482cbb53b2895c13a0f7ff33082a12ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=92=E7=84=B6Hang?= Date: Mon, 3 Nov 2014 23:19:31 +0800 Subject: [PATCH 6/7] change file mod --- monitor-host.sh | 0 show-cpu-and-memory.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 monitor-host.sh mode change 100644 => 100755 show-cpu-and-memory.sh diff --git a/monitor-host.sh b/monitor-host.sh old mode 100644 new mode 100755 diff --git a/show-cpu-and-memory.sh b/show-cpu-and-memory.sh old mode 100644 new mode 100755 From ff5877b4f8fb8e5b0f76b201b634a0c010ccce19 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Fri, 16 Jan 2015 21:18:12 +0800 Subject: [PATCH 7/7] format find-in-jars.sh --- find-in-jars.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/find-in-jars.sh b/find-in-jars.sh index 5b76ca36..25382cdb 100755 --- a/find-in-jars.sh +++ b/find-in-jars.sh @@ -46,10 +46,8 @@ done [ -z "$1" ] && { echo No find file pattern! ; usage 1; } dir=${dir:-.} -find ${dir} -iname '*.jar' | while read jarFile -do - jar tf ${jarFile} | egrep "$1" | while read file - do - echo "${jarFile}"\!"${file}" - done +find ${dir} -iname '*.jar' | while read jarFile; do + jar tf ${jarFile} | egrep "$1" | while read file; do + echo "${jarFile}"\!"${file}" + done done