Shell script realizes server process monitoring

  • writing background:

  The project is based on the processing mode of java, weblogic and timer. After each service deployment, the overall status of the timer is a blind spot. There should be more than 100 processes. Whether there is a startup omission or repeated startup, it is difficult to understand the time at a glance.

 

  • Program Description:

1) By configuring the system-defined process (timer) into the configuration file process_signal.config

2) Store all the current java processes of the server in process_current.txt

3) Read the processes in process_signal.config line by line and match them in process_current.txt

4) If there is no match, it is a startup omission, and it is stored in process_invalid.txt. If it matches once, it is normal (no processing), and if it matches more than once, the timer name and the number of starts are recorded in process_invalid.txt.

5) Execute the script once every 30 minutes through the timer, use SQLLOAD to load process_invalid.txt into the data table, and monitor the database table.

 


 

  •  Script description:

1. Overall file structure: 

webusr@iomtimer1:/weblogic/script/process_signal >ls

process_current.txt    process_invalid.txt    process_invalid_his.txt    process_signal.config    process_signal.sh

 

2. Process configuration example:

webusr@iomtimer1:/weblogic/script/process_signal >cat process_signal.config 

#stop recurrenceNAS
extapp.tftonas.PutTfToNas 10 2
extapp.tftonas.PutTfToNas 11 2
extapp.tftonas.PutTfToNas 12 3

 

3. Execution result record: 

webusr@iomtimer1:/weblogic/script/process_signal >cat process_invalid.txt 

132.77.255.36 process [extapp.leaseroute.PutToLeaseRoute 180] is not exist 2018-04-11 08:29:00
132.77.255.36 process [ DealWorkTaskTimer 3001 ] is repeatRun 2 Times 2018-04-11 17:51:56

  

4. Logical matching entry:

webusr@iomtimer1:/weblogic/script/process_signal >cat process_signal.sh

#!/bin/sh

path=/weblogic/script/process_signal #Script path
file_config=process_signal.config #Configuration file name
file_result=process_invalid.txt #Error process information
file_tmp=process_current.txt #Current process information (full, temporary)
if_get_exist="N" #Whether Output log (N does not output, Y outputs)
hostip="127.0.0.1" #Host IP
currenttime=`date "+%Y-%m-%d %H:%M:%S"` #Current system time

#Define method get_process_signal()
get_process_signal(){

  # Dump the last recorded time, append
  cat /weblogic/script/process_signal/process_invalid.txt >> process_invalid_his.txt #Clear
  error process information, current process information
  >/weblogic/script/process_signal/process_invalid.txt
  >/weblogic/ script/process_signal/process_current.txt #Output
  the current time and get all java class processes on the host
  echo "########################## get ps info time is: " $currenttime " #########################">>/weblogic/script/process_signal/process_current.txt
  ps -ef|grep java >>/weblogic/script/process_signal/process_current.txt
  echo "########################## get ps info time is: " $currenttime " # ##########################">>/weblogic/script/process_signal/process_current.txt

  #Read the configuration file one by one process_signal.config
  cat /weblogic/script/process_signal/process_signal.config | while read LINE
  do
    # If the configuration file contains a #, skip the processing
    if [[ `echo $LINE|cut -c1- 1` != "#" ]]; then #If
      the configuration file record exists in the host process
      if [[ -n `find $path -name $file_tmp | xargs grep -w "$LINE"` ]]; then
        #Switch For Y, output to the screen
        if [[ $if_get_exist = "Y" ]]; then
          echo $hostip " process [" $LINE "] is exist " $currenttime >>/weblogic/script/process_signal/process_invalid.txt
        fi
        #Configuration File record matches host process
        run=`find $path -name $file_tmp | xargs grep -w "$LINE"|wc -l`
        if (($run>1));then #Print
          the records in the configuration file that match the number of records with the host process greater than 1
          echo $hostip " process [" $LINE "] is repeatRun "$run " Times" $currenttime >>/weblogic/script/process_signal/process_invalid.txt
        fi #If the
        configuration file record does not exist in the host process
      else
        echo $hostip " process ["$LINE"] is not exist " $currenttime >>/weblogic/script/process_signal/process_invalid.txt
      fi
    fi
  done
} #Call the
method
get_process_signal


#fhs.workflow.EventMonitorMain 4
#find /weblogic/script/process_signal -name process_current.txt | xargs grep -i "fhs.workflow.EventMonitorMain 4"
#ps -ef|grep java|grep "fhs.workflow.EventMonitorMain 4"

5. SqlLOAD storage (including control file conl.ctl)

efile92@iomitfdb2:/interface/contabfile/monitor_time >cat conl.ctl
load data
infile '/interface/contabfile/monitor_time/process_invalid.txt'
truncate into table T_MONITOR_TIMER
fields terminated by '\n'

-- Create table
create table T_MONITOR_TIMER
(
  info VARCHAR2(1000)
)

sqlldr userid=username/password@sid control=/interface/contabfile/monitor_time/ conl.ctl log=/interface/contabfile/monitor_time/conl.log

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324687078&siteId=291194637