fix detect anomal task bug

Change-Id: Ib6a081276bb3665cd1743d375980c5a9111bc9f2
This commit is contained in:
inspurericzhang 2023-08-01 08:13:31 +00:00
parent 22c43afb1c
commit 4d341e44bd
3 changed files with 14 additions and 12 deletions

View File

@ -125,13 +125,13 @@ class AnomalyDetectSql(object):
session.add(rule)
def get_record_list(self, params):
title = params["title"]
module = params["module"]
ltype = params["log_type"]
start_time = params["start_time"]
end_time = params["end_time"]
page_num = int(params["page_num"])
page_size = int(params["page_size"])
title = params.get("title", None)
module = params.get("module", None)
ltype = params.get("log_type", None)
start_time = params.get("start_time", None)
end_time = params.get("end_time", None)
page_num = int(params.get("page_num", "1"))
page_size = int(params.get("page_size", "10"))
session = get_session()
with session.begin():
@ -152,7 +152,7 @@ class AnomalyDetectSql(object):
t = time.strftime('%Y-%m-%d %H:%M:%S', lt)
query = query.filter(models.AnomalyRecords.create_time <= t)
query = query.limit(page_size).offset((page_num - 1) * page_num)
query = query.limit(page_size).offset((page_num - 1) * page_size)
res = query.all()
return res

View File

@ -37,10 +37,10 @@ class AnomalyDetectTask(object):
last_timestamp = self.config_api.get_config("last_detect_timestamp")
if last_timestamp:
last_timestamp = int(last_timestamp)
if now_timestamp - last_timestamp > 3000000:
last_timestamp = last_timestamp - 3000000
if now_timestamp - last_timestamp > 300:
last_timestamp = last_timestamp - 300
else:
last_timestamp = now_timestamp - 6000000
last_timestamp = now_timestamp - 60
self.anomaly_detect_logs("flog", last_timestamp, now_timestamp)
self.anomaly_detect_logs("slog", last_timestamp, now_timestamp)

View File

@ -39,7 +39,9 @@ class DeleteAnomalyRecordTask(object):
LOG.info(_LI("anomaly record save days: %s"), len_d)
try:
params = {}
params["start_time"] = str(time.time() - 86400 * int(len_d))
params["page_num"] = "1"
params["page_size"] = "999999"
params["end_time"] = str(int(time.time()) - 86400 * int(len_d))
records = self.anomaly_api.get_record_list(params)
for r in records:
self.anomaly_api.delete_record(r.id)