我正在尝试开发一个脚本,该脚本将从Linux读取top.log文件,并隔离令人讨厌的特定进程,并为您提供发生这种情况的时间和日期。 目前,我正在尝试使用以下数据填充JSON:
def jsonify(cleanlist: list):
regex = re.compile(r'.*mysqld$')
date_regex = re.compile(r'^top -.*$ ')
for sub in cleanlist:
for line in sub:
d = re.match(date_regex, line)
m = re.match(regex, line)
if d:
data['date'] = line
elif m:
splt = line.split(' ')
splt = list(filter(None, splt))
data[splt[11]] = splt[8]
json_data = json.dumps(data)
print(json_data)
但是,当我打印json数据时,我只会得到进程和CPU%键值对。 可能做的作业不正确,但是我想念什么?
感谢所有提前反馈。