Commit d2ed3cc3 by 陈森彬

add spider expired rate

parent 5b58ea3b
Showing with 16 additions and 0 deletions
......@@ -3,10 +3,13 @@
import sys
import time
import pymongo
import json
from utils.glo import Glo
from urllib.parse import quote_plus
from utils.mysql import MySqlOperator
mysql_db = MySqlOperator('dashboard')
glo = Glo()
MG_HOST_SET = {
......@@ -79,6 +82,7 @@ class MongoOperator:
msg = '数据过期率监控预警 过去3小时内:\n'
demo = '平台:{} 数据过期率为{:.2f}%'
msgs = []
expired_dict = {}
for plat in self.colls:
coll = self.db[plat]
ts = self.get_unexpired_time(plat)
......@@ -99,9 +103,12 @@ class MongoOperator:
msg_line = demo.format(plat, rate)
msgs.append(msg_line)
msg += msg_line + '\n'
expired_dict[plat] = "{:.2f}".format(rate)
else:
print(plat, expired, total)
if msgs:
ts = int(time.time())
mysql_db.insert_expired_data(ts, json.dumps(expired_dict))
return msg
else:
return
......
......@@ -58,3 +58,11 @@ class MySqlOperator:
"""
cursor.execute(sql, (s, u))
self.db.commit()
def insert_expired_data(self,time_stamp,platform_data):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_spider_expired_rate(time_stamp, platform_data) VALUES (%s, %s)
"""
cursor.execute(sql,(time_stamp,platform_data))
self.db.commit()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment