File tree Expand file tree Collapse file tree 2 files changed +74
-0
lines changed Expand file tree Collapse file tree 2 files changed +74
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ # @Function
3+ # monitor host:network io memory cpu
4+ #
5+ # @Usage
6+ # $ ./monitor-host.sh
7+ #
8+ # @author Bryant Hang
9+
10+ DELAY=10
11+ COUNT=60
12+
13+ LOG_PATH=' monitor_path'
14+
15+ if ! [ -d $monitor_log_path ]; then
16+ mkdir -p $monitor_log_path
17+ fi
18+
19+ cur_date=" ` date +%Y%m%d` "
20+
21+ top_log_path=$LOG_PATH ' /top_' $cur_date ' .log'
22+ memory_log_path=$LOG_PATH ' /memory_' $cur_date ' .log'
23+ cpu_log_path=$LOG_PATH ' /cpu_' $cur_date ' .log'
24+ io_log_path=$LOG_PATH ' /io_' $cur_date ' .log'
25+ network_log_path=$LOG_PATH ' /network_' $cur_date ' .log'
26+
27+ # total performance check
28+ top -b -d $DELAY -n $COUNT > top_log_path 2>&1 &
29+
30+ # memory check
31+ vmstat $DELAY $COUNT > memory_log_path 2>&1 &
32+
33+ # cpu check
34+ sar -u $DELAY $COUNT > cpu_log_path 2>&1 &
35+
36+ # IO check
37+ iostat $DELAY $COUNT > io_log_path 2>&1 &
38+
39+ # network check
40+ sar -n DEV $DELAY $COUNT > network_log_path 2>&1 &
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ # @Function
3+ # Show total and every process's memory and cpu usage
4+ #
5+ # @Usage
6+ # $ ./show-cpu-and-memory.sh
7+ #
8+ # @author Bryant Hang
9+ cur_date=" ` date +%Y%m%d` "
10+
11+ total_mem=" ` free -m | grep ' Mem' ` "
12+ total_cpu=" ` top -n 1 | grep ' Cpu' ` "
13+
14+ echo ' **********' $cur_date ' **********'
15+
16+ echo ' '
17+
18+ echo $total_mem
19+ echo $total_cpu
20+
21+ echo ' '
22+
23+ for i in ` ps -ef | grep -v " awk|$0 " | awk ' {print $2}' `
24+ do
25+ # not pid
26+ if [[ $i == * [! 0-9]* ]]; then
27+ continue
28+ fi
29+
30+ mem=` cat /proc/$i /status 2> /dev/null | grep VmRSS | awk ' {print $2" " $3}' `
31+ cpu=` top -n 1 -b | awk ' $1==' $i ' {print $9}' `
32+
33+ echo ' pid: ' $i ' , memory: ' $mem ' , cpu:' $cpu ' %'
34+ done
You can’t perform that action at this time.
0 commit comments