指定进程系统资源占用统计脚本,cpu、内存、IO、EPS

  1 #!/bin/bash
  2 #author shiqi
  3 
  4 t_pid=29977
  5 es_pid_M=8787
  6 es_pid_S=8284
  7 
  8 if [ $# -eq 0 ];
  9 then
 10     echo -e "\033[33m ------------------------------------- \033[0m"
 11     echo -e "\033[32m 1)测试 translator: ./translator_test.sh 1 interval_time total_time date\033[0m"
 12     echo -e "\033[31m 2)测试 inserter & es: $0 2 interval_time total_time date\033[0m"
 13     exit
 14 fi
 15 
 16 if [ $1 -eq 1 ];
 17 then
 18     if [ -z $2 -a -z $3 ];
 19     then
 20         echo -e "\033[31m 必须按照格式: $0 $1 interval_time total_time date such as: $0 $1 10 300 20200426 \033[0m"
 21         exit
 22     fi
 23     if [ -z $4 ];
 24     then
 25         echo -e "\033[31m You must have a date to exec \033[0m"    
 26         exit
 27     fi
 28     starttime=$4
 29     interval_time=$2
 30     total_time=$3
 31     dataSource=/home/fantom/kechaojian/20200410/netflow
 32     targetPath=/data/primitive/$starttime/sangfor
 33     if [ ! -d $targetPath ];
 34     then
 35         mkdir -p $targetPath
 36         echo "Path $targetPath create success"
 37     fi
 38     if [ ! -d $dataSource ];
 39     then
 40         echo "Data source not exist please change the data source!"
 41         exit
 42     else
 43         systemctl stop inserter 
 44         /bin/cp $dataSource $targetPath -rf
 45         date -s "$starttime 00:01:00"
 46         count=`expr $total_time / $interval_time`
 47         nohup pidstat -d $interval_time $count -p $t_pid >> translator_io_info.log & 
 48         i=0
 49         top -b -n 1 -p 29977 | grep PID >>translator_cpu_mem_info.log
 50         while [ $i -lt $total_time ];
 51         do 
 52             top -b -n 1 -p $t_pid | grep $t_pid >> translator_cpu_mem_info.log
 53 #            pidstat -d 1 1 | grep $t_pid >> translator_io_info.log 
 54             sleep $interval_time
 55             echo -e "\033[33m Current time:$i  Total time:$total_time \033[0m"
 56             ((i=i+$interval_time))
 57         done
 58     fi    
 59 fi
 60 
 61 
 62 if [ $1 -eq 2 ];
 63 then
 64         if [ -z $2 -a -z $3 ];
 65         then
 66         echo -e "\033[31m 必须按照格式: $0 $1 interval_time total_time date such as: $0 $1 10 300 20200426 \033[0m"
 67                 exit
 68         fi  
 69         if [ -z $4 ];
 70         then
 71                 echo -e "\033[31m You must have a date to exec \033[0m" 
 72                 exit
 73         fi  
 74         starttime=$4
 75         interval_time=$2
 76         total_time=$3
 77         dataSource=/data/dap/log_data/store/fw/kvd/S/$starttime/
 78         if [ ! -d $dataSource ];
 79         then
 80                 echo "Data source not exist please change the data source!"
 81                 exit
 82         else
 83                 date -s "$starttime 00:01:00"
 84                 systemctl start inserter &&
 85         i_pid=$(ps -aux | grep inserter | grep "/usr/bin" | awk '{print $2}') 
 86                 count=`expr $total_time / $interval_time`
 87                 nohup pidstat -d $interval_time $count -p $i_pid >> inserter_io_info.log & 
 88                 nohup pidstat -d $interval_time $count -p $es_pid_M >> es_master_io_info.log & 
 89                 nohup pidstat -d $interval_time $count -p $es_pid_S >> es_slave_io_info.log & 
 90                 sleep 2
 91         es idx | grep health >> es_num.log
 92         i=0 
 93                 top -b -n 1 -p $i_pid | grep PID >>inserter_cpu_mem_info.log
 94                 top -b -n 1 -p $es_pid_M | grep PID >>es_M_cpu_mem_info.log
 95                 top -b -n 1 -p $es_pid_S | grep PID >>es_S_cpu_mem_info.log
 96                 while [ $i -lt $total_time ];
 97                 do 
 98                         top -b -n 1 -p $i_pid | grep $i_pid >> inserter_cpu_mem_info.log
 99                         top -b -n 1 -p $es_pid_M | grep $es_pid_M >> es_M_cpu_mem_info.log
100                         top -b -n 1 -p $es_pid_S | grep $es_pid_S >> es_S_cpu_mem_info.log
101             es idx | grep ngfw.access-2020-07-17 >> es_num.log
102 #                       pidstat -d 1 1 | grep $t_pid >> translator_io_info.log 
103                         sleep $interval_time
104                         echo -e "\033[33m Current time:$i  Total time:$total_time \033[0m"
105                         ((i=i+$interval_time))
106                 done
107         fi    
108 fi

 

上一篇:Linux中mpstat命令参数详解


下一篇:Oracle统计一个小时内,一天内、一个星期内、一个月内、一年内的数据