Example #1
0
 def handle(self):
     redis_sub = self.redis.subscribe()
     while True:
         msg = redis_sub.parse_response()
         print 'recv:',msg
         action_process.action_process(self,msg)
         print '---waiting for new msg ---'
         for host,val in self.hosts['hosts'].items():
             print host,val
Example #2
0
 def start(self):
     self.monitor_data_processing()
     while True:
         client_data = json.loads(self.sub.parse_response()[2])
         client_data['last_update'] = time.time()
         #print client_data
         business_type = client_data.keys()[0]
         action_process.action_process(self,business_type,client_data)
         '''
    def handler(self):
        redis_sub = self.redis_service.sub()
        while True:
            msg = redis_sub.parse_response()
            print "rcv:",msg
            action_process.action_process(self,msg)

            print "waiting for new msg"
            for host,val in self.hosts["hosts"].items():
                print host ,val
Example #4
0
 def handle(self):
     redis_sub = self.redis.subscribe()
     #redis_sub.parse_response()
     while True:
         msg = redis_sub.parse_response()
         print 'recv:',msg
         action_process.action_process(self,msg)#把self传过去的好处是,在另一个模块中也可以调用这个模块中已经生成的实例,而不需要再重新实例化出一个新的实例,相当于把实例传过去
         print '---waiting for new msg---'
         
         for host,val in self.hosts['hosts'].items():
             print host,val
Example #5
0
    def handle(self):
        redis_sub = self.redis.subscribe()
        #redis_sub.parse_response()
        while True:
            msg = redis_sub.parse_response()
            #收到消息就打印,没有就堵塞
            print('recv:', msg)
            #收到丢给action_process
            action_process.action_process(self, msg)
            print('-----waiting for new msg------')

            for host, val in self.hosts['hosts'].items():
                print(host, val)
Example #6
0
    def handle(self,msg):
        # print 'recv:',msg
        # print '>> process data:: %s' % pickle.loads(msg)
        data = pickle.loads(msg)
        for k,msg in data.items():
            fun_name = k.split('::')[0]
            time = k.split('::')[1]
            action_process.action_process(self,fun_name,time,msg)
        print '---------waiting for new msg ---------'

        # received data
        for host,val in self.hosts['hosts'].items():
            if val:
                t = threading.Thread(target=self.process,args=[host,val])
                t.start()
            else:
                print '%s host monitor info is null...' %host
Example #7
0
    def handle(self, msg):
        # print 'recv:',msg
        # print '>> process data:: %s' % pickle.loads(msg)
        data = pickle.loads(msg)
        for k, msg in data.items():
            fun_name = k.split('::')[0]
            time = k.split('::')[1]
            action_process.action_process(self, fun_name, time, msg)
        print '---------waiting for new msg ---------'

        # received data
        for host, val in self.hosts['hosts'].items():
            if val:
                t = threading.Thread(target=self.process, args=[host, val])
                t.start()
            else:
                print '%s host monitor info is null...' % host
Example #8
0
    def handle(self):
        redis_sub = self.redis.subscribe()

        value_dic = {}
        for host in self.hosts['hosts'].keys():
            value_dic[host] = {
                'MemUsage': [],
                'iowait': [],
                'idle': [],
                'load1': []
            }  #用来存数据
        print value_dic

        while True:
            msg = redis_sub.parse_response()
            #print 'recv:',msg
            action_process.action_process(
                self,
                msg)  #self是将本实例传给action_process方法,action_process不再需要导入redis
            print '----waiting for new msg ---'

            #received data
            for host, val in self.hosts['hosts'].items():
                if val is not None:
                    #print host, val
                    #get config
                    configs = self.get_config(host)

                    for service_name, val2 in val.items():
                        print "hahaha", configs[service_name]
                        c_time_stamp = val2['time_stamp']
                        data = val2['data']
                        #print "dadada",data

                        time_pass_since_last_recv = time.time() - c_time_stamp
                        #print  "Time pass:"******"\033[41;1m Service %s has no data for %ss\033[0m" % (
                                service_name, time_pass_since_last_recv)
                        else:

                            if 'MemUsage' in data.keys():
                                key = 'MemUsage'
                                key_value = int(data['MemUsage']) * 100 / int(
                                    data['MemTotal'])
                                print key, ": ", key_value
                                value_dic[host][key].append(float(key_value))
                            else:
                                for key in configs[service_name].keys():
                                    key_value = data[key]
                                    print key, ": ", key_value
                                    value_dic[host][key].append(
                                        float(key_value))
                        for key in configs[service_name].keys():
                            if len(value_dic[host][key]) > 5:  #只保留5个数,测试用
                                del value_dic[host][key][0]
                                configs[service_name][key]['func'](
                                    configs[service_name][key]['warning'],
                                    configs[service_name][key]['operator'],
                                    value_dic[host][key][-6:-1])
                            #times = int(configs[service_name][key]['minutes'])*60/
                            print value_dic