sysom1/sysom_server/sysom_diagnosis/service_scripts/iosdiag_latency

53 lines
1.7 KiB
Python
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/python3
# coding=utf-8
import json
import sys
###############################################################################
## 如前端入参是这个:
## {
## "instance":"192.168.1.101",
## "thresh":"1",
## "diag_time":"10"
## "disk":"vda"
## }
## 解析参数方法:
## sysak iosdiag latency -t 1 -T 10 vda
## -t 1 thresh表示要捕获IO耗时超过1ms的IO
## -T 10 diag_time表示诊断10秒后自动退出
## vda disk可以不填不填默认会捕获系统所有磁盘的IO
## 如填写有效盘符则只捕获指定磁盘IO
## 如填写一个无效盘符也会捕获系统所有磁盘的IO
##
###############################################################################
class Param(dict):
def __missing__(self,key):
sys.stderr.write("入参检查失败,没有检查到入参'%s'"%key)
exit(1)
args = Param(json.loads(sys.argv[1]))
result = {}
result['commands'] = []
cmd0 = {}
cmd0['instance'] = args["instance"]
cmd0_arg_t = args.get("thresh","5000")
if int(cmd0_arg_t) < 0:
cmd0_arg_t = 0
cmd0_arg_T = args.get("diag_time","10")
if int(cmd0_arg_T) <= 0:
cmd0_arg_T = 10
cmd0_arg_device = args.get("disk","")
dump_log_cmd = "cat /var/log/sysak/iosdiag/latency/result.log.stat 2>/dev/null;\
echo \"\";cat /var/log/sysak/iosdiag/latency/result.log.seq 2>/dev/null;"
iosdiag_cmd = "sysak -g iosdiag latency -t "+str(cmd0_arg_t)+" -T "+str(cmd0_arg_T)+" "+cmd0_arg_device+" > /dev/null"
print_result_cmd = "if [ \"$?\" = \"0\" ]; then "+\
dump_log_cmd+"else echo \"fail\"; fi"
cmd0['cmd'] = "rm /var/log/sysak/iosdiag/latency/* -f && "+iosdiag_cmd+" && "+print_result_cmd
result['commands'].append(cmd0)
data = json.dumps(result)
print(data)