def ajax_kpi(request): km = [] sym = request.GET.get('kpi', 'default') for jifang in uniform.cluster(): if sym == 'machine': kpi_element = list( KpiMachine.objects.filter( cluster=jifang).order_by("-stat_time")[0:1]) kpi_element[0].latest_24 = str("%.2f" % kpi_element[0].latest_24) kpi_element[0].day_30 = str("%.2f" % kpi_element[0].day_30) kpi_element[0].latest_30 = str("%.2f" % kpi_element[0].latest_30) else: kpi_element = list( KpiInstance.objects.filter( cluster=jifang).order_by("-stat_time")[0:1]) kpi_element[0].per_24 = str("%.2f" % kpi_element[0].per_24) kpi_element[0].per_day_30 = str("%.2f" % kpi_element[0].per_day_30) kpi_element[0].per_latest_30 = str("%.2f" % kpi_element[0].per_latest_30) km.append(kpi_element) kpi = {} cl = uniform.cluster() if sym == 'machine': for x in cl: id = cl.index(x) kpi[x] = [ km[id][0].latest_24, km[id][0].day_30, km[id][0].latest_30 ] else: for x in cl: id = cl.index(x) kpi[x] = [ km[id][0].per_24, km[id][0].per_day_30, km[id][0].per_latest_30 ] return JsonResponse(kpi)
def get_core(): global PATH core_map = {} for x in uniform.cluster(): core_map[x] = {} if os.path.exists(PATH + 'version_info'): file_version = open(PATH + 'version_info') for line in file_version: line = line.strip('\n') x = line.split() cluster = x[0] shell_pd_rm = x[1] version = x[2] if len(x) < 3: core_map[cluster][shell_pd_rm] = '??' else: core_map[cluster][shell_pd_rm] = version else: for x in uniform.cluster(): core_map[x]['shell'] = '??' core_map[x]['pd'] = '??' core_map[x]['rm'] = '??' file_main = open(PATH + 'main.list') for line in file_main: line = line.strip('\n') x = line.split() cluster = x[0] host = x[1] core_map[cluster]['main'] = host file_backup = open(PATH + 'vice.list') for line in file_backup: line = line.strip('\n') x = line.split() cluster = x[0] host = x[1] core_map[cluster]['backup'] = host file_zk = open(PATH + 'zk.list') for line in file_zk: line = line.strip('\n') x = line.split() cluster = x[0] host = x[1] core_map[cluster]['zk'] = host l = core_map.items() l.sort(sort_cluster) return l
def ajax_new_fault(request): param = request.GET l = uniform.cluster() mi_count = {} for x in l: mi_count[x] = 0 modeln = param.get('new_fault') countn = param.get('new_fault_time') nhours = int(countn) fault_type = param.get('fault_type', 'nothing') if modeln == 'bs_on_ns': instance_fault = list( InstanceFaultNs.objects.order_by("-time", "room", "type")[0:40]) instance_fault_old = list( InstanceFaultNs.objects.order_by( "-time", "room", "type")[40 * nhours:40 * nhours + 40]) else: instance_fault = list( InstanceFault.objects.filter(model=modeln).order_by( "-time", "room", "model", "type")[0:40]) instance_fault_old = list( InstanceFault.objects.filter(model=modeln).order_by( "-time", "room", "model", "type")[40 * nhours:40 * nhours + 40]) new_fault = {} new_fault_total = {} for x in l: new_fault_total[x] = {} new_fault_total[x]['total'] = 0 new_fault_total[x]['total_delta'] = 0 for i in instance_fault: if i.room not in new_fault.keys(): new_fault[i.room] = [] index = instance_fault.index(i) oldnum = instance_fault_old[index].num if len( instance_fault_old) > 0 else 0 deltanum = i.num - oldnum new_fault[i.room].append({ "room": i.room, "type": i.type, "num": i.num, "num_delta": deltanum }) new_fault_total[i.room]["total"] += i.num new_fault_total[i.room]["total_delta"] += deltanum if i.type == fault_type: mi_count[i.room] = i.num new_fault_list = [[], [], [], [], []] for x in l: id = l.index(x) new_fault_list[id] = new_fault[x] map = { 'new_fault_list': new_fault_list, 'new_fault_total': new_fault_total, 'mi_count': mi_count } return JsonResponse(map)
def index(request): list_str = get.getdata(request) l = uniform.cluster() mi_count = {} for x in l: mi_count[x] = 0 hours = 24 instance_fault = list(InstanceFaultNs.objects.order_by("-time", "room", "type")[0:40]) instance_fault_old = list(InstanceFaultNs.objects.order_by("-time", "room", "type")[40*hours:40*hours+40]) new_fault = {} new_fault_total = {} for x in l: new_fault_total[x] = {} new_fault_total[x]['total'] = 0 new_fault_total[x]['total_delta'] = 0 for i in instance_fault: if i.room not in new_fault.keys(): new_fault[i.room] = [] index = instance_fault.index(i) oldnum = instance_fault_old[index].num if len(instance_fault_old) > 0 else 0 deltanum = i.num - oldnum new_fault[i.room].append({"room":i.room, "type":i.type, "num":i.num, "num_delta":deltanum}) new_fault_total[i.room]["total"] += i.num new_fault_total[i.room]["total_delta"] += deltanum if i.type == 'dfail': mi_count[i.room] = i.num new_fault_list = [[],[],[],[],[]] for x in l: id = l.index(x) new_fault_list[id] = new_fault[x] kpi_list = [['machine',u'机器 总使用率 平均'],['instance',u'core 实例存活率 95分位']] chart_machine = {"all":u'总使用率', "online":u'标记online率', "hard":u'硬故障率', "soft":u'软故障率', "no_err":u'无故障率', "no_err_use":u'无故障使用率'} chart_machine_list = chart_machine.items() chart_machine_list.sort(get.mcsort) machine_where_list = instance_where_list = ['rate','num'] machine_switch_list = instance_switch_list = ['on','off'] chart_items_list = new_fault_items_list = uniform.module() new_fault_time = [[1,'1h'],[24,'1d']] #history history = get.get_history() for x in history: x[2] = x[2][2:4]+'/'+x[2][4:6]+' '+x[2][-2:]+':00' #kpi km = list_str['kpi_machine'] kpi = [] for i in range(0,5): kpi.append([km[i][0].cluster,km[i][0].stat_time,km[i][0].latest_24,km[i][0].day_30,km[i][0].latest_30]) print get.get_core() infos = {'list_str':list_str,'chart_machine_list':chart_machine_list, 'chart_items_list':chart_items_list, 'core_info':get.get_core(),'history':history,'kpi':kpi,'new_fault_list':new_fault_list, 'mi_count':mi_count,'new_fault_items_list':new_fault_items_list,'new_fault_total':new_fault_total, 'kpi_list':kpi_list,'machine_where_list':machine_where_list,'machine_switch_list':machine_switch_list, 'instance_where_list':instance_where_list,'instance_switch_list':instance_switch_list,'city':uniform.cluster(), 'zk_map':get.get_zk_info(),'new_fault_time':new_fault_time } return render_to_response('index.html', infos)
def ajax_detail_base(request): param = request.GET cd_base = param.get('cd_base') btl = cd_base.split('-') base_time = btl[0][-2:] + btl[1] + btl[2] consistency_header = {} l = uniform.cluster() for x in l: consistency_header[x] = [] for cc in l: path_base = "/home/work/data_zk_consistent/" + base_time + "/" + cc + "_base_bs_header" bo = '' if os.path.exists(path_base): base_open = open(path_base) bo = base_open.read() consistency_header[cc].append(bo) return JsonResponse(consistency_header)
def ajax_detail_ltr(request): param = request.GET cd_ltr = param.get('cd_ltr') ltl = cd_ltr.split('-') ltr_time = ltl[0][-2:] + ltl[1] + ltl[2] consistency_header = {} l = uniform.cluster() for x in l: consistency_header[x] = [] for cc in l: path_ltr = "/home/work/data_zk_consistent/" + ltr_time + "/" + cc + "_ltr_ranksvm_model_chn_header" lo = '' if os.path.exists(path_ltr): ltr_open = open(path_ltr) lo = ltr_open.read() consistency_header[cc].append(lo) return JsonResponse(consistency_header)
def ajax_detail_package(request): param = request.GET cd_package = param.get('cd_package') ptl = cd_package.split('-') package_time = ptl[0][-2:] + ptl[1] + ptl[2] consistency_header = {} l = uniform.cluster() for x in l: consistency_header[x] = [] for cc in l: path_date = "/home/work/data_zk_consistent/" + package_time + "/" + cc + "_package_date_source_header" do = '' if os.path.exists(path_date): date_open = open(path_date) do = date_open.read() consistency_header[cc].append(do) return JsonResponse(consistency_header)
def getdata(request): list_str = { "machine": [], "instance": [], "sym1": '%', "sym2": '%', "kpi_machine": [], "kpi_instance": [] } l = uniform.cluster() for x in l: ret = getinfo(request, x) labelm = 'machine' + str(l.index(x) + 1) labeli = 'instance' + str(l.index(x) + 1) machine = [labelm, ret[4], ret[0], ret[1]] instance = [labeli, ret[5], ret[2], ret[3]] list_str['machine'].append(machine) list_str['instance'].append(instance) list_str['kpi_machine'].append(ret[6]) list_str['kpi_instance'].append(ret[7]) return list_str
def show(request, room): dl = get_detail.getinfo_detail(request, room) which_items_list = which1_items_list = which2_items_list = [[ 'rate', u'±ÈÂÊ' ], ['num', u'ÊýÁ¿']] daylist = get_detail.daylist() weeklist = get_detail.weeklist() monthlist = get_detail.monthlist() #chart_machine_list chart_machine = uniform.mrate_better() chart_machine_list = chart_machine.items() chart_machine_list.sort(get.mcsort) #machine_label_list machine_label = dl[10] #chart_instance_list chart_instance_list = uniform.module() #chart_agent_list chart_agent_list = uniform.agent() # yj_time for x in dl[0]: x.stat = x.stat_time[2:4] + '.' + x.stat_time[4:6] + ' ' + x.stat_time[ -2:] + ':00' strtime = time.strftime('%Y-%m-%d', time.localtime()) #consistency_time ptl = strtime.split('-') package_time = ltr_time = base_time = ptl[0][-2:] + ptl[1] + ptl[2] #consistency_header consistency_header = {} for x in uniform.cluster(): consistency_header[x] = [] for cc in consistency_header.keys(): bo = lo = do = '' path_base = "/home/work/data_zk_consistent/" + base_time + "/" + cc + "_base_bs_header" if os.path.exists(path_base): base_open = open(path_base) bo = base_open.read() path_ltr = "/home/work/data_zk_consistent/" + ltr_time + "/" + cc + "_ltr_ranksvm_model_chn_header" if os.path.exists(path_ltr): ltr_open = open(path_ltr) lo = ltr_open.read() path_date = "/home/work/data_zk_consistent/" + package_time + "/" + cc + "_package_date_source_header" if os.path.exists(path_date): date_open = open(path_date) do = date_open.read() consistency_header[cc].extend([do, lo, bo]) consistency = [['package_date_source', package_time], ['ltr_ranksvm_model_chn', ltr_time], ['base_bs', base_time]] # kpi_machine km = list( KpiMachine.objects.filter(cluster=room).order_by("-stat_time")[0:15]) km.reverse() for x in km: x.stat_time = x.stat_time[4:6] # kpi_instance ki = list( KpiInstance.objects.filter(cluster=room).order_by("-stat_time")[0:15]) ki.reverse() #unused machine um_date = strtime unused_machine = {} l = uniform.cluster_short() for x in l: unused_machine[x] = '' for cluster in l: infile = "/home/work/data_unused_machine/" + um_date + "/02-00/" + cluster + ".analyse_machine_userate.result" umstr = '' if os.path.exists(infile): fin = open(infile).readlines() for x in fin[3:]: x = x.replace('\n', '</br>') x = x.replace(' ', ' ') x = x.replace('\t', ' ') if '(' in x and ')' in x: start = x.index('file: ') end = x.index(')') substr = x[start:end] x = x.replace( substr, "<a href='/um_open?file=" + substr + "' target='_blank'>list</a>") umstr += x unused_machine[cluster] = umstr #date_list mia_date_list = monthlist + weeklist + daylist #info info = { "room": room, 'city': uniform.cluster(), 'which_items_list': which_items_list, 'yj_table': dl[0], 'qsm': dl[1], 'qsi': dl[2], 'chart_machine_list': chart_machine_list, 'chart_instance_list': chart_instance_list, 'which1_items_list': which1_items_list, 'time_mac': dl[3], 'time_ins': dl[4], 'tuple_day_mac': dl[5], 'tuple_day_ins': dl[6], 'daylist': daylist, 'weeklist': weeklist, 'monthlist': monthlist, 'qsa': dl[7], 'time_agent': dl[8], 'tuple_day_agent': dl[9], 'chart_agent_list': chart_agent_list, 'which2_items_list': which2_items_list, 'consistency_header': consistency_header, 'consistency': consistency, 'km': km, 'ki': ki, 'unused_machine': unused_machine, 'cd_package': strtime, 'cd_ltr': strtime, 'cd_base': strtime, 'um_date': um_date, 'machine_label': machine_label, 'mia_date_list': mia_date_list } return render_to_response('detail.html', info)
def ajax_index_machine(request): param = request.GET r = param.get('machine') where0 = param.get('where0') switch = param.get('switch') map = {} for x in uniform.cluster(): map[x] = [] l = uniform.cluster() for jifang in l: machine_today = list( reversed( list( StatMachine.objects.filter( cluster=jifang, label='*all*').order_by("-stat_time")[0:24]))) machine_yes = list( reversed( list( StatMachine.objects.filter( cluster=jifang, label='*all*').order_by("-stat_time")[24:48]))) mt = [] for x in machine_today: rate_map = {'all':x.running_rate,'no_err_use':x.no_err_running_rate,'hard':x.hard_err_rate,'no_err':x.no_err_rate,\ 'online':x.online_rate,'soft':x.soft_err_rate} rate = rate_map[r] if where0 == 'rate': mt.append(rate) else: mt.append(int(round(x.all_machine * rate / 100))) my = [] for x in machine_yes: rate_map = {'all':x.running_rate,'no_err_use':x.no_err_running_rate,'hard':x.hard_err_rate,'no_err':x.no_err_rate,\ 'online':x.online_rate,'soft':x.soft_err_rate} rate = rate_map[r] if where0 == 'rate': my.append(rate) else: my.append(int(round(x.all_machine * rate / 100))) mac_time = [] for t in machine_today: mac_time.append(t.stat_time[-2:]) labelm = 'machine' + str(l.index(jifang) + 1) sym = '%' if where0 == 'rate' else '' machine = [labelm, mac_time, mt, my, sym] map[jifang] = machine if switch == 'on': today_list = yes_list = [] for x in uniform.cluster(): today_list += map[x][2] yes_list += map[x][3] max_today = max(today_list) min_today = min(today_list) max_yes = max(yes_list) min_yes = min(yes_list) mmax = max([max_today, max_yes]) mmin = min([min_today, min_yes]) map['mmax'] = mmax map['mmin'] = mmin return JsonResponse(map)
def ajax_index_instance(request): param = request.GET biaoqian = param.get('chart') where = param.get('where') switch1 = param.get('switch1') map = {} l = uniform.cluster() for x in l: map[x] = [] for jifang in l: if biaoqian == "bs_on_ns": instance_today = list( reversed( list( NsTotal.objects.filter( room=jifang).order_by("-time")[0:24]))) instance_yes = list( reversed( list( NsTotal.objects.filter( room=jifang).order_by("-time")[24:48]))) else: instance_today = list( reversed( list( StatInstance.objects.filter( cluster=jifang, module=biaoqian).order_by("-stat_time")[0:24]))) instance_yes = list( reversed( list( StatInstance.objects.filter( cluster=jifang, module=biaoqian).order_by("-stat_time")[24:48]))) it = [] if biaoqian == "bs_on_ns": for x in instance_today: if where == 'rate': it.append(round(x.live_rate * 100, 2)) else: it.append(x.total) else: for x in instance_today: if where == 'rate': it.append(round(100 - x.live_rate, 2)) else: it.append( int(round(x.all_instance * (100 - x.live_rate) / 100))) iy = [] if biaoqian == "bs_on_ns": for x in instance_yes: if where == 'rate': iy.append(round(x.live_rate * 100, 2)) else: iy.append(x.total) else: for x in instance_yes: if where == 'rate': iy.append(round(100 - x.live_rate, 2)) else: iy.append( int(round(x.all_instance * (100 - x.live_rate) / 100))) ins_time = [] if biaoqian == "bs_on_ns": for t in instance_today: ins_time.append(t.time[-2:]) else: for t in instance_today: ins_time.append(t.stat_time[-2:]) labeli = 'instance' + str(l.index(jifang) + 1) sym = '%' if where == 'rate' else '' instance = [labeli, ins_time, it, iy, sym] map[jifang] = instance if switch1 == 'on': today_list = yes_list = [] for x in uniform.cluster(): today_list += map[x][2] yes_list += map[x][3] max_today = max(today_list) min_today = min(today_list) max_yes = max(yes_list) min_yes = min(yes_list) mmax = max([max_today, max_yes]) mmin = min([min_today, min_yes]) map['mmax'] = mmax map['mmin'] = mmin map['kaiguan'] = True return JsonResponse(map)
def sort_cluster(a, b): clist = uniform.cluster() x = clist.index(a[0]) y = clist.index(b[0]) return x - y