Esempio n. 1
0
    def run(self):
        server_list = self.get_server_list()
        self.log("StatServerDate start %s" % get_time())

        if self.server_id is None:
            statServerDatas = StatServerDataCountry.query(
                condition="stat_date ='%s'" % self.date)
        else:
            statServerDatas = StatServerDataCountry.query(
                condition="stat_date ='%s' and server_id = '%s' " %
                (self.date, self.server_id))
        if not statServerDatas:
            for server in server_list:
                try:
                    if server.server_status == 100:
                        continue
                    countries = self.getServerCountryCode(server)
                    if countries:
                        for country in countries:
                            self.stat(server, self.date, country['idfa'])
                except Exception, ex:
                    self.log("server_name[%s] error" % server.server_name)
                    self.log(ex)

            self.log("StatServerDate end %s" % get_time())
 def stat(self,server):
     self.log("LiuCunServerData start %s,server:[%s]" % (get_time(),server.server_name))
     values = {}
     days = {'one_user':0,'two_user':1,'three_user':3,'four_user':4,'five_user':5,'six_user':6,'seven_user':7,'fivteen_user':15,'thirty_user':30}
     values['server_id'] = server.server_id
     values['server_name'] = server.server_name
     open_time = server.open_time
     con= get_conn(server_util.str_to_dbconfig(server.db_connect))
     for k,v in days.iteritems():
         temp_date = get_datetime_str_by_day(open_time,v,"%Y-%m-%d")
         values[k] = self.stat_login_user(temp_date,con,get_datetime_str_by_day(open_time,0,"%Y-%m-%d"))
             
     statLiucunData = StatLiucunData()
     one_user = values['one_user']
     for k, v in values.iteritems():
         if k == 'one_user' or k == 'server_id' or k == 'server_name':
             setattr(statLiucunData, k, v)
         else:
             value = 0
             if one_user != 0 and v != 0:
                 value = round(v/float(one_user),5)*100
                 setattr(statLiucunData, k, value)
             else:
                 setattr(statLiucunData, k, value)
     statLiucunData.persist()
Esempio n. 3
0
 def stat(self,server,open_time):
     self.log("LiuCunServerData start %s,server:[%s]" % (get_time(),server.server_name))
     values = {}
     days = {'one_user':0,'two_user':1,'three_user':3,'four_user':4,'five_user':5,'six_user':6,'seven_user':7,'fivteen_user':15,'thirty_user':30}
     values['server_id'] = server.server_id
     values['server_name'] = server.server_name
     con= get_conn(server_util.str_to_dbconfig(server.db_connect))
     for k,v in days.iteritems():
         temp_date = get_datetime_str_by_day(open_time,v,"%Y-%m-%d")
         values[k] = self.stat_login_user(temp_date,con,get_datetime_str_by_day(open_time,0,"%Y-%m-%d"))
            
     statLiucunData = StatLiucunDataDate()
     one_user = values['one_user']
     for k, v in values.iteritems():
         if k == 'one_user' or k == 'server_id' or k == 'server_name':
             setattr(statLiucunData, k, v)
         else:
             value = 0
             if one_user != 0 and v != 0:
                 value = round(v/float(one_user),5)*100
                 setattr(statLiucunData, k, value)
             else:
                 setattr(statLiucunData, k, value)
     statLiucunData.data_date=datetime_to_string(open_time)
     statLiucunData.persist()
Esempio n. 4
0
    def run(self):
        server_list = self.get_server_list()
        self.log("StatServerDate start %s" % get_time())
        
        if self.server_id is None:
            statServerDatas = StatServerData.query(condition="stat_date ='%s'" % self.date)
        else:
            statServerDatas = StatServerData.query(condition="stat_date ='%s' and server_id = '%s' " % (self.date, self.server_id))

        if not statServerDatas:
            for server in server_list:
                try:
                    self.stat(server,self.date)
                except Exception,ex:
                    self.log("server_name[%s] error" % server.server_name)
                    self.log(ex)
                
            self.log("StatServerDate end %s" % get_time())
Esempio n. 5
0
    def run(self):
        server_list = self.get_server_list()
        self.log("StatServerDate start %s" % get_time())

        if self.server_id is None:
            statServerDatas = StatServerData.query(
                condition="stat_date ='%s'" % self.date)
        else:
            statServerDatas = StatServerData.query(
                condition="stat_date ='%s' and server_id = '%s' " %
                (self.date, self.server_id))

        if not statServerDatas:
            for server in server_list:
                try:
                    self.stat(server, self.date)
                except Exception, ex:
                    self.log("server_name[%s] error" % server.server_name)
                    self.log(ex)

            self.log("StatServerDate end %s" % get_time())
 def run(self):
     server_list = self.get_server_list()
     self.log("StatServerDate start %s" % get_time())
     
     if self.server_id is None:
         statServerDatas = StatServerDataCountry.query(condition="stat_date ='%s'" % self.date)
     else:
         statServerDatas = StatServerDataCountry.query(condition="stat_date ='%s' and server_id = '%s' " % (self.date, self.server_id))
     if not statServerDatas:
         for server in server_list:
             try:
                 if server.server_status==100:
                     continue
                 countries = self.getServerCountryCode(server)
                 if countries :
                     for country in countries:
                         self.stat(server, self.date, country['idfa'])
             except Exception,ex:
                 self.log("server_name[%s] error" % server.server_name)
                 self.log(ex)
             
         self.log("StatServerDate end %s" % get_time())
Esempio n. 7
0
def main():
    """main"""
    servers = server_business.get_all_server_list()
    date = get_time()
    for server in servers:
        if not server:
            continue
        redis_cfg = str_to_redisconfig(server.redis_connect)
        logging.debug("host[%s], port[%s]" %
                      (redis_cfg['host'], redis_cfg['port']))
        client = redis.Redis(host=redis_cfg['host'], port=redis_cfg['port'])
        s = client.get("ldsg_local_system_status_key")
        if s:
            info = json.loads(s)
            online = info["connCount"]
            cursor = connection.cursor()
            try:
                cursor.execute(
                    "INSERT INTO stat_online(online, stat_time,server_id) VALUES(%d, '%s','%s')"
                    % (online, date, server.server_id))
            finally:
                connection.close()