def getSenderCallback(self): resp = {} resp["total"] = self.getRedisValue("totalCallback") resp["today"] = self.getRedisValue(util.current_date() + ":totalCallback") resp["yesterday"] = self.getRedisValue( util.current_date(-1) + ":totalCallback") resp["hour"] = self.getRedisValue(util.current_hour() + ":totalCallback") resp["hour-1"] = self.getRedisValue( util.current_hour(-1) + ":totalCallback") return resp
def logDelayTime(resp): try: pipe = resp['trespassing_field']['pipe'] delay = time.time() - resp['trespassing_field']['_log_id'] prefix = util.current_hour() stat.incrRedis("cspub:delay:{}:{}".format(prefix, pipe), delay / 1000.0, expire=86400) stat.incrRedis("cspub:callback:{}:{}".format(prefix, pipe), 1, expire=86400) log.notice("logDelayTime pipe: {}, delay: {}".format(pipe, delay)) except: pass
def getCspubSpiderSent(self): keys = redistool.redisServ.keys("cspub:sent:{}:*".format( util.current_hour())) if len(keys) == 0: return {} resp = {} for k in keys: try: sent = redistool.redisServ.get(k) back = redistool.redisServ.get( k.replace(":sent:", ":callback:")) avgDelay = "sent:{}, back:{}".format(sent, back) newKey = k.split(":")[2:4] resp[":".join(newKey)] = avgDelay except Exception as e: resp[k] = str(e) return resp
def getCspubSpiderDelay(self): keys = redistool.redisServ.keys("cspub:delay:" + util.current_hour() + ":*") if len(keys) == 0: return {} resp = {} for k in keys: try: avgDelay = float(redistool.redisServ.get(k)) / float( redistool.redisServ.get(k.replace(":delay:", ":callback:"))) avgDelay = str(avgDelay * 1000) + "(s)" newKey = k.split(":")[2:4] resp[":".join(newKey)] = avgDelay except Exception as e: resp[k] = str(e) return resp
def patch(json_data, bypass=None, urlPack=None, destHost=None, destPort=None): json_data['user'] = '******' json_data['user_key'] = 'midway_island' if destHost is None: destHost = random.choice(CALLBACK_HOST) if destPort is None: destPort = CALLBACK_PORT json_data['dest_host'] = destHost json_data['dest_port'] = destPort if urlPack is not None: if 0 <= urlPack.priority <= 32: json_data['priority'] = urlPack.priority else: json_data['priority'] = urlPack.getKey('priority', 0) if bypass is not None and type(bypass) == dict: bypass['_log_id'] = time.time() bypass['_cb'] = destHost + ":" + str(destPort) json_data['trespassing_field'] = mcpack.OBJ(bypass) currentHour = util.current_hour() stat.incrRedis("cspub:sent:{}:{}".format(currentHour, bypass.get('pipe')), expire=86400)
def getSaverError(self): keys = redistool.redisServ.keys("saver:status-v2:{}:*".format( util.current_hour())) if len(keys) == 0: return {} return {key: redistool.redisServ.get(key) for key in keys}
def incrSenderCallback(self): self.incrRedis("totalCallback") self.incrRedis(util.current_date() + ":totalCallback") self.incrRedis(util.current_hour() + ":totalCallback")
def incrPipeSaverStatus(pipeName, status): prefix = util.current_hour() stat.incrRedis("saver:status-v2:{}:{}:{}".format(prefix, pipeName, status), 1, 86400)