/
camelbell.py
93 lines (77 loc) · 2.7 KB
/
camelbell.py
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
#!/bin/env python
#coding:utf-8
import os
import sys
import string
import time
import datetime
import MySQLdb
import logging
import logging.config
logging.config.fileConfig("etc/logger.ini")
logger = logging.getLogger("main")
path='./include'
sys.path.insert(0,path)
import functions as func
from multiprocessing import Process;
def job_run(script_name,times=3600):
logger.info("%s check per %s seconds." % (script_name, times))
while True:
os.system("python "+script_name+".py")
time.sleep(int(times))
def main():
logger.info("camelbell controller start.")
monitor = str(func.get_option('monitor'))
monitor_mysql = str(func.get_option('monitor_mysql'))
monitor_mysql_bigtable = str(func.get_option('monitor_mysql_bigtable'))
monitor_mongodb = str(func.get_option('monitor_mongodb'))
monitor_oracle = str(func.get_option('monitor_oracle'))
monitor_redis = str(func.get_option('monitor_redis'))
monitor_os = str(func.get_option('monitor_os'))
alarm = str(func.get_option('alarm'))
frequency_monitor = func.get_option('frequency_monitor')
frequency_monitor_alarm = int(frequency_monitor)+10
frequency_sync_os = func.get_option('frequency_sync_os')
joblist = []
if monitor=="1":
#
logger.info("[BBQ] sync_os")
job = Process(target = job_run, args = ('sync_os', frequency_sync_os))
joblist.append(job)
job.start()
logger.info("[BBQ]monitor mysql %s" % (monitor_mysql))
if monitor_mysql=="1":
job = Process(target = job_run, args = ('check_mysql',frequency_monitor))
joblist.append(job)
job.start()
if monitor_oracle=="1":
time.sleep(3)
job = Process(target = job_run, args = ('check_oracle',frequency_monitor))
joblist.append(job)
job.start()
if monitor_mongodb=="1":
time.sleep(3)
job = Process(target = job_run, args = ('check_mongodb',frequency_monitor))
joblist.append(job)
job.start()
if monitor_redis=="1":
time.sleep(3)
job = Process(target = job_run, args = ('check_redis',frequency_monitor))
joblist.append(job)
job.start()
if monitor_os=="1":
time.sleep(3)
freq_os = 60 * 5
job = Process(target = job_run, args = ('check_os',freq_os))
joblist.append(job)
job.start()
if alarm=="1":
time.sleep(3)
job = Process(target = job_run, args = ('alarm',frequency_monitor_alarm))
joblist.append(job)
job.start()
for job in joblist:
job.join();
logger.info("camelbell controller finished.")
if __name__ == '__main__':
main()