. 1 ! # / Bin / the bash 2 . 3 IF [ " $ # " -LT- 2 ] # $ # number of arguments passed to the script or function . 4 the then . 5 echo " the Usage: $ 0 Program " # $ 0 script name . 6 Exit - . 1 ; . 7 Fi . 8 . 9 SLEEP_TIME = $ . 1 10 the LOG = $ 2 . 11 12 is the while to true 13 is do 14 # threads 15 thread_num SAR = `-q . 1 . 1 |awk ' / ^ Average: / {Print $. 3} ' ` 16 # handles . 17 Open_files =` SAR -v . 1 . 1 | awk ' / ^ Average: / {Print $. 3} ' ` 18 is #cpu occupancy . 19 The cpu_info =` SAR -u . 1 . 1 | awk ' / ^ Average: /. 8} {Print 100- $ ' ` 20 is # memory usage 21 is MEM =` -R & lt SAR . 1 . 1 | awk ' / ^ Average: / {Print ($ 3- $ 5- $. 6 )} / ($ 2 + $. 3) 100 * ' ` 22 is #IO transmission amount 23 SAR = -b `IO . 1 . 1 | awk ' / ^ Average: / Print $ {2} ' ` 24 # output to a log file 25 echo -e " ` DATE + " % Y-M-% D%% H:% M :% S " `, $ {} The cpu_info, MEM} {$, $ {IO}, {thread_num} $, $ {} Open_files " >> $ {} the LOG 26 is SLEEP $ SLEEP_TIME 27 DONE
SAR monitoring shell script for Linux-based resources
Guess you like
Origin www.cnblogs.com/andrew209/p/11567381.html
Ranking