1
+ #Region ;**** 参数创建于 ACNWrapper_GUI ****
2
+ #AutoIt3Wrapper_outfile= 某业务监控脚本v20120427.exe
3
+ #EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
4
+ ; AutoIT script
5
+ ; Monitor for xxxx 某业务
6
+ ; by avyou
7
+ ; 2011-03-20
8
+ ; update 2011-10-28
9
+ ; last update 2012-04-27
10
+
11
+ #Include < File.au3>
12
+ #include < Thread.au3>
13
+ ; 释放内存
14
+ _RTEmptyWorkingSet()
15
+
16
+ ; 定义错误信息
17
+ Dim $error
18
+ $error = ' ERROR (): CXMPPClient::onDisconnect(),'
19
+
20
+ Dim $pm
21
+ $pm = MsgBox (4 + 32 ," 在线客服进程监控" ,' 在线客服程序将启动并被监控,退出请安"否"' ,5 )
22
+
23
+ Func _ReduceMemory($i_PID = - 1 )
24
+ If $i_PID <> - 1 Then
25
+ Local $ai_Handle = DllCall (" kernel32.dll" , ' int' , ' OpenProcess' , ' int' , 0x1f0fff , ' int' , False , ' int' , $i_PID )
26
+ Local $ai_Return = DllCall (" psapi.dll" , ' int' , ' EmptyWorkingSet' , ' long' , $ai_Handle [0 ])
27
+ DllCall (' kernel32.dll' , ' int' , ' CloseHandle' , ' int' , $ai_Handle [0 ])
28
+ Else
29
+ Local $ai_Return = DllCall (" psapi.dll" , ' int' , ' EmptyWorkingSet' , ' long' , - 1 )
30
+ EndIf
31
+
32
+ Return $ai_Return [0 ]
33
+ EndFunc
34
+
35
+ Func nowtime()
36
+ return (@YEAR & " -" & @MON & " -" & @MDAY & " " & @HOUR & " :" & @MIN & " :" & @SEC )
37
+ EndFunc
38
+
39
+ ; ;############### myserver1 组启动函数 ####################
40
+ Func Stop_myserver()
41
+ ShellExecute (" taskkill" , " /F /IM myserver.exe" , @ScriptDir )
42
+ Sleep (3000 )
43
+ EndFunc
44
+
45
+ Func Start_myserver()
46
+ ShellExecute (" D:\myserver1\myserver.bat" )
47
+ EndFunc
48
+
49
+ ; ;###############008_team_3s 组启动函数########################
50
+ Func Stop_myserver008()
51
+ ShellExecute (" taskkill" , " /F /IM myserver008.exe" , @ScriptDir )
52
+ Sleep (3000 )
53
+ EndFunc
54
+
55
+ Func Start_myserver008()
56
+ ShellExecute (" D:\008_team_3s\myserver008.bat" )
57
+ EndFunc
58
+
59
+ ; ;############### 004_team_fixed 组启动函数 ##################################
60
+ Func Stop_myserver004()
61
+ ShellExecute (" taskkill" , " /F /IM myserver004.exe" , @ScriptDir )
62
+ Sleep (3000 )
63
+ EndFunc
64
+
65
+ Func Start_myserver004()
66
+ ShellExecute (" D:\004_team_fixed\myserver004.bat" )
67
+ EndFunc
68
+
69
+ ; ;################## SHMonitor 进程函数 ######################################
70
+ Func Stop_SHMonitor()
71
+ ShellExecute (" taskkill" , " /F /IM SHMonitor.exe" , @ScriptDir )
72
+ Sleep (3000 )
73
+ EndFunc
74
+
75
+ Func Start_SHMonitor()
76
+ ShellExecute (" D:\myserver1\SHMonitor.bat" )
77
+ EndFunc
78
+
79
+
80
+ Select
81
+ Case $pm = 6 Or $pm = - 1
82
+ While 1
83
+ Sleep (3000 )
84
+ ; 监控openfire进程,需要注意的是openfire有两个进程,一个是openfire.exe,一个是openfired.exe,openfire.exe开启的话,openfired.exe不一定开启。
85
+ $list1 = ProcessList (" openfire.exe" )
86
+ $pnum1 = $list1 [0 ][0 ]
87
+ If ProcessExists (" openfire.exe" )= 0 Then
88
+ $check_file_log = FileOpen (" D:\myserver1\check-某业务.log" , 1 )
89
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------发现openfire进程已经关闭!" )
90
+ ShellExecute (" C:\Program Files\Openfire\bin\openfire.exe" )
91
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------启动openfire进程和服务!" )
92
+ FileClose ($check_file_log )
93
+ Sleep (10000 )
94
+
95
+ ElseIf $pnum1 > 1 Then
96
+ $check_file_log = FileOpen (" D:\myserver1\check-某业务.log" , 1 )
97
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------发现多个openfire进程!" )
98
+ ProcessClose (" openfire.exe" )
99
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------结束openfire进程!" )
100
+ FileClose ($check_file_log )
101
+ EndIf
102
+
103
+ ; 监控openfired进程
104
+ $list2 = ProcessList (" openfired.exe" )
105
+ $pnum2 = $list2 [0 ][0 ]
106
+ If ProcessExists (" openfired.exe" )= 0 Then
107
+ $check_file_log = FileOpen (" D:\myserver1\check-某业务.log" , 1 )
108
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------发现openfired服务已经关闭!" )
109
+ ProcessClose (" openfire.exe" )
110
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------结束openfire进程!" )
111
+ ShellExecute (" C:\Program Files\Openfire\bin\openfire.exe" )
112
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------启动openfire进程和服务!" )
113
+ FileClose ($check_file_log )
114
+ Sleep (10000 )
115
+
116
+ ElseIf $pnum2 > 1 Then
117
+ $check_file_log = FileOpen (" D:\myserver1\check-某业务.log" , 1 )
118
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------发现多个openfired服务!" )
119
+ ProcessClose (" openfired.exe" )
120
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------结束openfired进程!" )
121
+ FileClose ($check_file_log )
122
+ EndIf
123
+
124
+ #CS ;监控myserver程序错误,发现有20次连接不上openfire,自动重启myserver
125
+ $lastline=FileReadLine("D:\myserver1\myserver1.log",-1)
126
+ ;如果最后一行存在错误后,再去判断后20行是否存在错误,不然循环检测会变得很慢。
127
+ If StringInStr($lastline,$error) Then
128
+ $has_error= True
129
+ $num_lines = _FileCountLines("D:\myserver1\myserver1.log")
130
+ For $error_lines= $num_lines To $num_lines-20 Step -1
131
+ $var_line=FileReadLine("D:\myserver1\myserver1.log",$error_lines)
132
+ If Not StringInStr($var_line,$error) Then
133
+ $has_error= False
134
+ EndIf
135
+ Next
136
+ If $has_error= True Then
137
+ $check_file_log = FileOpen("D:\myserver1\check-某业务.log", 1)
138
+ FileWriteLine($check_file_log,"[" & nowtime() & "]" & "------发现myserver.log日志中有CXMPPClient::onDisconnect(), error:错误!,一直连接不上openfire.")
139
+ Stop_myserver()
140
+ FileWriteLine($check_file_log,"[" & nowtime() & "]" & "------结束myserver.exe进程!")
141
+ Start_myserver()
142
+ FileWriteLine($check_file_log,"[" & nowtime() & "]" & "------启动myserver.exe进程!")
143
+ FileClose($check_file_log)
144
+ EndIf
145
+ EndIf
146
+ #CE
147
+
148
+ ; ########################## 监控myserver进程 ################################################
149
+ $list3 = ProcessList (" myserver.exe" )
150
+ $pnum3 = $list3 [0 ][0 ]
151
+ If $pnum3 = 0 Then
152
+ $check_file_log = FileOpen (" D:\myserver1\check-某业务.log" , 1 )
153
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------发现myserver.exe进程已经被关闭!" )
154
+ Stop_myserver()
155
+ Start_myserver()
156
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------启动myserver.exe进程!" )
157
+ FileClose ($check_file_log )
158
+ ElseIf $pnum3 > 1 Then
159
+ $check_file_log = FileOpen (" D:\myserver1\check-某业务.log" , 1 )
160
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------发现有多个myserver.exe进程!" )
161
+ Stop_myserver()
162
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------结束myserver.exe进程!" )
163
+ Start_myserver()
164
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------启动myserver.exe进程!" )
165
+ FileClose ($check_file_log )
166
+ EndIf
167
+ ; ########################## 监控SHmonitor进程 ###########################################
168
+ $list4 = ProcessList (" SHMonitor.exe" )
169
+ $pnum4 = $list4 [0 ][0 ]
170
+ If $pnum4 = 0 Then
171
+ $check_file_log = FileOpen (" D:\myserver1\check-某业务.log" , 1 )
172
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------发现SHMonitor.exe进程已经被关闭!" )
173
+ Start_SHMonitor()
174
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------启动SHMonitor.exe进程!" )
175
+ FileClose ($check_file_log )
176
+ ElseIf $pnum4 > 1 Then
177
+ $check_file_log = FileOpen (" D:\myserver1\check-某业务.log" , 1 )
178
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------发现有多个SHMonitor.exe进程!" )
179
+ Stop_SHMonitor()
180
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------结束SHMonitor.exe进程!" )
181
+ Start_SHMonitor()
182
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------启动SHMonitor.exe进程!" )
183
+ FileClose ($check_file_log )
184
+ EndIf
185
+
186
+ ; ###################### 监控myserver004进程 ###############################################
187
+ $list5 = ProcessList (" myserver004.exe" )
188
+ $pnum5 = $list5 [0 ][0 ]
189
+ If $pnum5 = 0 Then
190
+ $check_file_log = FileOpen (" D:\004_team_fixed\check-某业务.log" , 1 )
191
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------发现myserver004.exe进程已经被关闭!" )
192
+ Stop_myserver004()
193
+ Start_myserver004()
194
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------启动myserver004.exe进程!" )
195
+ FileClose ($check_file_log )
196
+ ElseIf $pnum5 > 1 Then
197
+ $check_file_log = FileOpen (" D:\004_team_fixed\check-某业务.log" , 1 )
198
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------发现有多个myserver004.exe进程!" )
199
+ Stop_myserver004()
200
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------结束myserver004.exe进程!" )
201
+ Start_myserver004()
202
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------启动myserver004.exe进程!" )
203
+ FileClose ($check_file_log )
204
+ EndIf
205
+
206
+ ; ###################### 监控myserver008 进程 ###############################################
207
+ $list6 = ProcessList (" myserver008.exe" )
208
+ $pnum6 = $list6 [0 ][0 ]
209
+ If $pnum6 = 0 Then
210
+ $check_file_log = FileOpen (" D:\008_team_3s\check-某业务.log" , 1 )
211
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------发现myserver008.exe进程已经被关闭!" )
212
+ Stop_myserver008()
213
+ Start_myserver008()
214
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------启动myserver008.exe进程!" )
215
+ FileClose ($check_file_log )
216
+ ElseIf $pnum6 > 1 Then
217
+ $check_file_log = FileOpen (" D:\008_team_3s\check-某业务.log" , 1 )
218
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------发现有多个myserver008.exe进程!" )
219
+ Stop_myserver008()
220
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------结束myserver008.exe进程!" )
221
+ Start_myserver008()
222
+ FileWriteLine ($check_file_log ," [" & nowtime() & " ]" & " ------启动myserver008.exe进程!" )
223
+ FileClose ($check_file_log )
224
+ EndIf
225
+ WEnd
226
+
227
+ Case $pm = 7
228
+ Exit
229
+ EndSelect
0 commit comments