mirror of https://gitee.com/anolis/sysom.git
54 lines
1.6 KiB
Python
Executable File
54 lines
1.6 KiB
Python
Executable File
#!/usr/bin/python3
|
|
# coding=utf-8
|
|
import sys
|
|
import json
|
|
|
|
|
|
def iosdiagJoinData(raw):
|
|
postprocess_result = {
|
|
"code": 0,
|
|
"err_msg": "",
|
|
"result": {}
|
|
}
|
|
if raw.startswith('fail'):
|
|
postprocess_result["code"] = 1
|
|
postprocess_result["err_msg"] = f"Diagnosis failed:\n{raw}"
|
|
print(json.dumps(postprocess_result, indent=4))
|
|
return
|
|
|
|
raw = raw.strip()
|
|
|
|
if 'summary' not in raw:
|
|
data = {"status": "success", "IO timeout": "false"}
|
|
else:
|
|
data = {"status": "success", "IO timeout": "true", "stat": [], "seq": []}
|
|
for s in raw.split('\n'):
|
|
obj = json.loads(s)
|
|
if "percent" in str(obj):
|
|
data['stat'] = obj['summary']
|
|
else:
|
|
data["seq"] = obj['summary']
|
|
for diskIdx in range(len(list(data["seq"]))):
|
|
seq = data["seq"][diskIdx]
|
|
for idx in range(len(list(seq["slow ios"]))-1, 0, -1):
|
|
if seq["slow ios"][idx]["time"] == seq["slow ios"][idx-1]["time"]:
|
|
if seq["slow ios"][idx]["totaldelay"] <= seq["slow ios"][idx-1]["totaldelay"]:
|
|
del seq["slow ios"][idx]
|
|
else:
|
|
del seq["slow ios"][idx-1]
|
|
postprocess_result["result"] = data
|
|
s = json.dumps(postprocess_result, indent=4)
|
|
print(s)
|
|
|
|
|
|
def extract_params():
|
|
path, res, task_id = sys.argv[1], "", sys.argv[2]
|
|
with open(path, 'r') as tmp:
|
|
res = tmp.read()
|
|
return res, task_id
|
|
|
|
|
|
if __name__ == "__main__":
|
|
res, _ = extract_params()
|
|
iosdiagJoinData(res)
|