现在开始介绍php+mysql+shell监控系统
1 、目的
此监控系统主要是通过
php+mysql+shell的方式,通过shell脚本对各个机器的其各个服务进行监控,达到及时的了解其各个应用服务的状态(如果宕掉与启动),在检测应用服务宕掉时,记录在日志里与mysql数据库服务器里,同时进行服务宕掉的邮件提示,并自动启动宕掉的应用服务;在检测应该服务启动时,同时进行服务启动的邮件提示,所有的监控内容都能在php制作的web里进行浏览,同时能根据mysql里的数据,把资源监控数据视图化,在浏览数据的时候,更方便。
2 、实现的机制
监控方式主要是通过
shell脚本的实现,针对应用服务运行的端口进行监控,如果其端口开启,则证明此服务运行,反之则此服务没有运行。
3 、监控的应用服务
监控的应用服务有:
A、应用服务器的服务监控
web:
http、yu_tomcat、tomcat 共3个
交换:
pas、ppas、mas、mmas、cas共5个
引擎:
memcache、datastorageservice、http、dbstatserver共4个
B:应用服务器的资源监控
硬盘使用率、
cpu使用率、硬件启动信息错误、i/o使用率、15分钟内的负载、内存使用率(包括内存与swap)、日志错误信息、当前用户登录数
4 、已经监控的省份
目前天津、广西、贵州、海南、河北、河南、湖北、湖南、宁夏、陕西、青海、西藏、新疆、包头、甘肃、江西都已经部署完成,经过
3个月的测试,没有发现问题。
5 、
shell监控脚本内容与解释
(
1)web服务器(以甘肃web为例)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456 1
2
3
4
5 #!/bin/bash
6
7 #ip
8
9 web_ip=$(/sbin/ifconfig eth0|grep "inet addr"|cut -d : -f 2|awk '{print $1}')
10
11 ##eth0网卡的ip
12
13 #name
14
15 web_name=$(hostname)
16
17 ##web主机名
18
19 monitor_name=web
20
21 ##监控的服务器是什么类型
22
23 here='gansu'
24
25 ##监控的省份
26
27 #mysql info
28
29 mysql_ip='1.1.1.1'
30
31 ##数据库的ip
32
33 mysql_username='root'
34
35 ##数据库的用户
36
37 mysql_passwd='****'
38
39 #数据库的密码
40
41 mysql_database='monitor'
42
43 ##选择的数据库
44
45 memory_table=''$here'_memory'
46
47 load_table=''$here'_load'
48
49 io_table=''$here'_io'
50
51 hardware_table=''$here'_hardware'
52
53 message_table=''$here'_message'
54
55 user_table=''$here'_user'
56
57 disk_table=''$here'_disk'
58
59 cpu_table=''$here'_cpu'
60
61 service_table=''$here'_service'
62
63 ##想数据库里写入的表
64
65 #date and log
66
67 day="$(date +%Y%m%d)"
68
69 worklog='/usr/local/monitor/logs/all_work_log'
70
71 downlog='/usr/local/monitor/logs/all_down_log'
72
73 ##日志与实际
74
75 now="$(date +%Y-%m-%d-%T)"
76
77 #web service
78
79 tomcat="$(netstat -antl|grep 8080|wc -l)"
80
81 web_http="$(ps -ef|grep httpd|grep -v grep|wc -l)"
82
83 yz_tomcat="$(netstat -antl|grep 8081|wc -l)"
84
85 ##通过端口与服务在后头的运行情况监控其运行状态
86
87 #cpu service
88
89 alert_cpu='80'
90
91 ##cpu的报警阀值
92
93 web_cpu_idle="$(top -b -n 1 | grep Cpu | awk '{print $5}' | cut -f 1 -d .)"
94
95 web_cpu="$(echo 100 - $web_cpu_idle|/usr/bin/bc)"
96
97 ##监控cpu的使用率
98
99 #memory service
100
101 alert_mem='100'
102
103 ##内存的报警阀值
104
105 web_mem="$(/usr/bin/free -m|grep Mem|awk '{print $4}')"
106
107 web_swap="$(/usr/bin/free -m|grep Swap|awk '{print $3}')"
108
109 ##memory与swap的使用率
110
111 alert_swap='0'
112
113 ##swap的报警阀值
114
115 #memory log
116
117 memory_worklog='/usr/local/monitor/logs/mem_work_log'
118
119 memory_downlog='/usr/local/monitor/logs/mem_down_log'
120
121 #load service
122
123 cpu_count="$(grep -c 'model name' /proc/cpuinfo)"
124
125 alert_load="$(echo $cpu_count/2|/usr/bin/bc)"
126
127 web_load="$(uptime|awk '{print $NF}'|cut -f 1 -d .)"
128
129 web_load_15="$(uptime|awk '{print $NF}')"
130
131 #监控负载的使用率
132
133 #load log
134
135 load_worklog='/usr/local/monitor/logs/load_work_log'
136
137 load_downlog='/usr/local/monitor/logs/load_down_log'
138
139 #io service
140
141 alert_io='80'
142
143 web_io_idle_back="$(/usr/bin/iostat|awk 'NR==4{print $NF}'|cut -f 1 -d .)"
144
145 web_io_idle="$(echo 100 - $web_io_idle_back|/usr/bin/bc)"
146
147 ##io的使用值
148
149 #io log
150
151 io_worklog='/usr/local/monitor/logs/io_work_log'
152
153 io_downlog='/usr/local/monitor/logs/io_down_log'
154
155 #hardware service
156
157 web_hardware_error="$(dmesg|grep -i error|wc -l)"
158
159 web_info_error="$(dmesg|grep -i error)"
160
161 ##开机启动的错误信息
162
163 #hardware error log
164
165 hard_worklog='/usr/local/monitor/logs/hard_work_log'
166
167 hard_downlog='/usr/local/monitor/logs/hard_down_log'
168
169 #message service
170
171 web_message_error_count="$(awk '/"$(date +%Y%m%d)"/' /var/log/messages|grep -i error|wc -l)"
172
173 web_message_error="$(awk '/"$(date +%Y%m%d)"/' /var/log/messages|grep -i error)"
174
175 ##日志的错误信息
176
177 #message error log
178
179 message_worklog='/usr/local/monitor/logs/message_work_log'
180
181 message_downlog='/usr/local/monitor/logs/message_down_log'
182
183 #user service
184
185 web_user_count="$(/usr/bin/who|wc -l)"
186
187 web_user_info="$(/usr/bin/who)"
188
189 ##当前登录的用户值
190
191 #user log
192
193 user_worklog='/usr/local/monitor/logs/user_work_log'
194
195 user_downlog='/usr/local/monitor/logs/user_down_log'
196
197 #disk service
198
199 alert_disk='80'
200
201 web_disk="$(/bin/df -H|sort -k5nr|grep -vE 'Filesystem|tmpfs|cdrom'|awk '{print $5 " " $1}')"
202
203 web_disk_use=$(echo $web_disk|awk '{print $1}'|cut -d '%' -f1)
204
205 web_disk_partition=$(echo $web_disk|awk '{print $2}')
206
207 #硬盘使用率
208
209 #disk log
210
211 disk_worklog='/usr/local/monitor/logs/disk_work_log'
212
213 disk_downlog='/usr/local/monitor/logs/disk_down_log'
214
215 #cpu log
216
217 cpu_worklog='/usr/local/monitor/logs/cpu_work_log'
218
219 cpu_downlog='/usr/local/monitor/logs/cpu_down_log'
220
221 #notification mail
222
223 email='denglei@ctfo.com'
224
225 ##报警的接收人
226
227 #monitor
228
229 if [ ! -d "$loghere" ];then
230
231 mkdir $loghere
232
233 fi
234
235 #check web service
236
237 if [ $web_http -ge 1 ];then
238
239 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: http Monitor_Server: $monitor_name is working" >> $worklog-$day
240
241 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$web_name','$web_ip','$monitor_name','web_http','working',now())";
242
243 else
244
245 /etc/init.d/httpd start
246
247 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: http Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: http was a problem" $email
248
249 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: http Monitor_Server: $montior_name is down" >> $downlog-$day
250
251 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$web_name','$web_ip','$monitor_name','web_http','downing',now())";
252
253 fi
254
255
256
257 if [ $tomcat -ge 1 ];then
258
259 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: tomcat Monitor_Server: $monitor_name is working" >> $worklog-$day
260
261 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$web_name','$web_ip','$monitor_name','tomcat','working',now())";
262
263 else
264
265 /usr/local/monitor/shell/web_tomcat.sh
266
267 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: tomcat Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: tomcat was a problem" $email
268
269 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: tomcat Monitor_Server: $montior_name is down" >> $downlog-$day
270
271 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$web_name','$web_ip','$monitor_name','tomcat','downing',now())";
272
273 fi
274
275 if [ $yz_tomcat -ge 1 ];then
276
277 echo "$now ShengFen: $here Server: $web_name Service: Ip: $web_ip yz_tomcat Monitor_Server: $monitor_name is working" >> $worklog-$day
278
279 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$web_name','$web_ip','$monitor_name','yz_tomcat','working',now())";
280
281 else
282
283 /usr/local/monitor/shell/web_yz_tomcat.sh
284
285 echo "$now ShengFen: $here Server: $web_name Service: Ip: $web_ip yz_tomcat Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: yz_tomcat was a problem" $email
286
287 echo "$now ShengFen: $here Server: $web_name Service: Ip: $web_ip yz_tomcat Monitor_Server: $montior_name is down" >> $downlog-$day
288
289 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$web_name','$web_ip','$monitor_name','yz_tomcat','downing',now())";
290
291 fi
292
293 #check cpu_idle
294
295 if [ $web_cpu -ge $alert_cpu ];then
296
297 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: cpu_idle Monitor_Server: $monitor_name Cpu_use: $web_cpu"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: cpu_use was Exceed Threshold value: 80%" $email
298
299 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: cpu_idle Monitor_Server: $monitor_name Cpu_use: $web_cpu" >> $cpu_downlog-$day
300
301 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $cpu_table values ('','$here','$web_name','$web_ip','$monitor_name','cpu_use','$alert_cpu','$web_cpu','abnormal',now())";
302
303 else
304
305 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: cpu_idle Monitor_Server: $monitor_name Cpu_use: $web_cpu" >> $cpu_worklog-$day
306
307 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $cpu_table values ('','$here','$web_name','$web_ip','$monitor_name','cpu_use','$alert_cpu','$web_cpu','normal',now())";
308
309 fi
310
311 #check memory
312
313 if [ $web_mem -le $alert_mem ];then
314
315 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: memory Monitor_Server: $monitor_name Free_mem: $web_mem"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: memory was Exceed Threshold value" $email
316
317 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: memory Monitor_Server: $monitor_name Free_mem: $web_mem" >> $memory_downlog-$day
318
319 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$web_name','$web_ip','$monitor_name','memory','$alert_mem','$web_mem','abnormal',now())";
320
321 else
322
323 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: memory Monitor_Server: $monitor_name Free_mem: $web_mem" >> $memory_worklog-$day
324
325 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$web_name','$web_ip','$monitor_name','memory','$alert_mem','$web_mem','normal',now())";
326
327 fi
328
329 #check swap
330
331 if [ $web_swap -gt $alert_swap ];then
332
333 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: swap Monitor_Server: $monitor_name Swap_web: $web_swap"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: swap Ip: $web_ip was Exceed Threshold value" $email
334
335 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: swap Monitor_Server: $monitor_name Swap_web: $web_swap" >> $memory_downlog-$day
336
337 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$web_name','$web_ip','$monitor_name','swap','$alert_swap','$web_swap','abnormal',now())";
338
339 else
340
341 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: swap Monitor_Server: $monitor_name Swap_web: $web_swap" >> $memory_worklog-$day
342
343 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$web_name','$web_ip','$monitor_name','swap','$alert_swap','$web_swap','normal',now())";
344
345 fi
346
347 #check load_15
348
349 if [ $web_load -ge $alert_load ];then
350
351 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: load_15 Monitor_Server: $monitor_name Load_use: $web_load_15"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: load_15 Ip: $web_ip was Exceed Threshold value" $email
352
353 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: load_15 Monitor_Server: $monitor_name Load_use: $web_load_15" >> $load_downlog-$day
354
355 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $load_table values ('','$here','$web_name','$web_ip','$monitor_name','load_15','$alert_load','$web_load_15','abnormal',now())";
356
357 else
358
359 echo "$now ShengFen: $here Server: $server Ip: $ip Service: load Monitor_Server: $monitor_name Load_use: $web_load_15" >> $load_worklog-$day
360
361 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $load_table values ('','$here','$web_name','$web_ip','$monitor_name','load_15','$alert_load','$web_load_15','normal',now())";
362
363 fi
364
365 #check io_idle
366
367 if [ $web_io_idle -ge $alert_io ];then
368
369 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: io_idle Monitor_Server: $monitor_name Io_use: $web_io_idle"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: io_use was Exceed Threshold value: 80%" $email
370
371 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: io_idle Monitor_Server: $monitor_name Io_use: $web_io_idle" >> $io_downlog-$day
372
373 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $io_table values ('','$here','$web_name','$web_ip','$monitor_name','io_use','$alert_io','$web_io_idle','abnormal',now())";
374
375 else
376
377 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: io_idle Monitor_Server: $monitor_name Io_use: $web_io_idle" >> $io_worklog-$day
378
379 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $io_table values ('','$here','$web_name','$web_ip','$monitor_name','io_use','$alert_io','$web_io_idle','normal',now())";
380
381 fi
382
383 #check hareware error info
384
385 if [ $web_hardware_error -gt 0 ];then
386
387 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: hardware_error Monitor_Server: $monitor_name Error: $web_info_error"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: hardware_error were some hardware imformation error" $email
388
389 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: hardware_error Monitor_Server: $monitor_name Error: $web_info_error" >> $hard_downlog-$day
390
391 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $hardware_table values ('','$here','$web_name','$web_ip','$monitor_name','hardware_error','0','$web_hardware_error','abnormal',now())";
392
393 else
394
395 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: hardware_error Monitor_Server: $monitor_name Error: Nothing" >> $hard_worklog-$day
396
397 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $hardware_table values ('','$here','$web_name','$web_ip','$monitor_name','hardware_error','0','$web_hardware_error','normal',now())";
398
399 fi
400
401 #check message error
402
403 if [ $web_message_error_count -ge 1 ];then
404
405 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: message_error Monitor_Server: $monitor_name Message_error: $web_message_error"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: message_error were some message imformation error" $email
406
407 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: message_error Monitor_Server: $monitor_name Message_error: $web_message_error" >> $message_downlog-$day
408
409 /usr/bin/mysql-h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $message_table values ('','$here','$web_name','$web_ip','$monitor_name','message_error','1','$web_message_error_count','abnormal',now())";
410
411 else
412
413 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: message_error Monitor_Server: $monitor_name Message_error: Nothing" >> $message_worklog-$day
414
415 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $message_table values ('','$here','$web_name','$web_ip','$monitor_name','message_error','1','$web_message_error_count','normal',now())";
416
417 fi
418
419 #check user
420
421 if [ $web_user_count -ge 3 ];then
422
423 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: user Monitor_Server: $monitor_name User: $web_user_info"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: user was Exceed Threshold value: 3" $email
424
425 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: user Monitor_Server: $monitor_name User: $web_user_info" >> $user_downlog-$day
426
427 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $user_table values ('','$here','$web_name','$web_ip','$monitor_name','user','3','$web_user_count','abnormal',now())";
428
429 else
430
431 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: user Monitor_Server: $monitor_name User: normal" >> $user_worklog-$day
432
433 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $user_table values ('','$here','$web_name','$web_ip','$monitor_name','user','3','$web_user_count','normal',now())";
434
435 fi
436
437 #check disk
438
439 if [ $web_disk_use -ge $alert_disk ];then
440
441 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: disk_use Monitor_Server: $monitor_name Disk_use: $web_disk_partition ($web_disk_use%)"|/bin/mail -s "Warning!!! $here Server: $web_name Service: disk_use was Exceed Threshold value : $alert_disk% " $email
442
443 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: disk_use Monitor_Server: $monitor_name Disk_use: $web_disk_partion ($web_disk_use%)" >> $disk_downlog-$day
444
445 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $disk_table values ('','$here','$web_name','$web_ip','$monitor_name','disk_use','$alert_disk','$web_disk_partition','$web_disk_use','abnormal',now())";
446
447 else
448
449 echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: disk_use Monitor_Server: $monitor_name Disk_use: $web_disk_partition ($web_disk_use%)" >> $disk_worklog-$day
450
451 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $disk_table values ('','$here','$web_name','$web_ip','$monitor_name','disk_use','$alert_disk','$web_disk_partition','$web_disk_use','normal',now())";
452
453 fi
454
455
456
(
2)交换服务器(以甘肃交换为例,解释内容参照甘肃web)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452 1
2
3
4
5 #!/bin/bash
6
7 #ip
8
9 jh_ip=$(/sbin/ifconfig eth0|grep "inet addr"|cut -d : -f 2|awk '{print $1}')
10
11 #name
12
13 jh_name=$(hostname)
14
15 monitor_name=jiaohuan
16
17 here='gansu'
18
19 #mysql info
20
21 mysql_ip='1.1.1.1'
22
23 mysql_username='root'
24
25 mysql_passwd='****'
26
27 mysql_database='monitor'
28
29 memory_table=''$here'_memory'
30
31 load_table=''$here'_load'
32
33 io_table=''$here'_io'
34
35 hardware_table=''$here'_hardware'
36
37 message_table=''$here'_message'
38
39 user_table=''$here'_user'
40
41 disk_table=''$here'_disk'
42
43 cpu_table=''$here'_cpu'
44
45 service_table=''$here'_service'
46
47 #date and log
48
49 day="$(date +%Y%m%d)"
50
51 worklog='/usr/local/monitor/logs/all_work_log'
52
53 downlog='/usr/local/monitor/logs/all_down_log'
54
55 now="$(date +%Y-%m-%d-%T)"
56
57 loghere='/usr/local/monitor/logs'
58
59 #jiaohuan service
60
61 pas="$(ps -ef|grep pas|grep -v grep|grep -v ppas|wc -l)"
62
63 ppas="$(ps -ef|grep ppas|grep -v grep|wc -l)"
64
65 cas="$(ps -ef|grep cas|grep -v grep|wc -l)"
66
67 mas="$(ps -ef|grep mas|grep -v grep|grep -v mmas|wc -l)"
68
69 mmas="$(ps -ef|grep mmas|grep -v grep|wc -l)"
70
71 #cpu service
72
73 alert_cpu='80'
74
75 jh_cpu_idle="$(top -b -n 1 | grep Cpu | awk '{print $5}' | cut -f 1 -d .)"
76
77 jh_cpu="$(echo 100 - $jh_cpu_idle|/usr/bin/bc)"
78
79 #memory service
80
81 alert_mem='100'
82
83 jh_mem="$(/usr/bin/free -m|grep Mem|awk '{print $4}')"
84
85 jh_swap="$(/usr/bin/free -m|grep Swap|awk '{print $3}')"
86
87 alert_swap='0'
88
89 #memory log
90
91 memory_worklog='/usr/local/monitor/logs/mem_work_log'
92
93 memory_downlog='/usr/local/monitor/logs/mem_down_log'
94
95 #load service
96
97 cpu_count="$(grep -c 'model name' /proc/cpuinfo)"
98
99 alert_load="$(echo $cpu_count/2|/usr/bin/bc)"
100
101 jh_load="$(uptime|awk '{print $NF}'|cut -f 1 -d .)"
102
103 jh_load_15="$(uptime|awk '{print $NF}')"
104
105 #load log
106
107 load_worklog='/usr/local/monitor/logs/load_work_log'
108
109 load_downlog='/usr/local/monitor/logs/load_down_log'
110
111 #io service
112
113 alert_io='80'
114
115 jh_io_idle_back="$(/usr/bin/iostat|awk 'NR==4{print $NF}'|cut -f 1 -d .)"
116
117 jh_io_idle="$(echo 100 - $jh_io_idle_back|/usr/bin/bc)"
118
119 #io log
120
121 io_worklog='/usr/local/monitor/logs/io_work_log'
122
123 io_downlog='/usr/local/monitor/logs/io_down_log'
124
125 #hardware service
126
127 jh_hardware_error="$(dmesg|grep -i error|wc -l)"
128
129 jh_info_error="$(dmesg|grep -i error)"
130
131 #hardware error log
132
133 hard_worklog='/usr/local/monitor/logs/hard_work_log'
134
135 hard_downlog='/usr/local/monitor/logs/hard_down_log'
136
137 #message service
138
139 jh_message_error_count="$(awk '/"$(date +%Y%m%d)"/' /var/log/messages|grep -i error|wc -l)"
140
141 jh_message_error="$(awk '/"$(date +%Y%m%d)"/' /var/log/messages|grep -i error)"
142
143 #message error log
144
145 message_worklog='/usr/local/monitor/logs/message_work_log'
146
147 message_downlog='/usr/local/monitor/logs/message_down_log'
148
149 #user service
150
151 jh_user_count="$(/usr/bin/who|wc -l)"
152
153 jh_user_info="$(/usr/bin/who)"
154
155 #user log
156
157 user_worklog='/usr/local/monitor/logs/user_work_log'
158
159 user_downlog='/usr/local/monitor/logs/user_down_log'
160
161 #disk service
162
163 alert_disk='80'
164
165 jh_disk="$(/bin/df -H|sort -k5nr|grep -vE 'Filesystem|tmpfs|cdrom'|awk '{print $5 " " $1}')"
166
167 jh_disk_use=$(echo $jh_disk|awk '{print $1}'|cut -d '%' -f1)
168
169 jh_disk_partition=$(echo $jh_disk|awk '{print $2}')
170
171 #disk log
172
173 disk_worklog='/usr/local/monitor/logs/disk_work_log'
174
175 disk_downlog='/usr/local/monitor/logs/disk_down_log'
176
177 #cpu log
178
179 cpu_worklog='/usr/local/monitor/logs/cpu_work_log'
180
181 cpu_downlog='/usr/local/monitor/logs/cpu_down_log'
182
183 #notification mail
184
185 email='denglei@ctfo.com'
186
187 #monitor
188
189 if [ ! -d "$loghere" ];then
190
191 mkdir $loghere
192
193 fi
194
195 #monitor
196
197 #jiaohuan check
198
199 if [ $pas -ge 1 ];then
200
201 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: pas Monitor_Server: $monitor_name is working" >> $worklog-$day
202
203 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','pas','working',now())";
204
205 else
206
207 /usr/local/lbs/bin4.0.7.7/pas -daemon
208
209 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: pas Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: pas was a problem" $email
210
211 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: pas Monitor_Server: $montior_name is down" >> $downlog-$day
212
213 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','pas','downing',now())";
214
215 fi
216
217 if [ $ppas -ge 1 ];then
218
219 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: ppas Monitor_Server: $monitor_name is working" >> $worklog-$day
220
221 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','ppas','working',now())";
222
223 else
224
225 /usr/local/lbs/bin4.0.7.7/ppas -daemon
226
227 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: ppas Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: ppas was a problem" $email
228
229 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: ppas Monitor_Server: $montior_name is down" >> $downlog-$day
230
231 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','ppas','downing',now())";
232
233 fi
234
235 if [ $mas -ge 1 ];then
236
237 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: mas Monitor_Server: $monitor_name is working" >> $worklog-$day
238
239 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','mas','working',now())";
240
241 else
242
243 /usr/local/lbs/bin4.0.7.7/mas -daemon
244
245 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: mas Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: mas was a problem" $email
246
247 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: mas Monitor_Server: $montior_name is down" >> $downlog-$day
248
249 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','mas','downing',now())";
250
251 fi
252
253 if [ $mmas -ge 1 ];then
254
255 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: mmas Monitor_Server: $monitor_name is working" >> $worklog-$day
256
257 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','mmas','working',now())";
258
259 else
260
261 /usr/local/lbs/bin4.0.7.7/mmas -daemon
262
263 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: mmas Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: mmas was a problem" $email
264
265 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: mmas Monitor_Server: $montior_name is down" >> $downlog-$day
266
267 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','mmas','downing',now())";
268
269 fi
270
271 if [ $cas -ge 1 ];then
272
273 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: cas Monitor_Server: $monitor_name is working" >> $worklog-$day
274
275 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','cas','working',now())";
276
277 else
278
279 /usr/local/lbs/bin4.0.7.7/cas -daemon
280
281 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: cas Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: cas was a problem" $email
282
283 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: cas Monitor_Server: $montior_name is down" >> $downlog-$day
284
285 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','cas','downing',now())";
286
287 fi
288
289 #check cpu_idle
290
291 if [ $jh_cpu -ge $alert_cpu ];then
292
293 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: cpu_idle Monitor_Server: $monitor_name Cpu_use: $jh_cpu"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: cpu_use was Exceed Threshold value: 80%" $email
294
295 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: cpu_idle Monitor_Server: $monitor_name Cpu_use: $jh_cpu" >> $cpu_downlog-$day
296
297 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $cpu_table values ('','$here','$jh_name','$jh_ip','$monitor_name','cpu_use','$alert_cpu','$jh_cpu','abnormal',now())";
298
299 else
300
301 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: cpu_idle Monitor_Server: $monitor_name Cpu_use: $jh_cpu" >> $cpu_worklog-$day
302
303 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $cpu_table values ('','$here','$jh_name','$jh_ip','$monitor_name','cpu_use','$alert_cpu','$jh_cpu','normal',now())";
304
305 fi
306
307 #check memory
308
309 if [ $jh_mem -le $alert_mem ];then
310
311 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: memory Monitor_Server: $monitor_name Free_mem: $jh_mem"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: memory was Exceed Threshold value" $email
312
313 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: memory Monitor_Server: $monitor_name Free_mem: $jh_mem" >> $memory_downlog-$day
314
315 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$jh_name','$jh_ip','$monitor_name','memory','$alert_mem','$jh_mem','abnormal',now())";
316
317 else
318
319 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: memory Monitor_Server: $monitor_name Free_mem: $jh_mem" >> $memory_worklog-$day
320
321 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$jh_name','$jh_ip','$monitor_name','memory','$alert_mem','$jh_mem','normal',now())";
322
323 fi
324
325 #check swap
326
327 if [ $jh_swap -gt $alert_swap ];then
328
329 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: swap Monitor_Server: $monitor_name Swap_jh: $jh_swap"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: swap Ip: $jh_ip was Exceed Threshold value" $email
330
331 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: swap Monitor_Server: $monitor_name Swap_jh: $jh_swap" >> $memory_downlog-$day
332
333 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$jh_name','$jh_ip','$monitor_name','swap','$alert_swap','$jh_swap','abnormal',now())";
334
335 else
336
337 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: swap Monitor_Server: $monitor_name Swap_jh: $jh_swap" >> $memory_worklog-$day
338
339 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$jh_name','$jh_ip','$monitor_name','swap','$alert_swap','$jh_swap','normal',now())";
340
341 fi
342
343 #check load_15
344
345 if [ $jh_load -ge $alert_load ];then
346
347 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: load_15 Monitor_Server: $monitor_name Load_use: $jh_load_15"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: load_15 Ip: $jh_ip was Exceed Threshold value" $email
348
349 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: load_15 Monitor_Server: $monitor_name Load_use: $jh_load_15" >> $load_downlog-$day
350
351 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $load_table values ('','$here','$jh_name','$jh_ip','$monitor_name','load_15','$alert_load','$jh_load_15','abnormal',now())";
352
353 else
354
355 echo "$now ShengFen: $here Server: $server Ip: $ip Service: load Monitor_Server: $monitor_name Load_use: $jh_load_15" >> $load_worklog-$day
356
357 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $load_table values ('','$here','$jh_name','$jh_ip','$monitor_name','load_15','$alert_load','$jh_load_15','normal',now())";
358
359 fi
360
361 #check io_idle
362
363 if [ $jh_io_idle -ge $alert_io ];then
364
365 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: io_idle Monitor_Server: $monitor_name Io_use: $jh_io_idle"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: io_use was Exceed Threshold value: 80%" $email
366
367 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: io_idle Monitor_Server: $monitor_name Io_use: $jh_io_idle" >> $io_downlog-$day
368
369 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $io_table values ('','$here','$jh_name','$jh_ip','$monitor_name','io_use','$alert_io','$jh_io_idle','abnormal',now())";
370
371 else
372
373 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: io_idle Monitor_Server: $monitor_name Io_use: $jh_io_idle" >> $io_worklog-$day
374
375 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $io_table values ('','$here','$jh_name','$jh_ip','$monitor_name','io_use','$alert_io','$jh_io_idle','normal',now())";
376
377 fi
378
379 #check hareware error info
380
381 if [ $jh_hardware_error -gt 0 ];then
382
383 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: hardware_error Monitor_Server: $monitor_name Error: $jh_info_error"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: hardware_error were some hardware imformation error" $email
384
385 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: hardware_error Monitor_Server: $monitor_name Error: $jh_info_error" >> $hard_downlog-$day
386
387 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $hardware_table values ('','$here','$jh_name','$jh_ip','$monitor_name','hardware_error','0','$jh_hardware_error','abnormal',now())";
388
389 else
390
391 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: hardware_error Monitor_Server: $monitor_name Error: Nothing" >> $hard_worklog-$day
392
393 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $hardware_table values ('','$here','$jh_name','$jh_ip','$monitor_name','hardware_error','0','$jh_hardware_error','normal',now())";
394
395 fi
396
397 #check message error
398
399 if [ $jh_message_error_count -ge 1 ];then
400
401 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: message_error Monitor_Server: $monitor_name Message_error: $jh_message_error"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: message_error were some message imformation error" $email
402
403 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: message_error Monitor_Server: $monitor_name Message_error: $jh_message_error" >> $message_downlog-$day
404
405 /usr/bin/mysql-h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $message_table values ('','$here','$jh_name','$jh_ip','$monitor_name','message_error','1','$jh_message_error_count','abnormal',now())";
406
407 else
408
409 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: message_error Monitor_Server: $monitor_name Message_error: Nothing" >> $message_worklog-$day
410
411 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $message_table values ('','$here','$jh_name','$jh_ip','$monitor_name','message_error','1','$jh_message_error_count','normal',now())";
412
413 fi
414
415 #check user
416
417 if [ $jh_user_count -ge 3 ];then
418
419 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: user Monitor_Server: $monitor_name User: $jh_user_info"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: user was Exceed Threshold value: 3" $email
420
421 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: user Monitor_Server: $monitor_name User: $jh_user_info" >> $user_downlog-$day
422
423 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $user_table values ('','$here','$jh_name','$jh_ip','$monitor_name','user','3','$jh_user_count','abnormal',now())";
424
425 else
426
427 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: user Monitor_Server: $monitor_name User: normal" >> $user_worklog-$day
428
429 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $user_table values ('','$here','$jh_name','$jh_ip','$monitor_name','user','3','$jh_user_count','normal',now())";
430
431 fi
432
433 #check disk
434
435 if [ $jh_disk_use -ge $alert_disk ];then
436
437 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: disk_use Monitor_Server: $monitor_name Disk_use: $jh_disk_partition ($jh_disk_use%)"|/bin/mail -s "Warning!!! $here Server: $jh_name Service: disk_use was Exceed Threshold value : $alert_disk% " $email
438
439 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: disk_use Monitor_Server: $monitor_name Disk_use: $jh_disk_partion ($jh_disk_use%)" >> $disk_downlog-$day
440
441 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $disk_table values ('','$here','$jh_name','$jh_ip','$monitor_name','disk_use','$alert_disk','$jh_disk_partition','$jh_disk_use','abnormal',now())";
442
443 else
444
445 echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: disk_use Monitor_Server: $monitor_name Disk_use: $jh_disk_partition ($jh_disk_use%)" >> $disk_worklog-$day
446
447 /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $disk_table values ('','$here','$jh_name','$jh_ip','$monitor_name','disk_use','$alert_disk','$jh_disk_partition','$jh_disk_use','normal',now())";
448
449 fi
450
451
452
下一篇文章地址:
运维自动化之使用PHP+MYSQL+SHELL打造私有监控系统(三)