print('Cannot found %s in config_huawei.json file.' % monitor) exit(1) will_moniter.append([monitor, spiders[monitor]]) return will_moniter if __name__ == '__main__': if len(sys.argv) == 2: config_file = sys.argv[1] elif len(sys.argv) == 1: config_file = './config_huawei.json' else: print("Example: \n" " python3 monitor.py\n" " python3 monitor.py ./config_huawei.json") exit(1) Config.config_file = config_file spiders = get_monitors() hosts = Config.get_hosts() source_dir = Config.get_sources_dir() while True: for spider in spiders: dprint("check spider: %s" % spider[0]) for host in hosts: dprint("...check on host: %s" % host) check_and_start(host, source_dir, spider[0], spider[1]) print("") print("wait 120 seconds...\n") time.sleep(120)
from common import rcmd, Config def check_spider(host, spider_cmd): cmd = "ps -ef|grep -vE 'grep|monitor.py|check.py'|grep '%s'" % spider_cmd return rcmd(host, cmd).read() if __name__ == "__main__": print(sys.argv) if len(sys.argv) == 3: config_file = sys.argv[1] spider = sys.argv[2] elif len(sys.argv) == 2: config_file = './config.json' spider = sys.argv[1] else: print("Example: \n" " python3 check.py jingdong\n" " python3 check.py ./config.json jingdong") exit(1) Config.config_file = config_file spider_cmd = Config.get_spiders(spider) if spider_cmd is None: print("Cannot found '%s' in %s." % (spider, config_file)) exit(1) for host in Config.get_hosts(): print("On host %s" % host) print(check_spider(host, spider_cmd))