You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
754 B
27 lines
754 B
import os
|
|
import json
|
|
|
|
log_file_path = os.getenv("ACCESS_LOG_PATH", '/data/ww/py_sys_monitor/info/access_log')
|
|
|
|
def get_request_info(page_index=1, page_size=10):
|
|
if page_index <= 0:
|
|
page_index = 1
|
|
|
|
if page_size <=0 or page_size > 100:
|
|
page_size = 10
|
|
|
|
request_info = []
|
|
with open(log_file_path, 'r') as f:
|
|
lines = f.readlines()
|
|
|
|
total_records = len(lines)
|
|
# start = (page_index - 1) * page_size
|
|
start = total_records - 1 - page_index * page_size
|
|
end = start + page_size
|
|
|
|
if start < total_records:
|
|
for line in lines[start:end]:
|
|
record = json.loads(line.strip())
|
|
request_info.append(record)
|
|
|
|
return {"request_info": request_info, "total": total_records} |