def spend_list(req): now_startTime = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())) now_time = time.strftime("%H:%M:%S",time.localtime(time.time())) one_month_startTime = get_date.get_today_month(-1) + ' ' + now_time cmd = 'select u.department,count(us.jobuser) as usernum, sum(us.jobnum) as jobnum, sum(us.mapnum) as mapnum, sum(us.reducenum) as reducenum, sum(us.totaltime) as totaltime, sum(us.totalcpucost) as totalcpucost from(select jd.jobuser,count(1) as jobnum, sum(mapsTotal) as mapnum, sum(reducesTotal) as reducenum, sum(computeTime) as totaltime, sum(cpu_cost_time) as totalcpucost from audit_job_status_yz jd force index(startTime) where jd.startTime >= "%s" and jd.startTime <= "%s" group by jd.jobuser) us, audit_user u where us.jobuser=u.user_name group by u.department order by totaltime desc limit 10' %(one_month_startTime,now_startTime) datas = mysqlconn.mysql_conn(cmd) # return render_to_response('spend_list.html',{'datas':datas}) if 'beginTime' in req.GET and 'endTime' in req.GET: startTime1 = req.GET.get('beginTime') startTime2 = req.GET.get('endTime') cmd1 = 'select u.department,count(us.jobuser) as usernum, sum(us.jobnum) as jobnum, sum(us.mapnum) as mapnum, sum(us.reducenum) as reducenum, sum(us.totaltime) as totaltime, sum(us.totalcpucost) as totalcpucost from(select jd.jobuser,count(1) as jobnum, sum(mapsTotal) as mapnum, sum(reducesTotal) as reducenum, sum(computeTime) as totaltime, sum(cpu_cost_time) as totalcpucost from audit_job_status_yz jd force index(startTime) where jd.startTime >= "%s" and jd.startTime <= "%s" group by jd.jobuser) us, audit_user u where us.jobuser=u.user_name group by u.department order by totaltime desc limit 10' %(startTime1,startTime2) datas = mysqlconn.mysql_conn(cmd1) return render_to_response('spend_list.html',{'datas':datas}) return render_to_response('spend_list.html',{'datas':datas})
def job_time_status(req): timelist = [] userlist = Job_status_yz1.objects.values('jobuser').distinct() startTime = time.strftime("%Y-%m-%d",time.localtime(time.time())) for i in range(24): time1 = startTime + ' ' + str(i) time2 = startTime + ' ' + str(i+1) cmd = 'select sum(computeTime) from audit_job_status_yz1 where finishTime>="%s" and finishTime<"%s"' %(time1,time2) data1 = mysqlconn.mysql_conn(cmd) if data1[0][0]: timelist.append(int(data1[0][0])) else: timelist.append(0) if 'beginTimeshow' in req.GET: timelist = [] startTime = req.GET.get('beginTimeshow') st = re.split(" ",startTime)[0] for i in range(24): time1 = st + ' ' + str(i) time2 = st + ' ' + str(i+1) cmd = 'select sum(computeTime) from audit_job_status_yz1 where finishTime>="%s" and finishTime<"%s"' %(time1,time2) data1 = mysqlconn.mysql_conn(cmd) if data1[0][0]: timelist.append(int(data1[0][0])) else: timelist.append(0) return render_to_response('job_time1.html',{'userlist':userlist,'startTime':startTime,'timelist':timelist}) if 'beginTimeshow_user' in req.GET: timelist_user = [] if req.GET.has_key('search_user'): startTime = req.GET.get('beginTimeshow_user') jobuser = req.GET.get('user_name_graph') st = re.split(" ",startTime)[0] for i in range(24): time1 = st + ' ' + str(i) time2 = st + ' ' + str(i+1) cmd = 'select sum(computeTime) from audit_job_status_yz1 where finishTime>="%s" and finishTime<"%s" and jobuser="******"' %(time1,time2,jobuser) data1 = mysqlconn.mysql_conn(cmd) if data1[0][0]: timelist_user.append(int(data1[0][0])) else: timelist_user.append(0) return render_to_response('job_time1.html',{'userlist':userlist,'jobuser':jobuser,'st':st,'timelist_user':timelist_user}) return render_to_response('job_time1.html',{'userlist':userlist,'startTime':startTime,'timelist':timelist})
def user_reg(req): if 'user_name' in req.GET: user_name = req.GET.get('user_name') cmd = 'select * from audit_user where user_name="%s"' %user_name result = mysqlconn.mysql_conn(cmd) if len(result)!=0: return HttpResponse('用户名已存在') exit() applicant = req.GET.get('applicant') department = req.GET.get('department') leader = req.GET.get('leader') mobile_phone = req.GET.get('mobile_phone') tel_number = req.GET.get('tel_number') email = req.GET.get('email') storage = req.GET.get('storage') hadoop_client_ip = req.GET.get('hadoop_client_ip') if storage == '': storage = 0.0 storage_per_month = req.GET.get('storage_per_month') if storage_per_month == '': storage_per_month = 0.0 access_business_range = req.GET.get('access_business_range') description = req.GET.get('description') apply_date = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())) reginfo = User1(user_name=user_name, applicant=applicant, department=department, leader=leader, mobile_phone=mobile_phone, tel_number=tel_number, email=email, storage=storage, storage_per_month=storage_per_month, access_business_range=access_business_range, description=description, apply_date=apply_date) reginfo.save() if reginfo: return HttpResponse('注册成功') else: return HttpResponse('注册失败') return render_to_response('user_register1.html',{})
def get_three_month_job(): now_date = time.strftime("%Y-%m-%d",time.localtime(time.time())) three_month_ago = get_date.get_today_month(-3) cmd = 'select count(*) from audit_job_status_yz where finishTime>="%s" and finishTime<"%s"' %(three_month_ago,now_date) data = mysqlconn.mysql_conn(cmd) if data[0][0]: jobcount_three_month_ago = int(data[0][0]) else: jobcount_three_month_ago = 0 return jobcount_three_month_ago
def get_one_week_computeTime(): now_date = time.strftime("%Y-%m-%d",time.localtime(time.time())) one_week_ago = get_one_week_date() cmd = 'select sum(computeTime) from audit_job_status_yz where finishTime>="%s" and finishTime<"%s"' %(one_week_ago,now_date) data = mysqlconn.mysql_conn(cmd) if data[0][0]: computeTime_one_week_ago = int(data[0][0]) else: computeTime_one_week_ago = 0 return computeTime_one_week_ago
def get_three_month_computeTime1(): now_date = time.strftime("%Y-%m-%d",time.localtime(time.time())) three_month_ago = get_date.get_today_month(-3) cmd = 'select sum(computeTime) from audit_job_status_yz1 where finishTime>="%s" and finishTime<"%s"' %(three_month_ago,now_date) data = mysqlconn.mysql_conn(cmd) if data[0][0]: computeTime_three_month_ago1 = int(data[0][0]) else: computeTime_three_month_ago1 = 0 return computeTime_three_month_ago1
def summary(req): usercount_list = [] mapsTotal_list = [] reducesTotal_list = [] computeTime_list = [] sucesscount_list = [] failcount_list = [] startTime = time.strftime("%Y-%m-%d",time.localtime(time.time())) for i in range(24): time1 = startTime + ' ' + str(i) time2 = startTime + ' ' + str(i+1) cmd = 'select count(distinct jobuser),sum(mapsTotal),sum(reducesTotal),sum(computeTime)/60/60 from audit_job_status_yz where finishTime>="%s" and finishTime<"%s"' %(time1,time2) data1 = mysqlconn.mysql_conn(cmd) if data1[0][0] or data1[0][1] or data1[0][2] or data1[0][3]: usercount_list.append(int(data1[0][0])) mapsTotal_list.append(int(data1[0][1])) reducesTotal_list.append(int(data1[0][2])) computeTime_list.append(int(data1[0][3])) else: usercount_list.append(0) mapsTotal_list.append(0) reducesTotal_list.append(0) computeTime_list.append(0) cmd = 'select sum(sucesscount),sum(failcount) from audit_job_total_yz where finishTime>="%s" and finishTime<"%s"' data2 = mysqlconn.mysql_conn(cmd) if data2[0][0] or data2[0][1]: sucesscount_list.append(int(data2[0][0])) failcount_list.append(int(data2[0][1])) else: sucesscount_list.append(0) failcount_list.append(0) return render_to_response('summary.html',{'startTime':startTime,'usercount_list':usercount_list,'mapsTotal_list':mapsTotal_list,'reducesTotal_list':reducesTotal_list,'sucesscount_list':sucesscount_list,'failcount_list':failcount_list,'computeTime_list':computeTime_list})
def get_one_week_user1(): now_date = time.strftime("%Y-%m-%d",time.localtime(time.time())) one_week_ago = get_one_week_date() cmd = 'select count(distinct jobuser) from audit_job_status_yz1 where finishTime>="%s" and finishTime<"%s"' %(one_week_ago,now_date) data = mysqlconn.mysql_conn(cmd) if data[0][0]: usercount_one_week_ago1 = int(data[0][0]) else: usercount_one_week_ago1 = 0 return usercount_one_week_ago1
def department_reg(req): if 'department' in req.GET: department = req.GET.get('department') cmd = 'select * from audit_department where department="%s"' %department result = mysqlconn.mysql_conn(cmd) if len(result)!=0: return HttpResponse('部门已存在') exit() leader = req.GET.get('leader') depart_mail = req.GET.get('depart_mail') leader_mobile = req.GET.get('leader_mobile') leader_mail = req.GET.get('leader_mail') reginfo = Department(department=department, leader=leader, depart_mail=depart_mail, leader_mobile=leader_mobile, leader_mail=leader_mail) reginfo.save() if reginfo: return HttpResponse('注册成功') else: return HttpResponse('注册失败') return render_to_response('department_register.html',{})
def performance(req): eth_in_list = [] eth_out_list = [] bytes_in_list = [] bytes_out_list = [] load_five_list = [] cpu_user_list = [] cpu_system_list = [] startTime = time.strftime("%Y-%m-%d", time.localtime(time.time())) for i in range(24): time1 = startTime + " " + str(i) time2 = startTime + " " + str(i + 1) cmd = ( 'select avg(eth_in),avg(eth_out),avg(bytes_in),avg(bytes_out),avg(load_five),avg(cpu_user),avg(cpu_system) from audit_performance1 where collect_time >= (UNIX_TIMESTAMP("%s"))*1000 and collect_time < (UNIX_TIMESTAMP("%s"))*1000' % (time1, time2) ) data1 = mysqlconn.mysql_conn(cmd) if data1[0][0] or data1[0][1] or data1[0][2] or data1[0][3] or data1[0][4] or data1[0][5] or data1[0][6]: eth_in_list.append(int(data1[0][0])) eth_out_list.append(int(data1[0][1])) bytes_in_list.append(int(data1[0][2])) bytes_out_list.append(int(data1[0][3])) load_five_list.append(int(data1[0][4])) cpu_user_list.append(int(data1[0][5])) cpu_system_list.append(int(data1[0][6])) else: eth_in_list.append(0) eth_out_list.append(0) bytes_in_list.append(0) bytes_out_list.append(0) load_five_list.append(0) cpu_user_list.append(0) cpu_system_list.append(0) if "beginTimeshow" in req.GET: eth_in_list = [] eth_out_list = [] bytes_in_list = [] bytes_out_list = [] load_five_list = [] cpu_user_list = [] cpu_system_list = [] startTime = req.GET.get("beginTimeshow") st = re.split(" ", startTime)[0] for i in range(24): time1 = st + " " + str(i) time2 = st + " " + str(i + 1) cmd = ( 'select sum(eth_in),sum(eth_out),sum(bytes_in),sum(bytes_out),sum(load_five),sum(cpu_user),sum(cpu_system) from audit_performance1 where collect_time >= (UNIX_TIMESTAMP("%s"))*1000 and collect_time < (UNIX_TIMESTAMP("%s"))*1000' % (time1, time2) ) data1 = mysqlconn.mysql_conn(cmd) if ( data1[0][0] or data1[0][1] or data1[0][2] or data1[0][3] or data1[0][4] or data1[0][5] or data1[0][6] ): eth_in_list.append(int(data1[0][0])) eth_out_list.append(int(data1[0][1])) bytes_in_list.append(int(data1[0][2])) bytes_out_list.append(int(data1[0][3])) load_five_list.append(int(data1[0][4])) cpu_user_list.append(int(data1[0][5])) cpu_system_list.append(int(data1[0][6])) else: eth_in_list.append(0) eth_out_list.append(0) bytes_in_list.append(0) bytes_out_list.append(0) load_five_list.append(0) cpu_user_list.append(0) cpu_system_list.append(0) return render_to_response( "performance1.html", { "startTime": startTime, "eth_in_list": eth_in_list, "eth_out_list": eth_out_list, "bytes_in_list": bytes_in_list, "bytes_out_list": bytes_out_list, "load_five_list": load_five_list, "cpu_user_list": cpu_user_list, "cpu_system_list": cpu_system_list, }, ) return render_to_response( "performance1.html", { "startTime": startTime, "eth_in_list": eth_in_list, "eth_out_list": eth_out_list, "bytes_in_list": bytes_in_list, "bytes_out_list": bytes_out_list, "load_five_list": load_five_list, "cpu_user_list": cpu_user_list, "cpu_system_list": cpu_system_list, }, )
def job_status(req): maplist = [] redlist = [] suclist = [] failist = [] userlist = Job_status_yz.objects.values('jobuser').distinct() startTime = time.strftime("%Y-%m-%d",time.localtime(time.time())) # now_time = '2015-05-11' for i in range(24): time1 = startTime + ' ' + str(i) time2 = startTime + ' ' + str(i+1) cmd = 'select sum(mapsTotal),sum(reducesTotal) from audit_job_status_yz where finishTime>="%s" and finishTime<"%s"' %(time1,time2) data1 = mysqlconn.mysql_conn(cmd) if data1[0][0] or data1[0][1]: maplist.append(int(data1[0][0])) redlist.append(int(data1[0][1])) else: maplist.append(0) redlist.append(0) cmd = 'select sum(sucesscount),sum(failcount) from audit_job_total_yz where finishTime>="%s" and finishTime<"%s"' %(time1,time2) data2 = mysqlconn.mysql_conn(cmd) if data2[0][0] or data2[0][1]: suclist.append(int(data2[0][0])) failist.append(int(data2[0][1])) else: suclist.append(0) failist.append(0) if 'beginTimeshow' in req.GET: maplist = [] redlist = [] suclist = [] failist = [] startTime = req.GET.get('beginTimeshow') st = re.split(" ",startTime)[0] for i in range(24): time1 = st + ' ' + str(i) time2 = st + ' ' + str(i+1) cmd = 'select sum(mapsTotal),sum(reducesTotal) from audit_job_status_yz where finishTime>="%s" and finishTime<"%s"' %(time1,time2) data1 = mysqlconn.mysql_conn(cmd) if data1[0][0] or data1[0][1]: maplist.append(int(data1[0][0])) redlist.append(int(data1[0][1])) else: maplist.append(0) redlist.append(0) cmd = 'select sum(sucesscount),sum(failcount) from audit_job_total_yz where finishTime>="%s" and finishTime<"%s"' %(time1,time2) data2 = mysqlconn.mysql_conn(cmd) if data2[0][0] or data2[0][1]: suclist.append(int(data2[0][0])) failist.append(int(data2[0][1])) else: suclist.append(0) failist.append(0) return render_to_response('job_statistic.html',{'userlist':userlist,'startTime':startTime,'maplist':maplist,'redlist':redlist,'suclist':suclist,'failist':failist}) if 'beginTimeshow_user' in req.GET: maplist_user = [] redlist_user = [] suclist_user = [] failist_user = [] if req.GET.has_key('search_user'): startTime = req.GET.get('beginTimeshow_user') jobuser = req.GET.get('user_name_graph') st = re.split(" ",startTime)[0] for i in range(24): time1 = st + ' ' + str(i) time2 = st + ' ' + str(i+1) cmd = 'select sum(mapsTotal),sum(reducesTotal) from audit_job_status_yz where finishTime>="%s" and finishTime<"%s" and jobuser="******"' %(time1,time2,jobuser) data1 = mysqlconn.mysql_conn(cmd) if data1[0][0] or data1[0][1]: maplist_user.append(int(data1[0][0])) redlist_user.append(int(data1[0][1])) else: maplist_user.append(0) redlist_user.append(0) cmd = 'select sum(sucesscount),sum(failcount) from audit_job_total_yz where finishTime>="%s" and finishTime<"%s" and jobuser="******"' %(time1,time2,jobuser) data2 = mysqlconn.mysql_conn(cmd) if data2[0][0] or data2[0][1]: suclist_user.append(int(data2[0][0])) failist_user.append(int(data2[0][1])) else: suclist_user.append(0) failist_user.append(0) return render_to_response('job_statistic.html',{'userlist':userlist,'jobuser':jobuser,'st':st,'maplist_user':maplist_user,'redlist_user':redlist_user,'suclist_user':suclist_user,'failist_user':failist_user}) return render_to_response('job_statistic.html',{'userlist':userlist,'startTime':startTime,'maplist':maplist,'redlist':redlist,'suclist':suclist,'failist':failist})
def performance(req): eth_in_list = [] eth_out_list = [] bytes_in_list = [] bytes_out_list = [] load_five_list = [] cpu_user_list = [] cpu_system_list = [] startTime = time.strftime("%Y-%m-%d",time.localtime(time.time())) for i in range(24): time1 = startTime + ' ' + str(i) time2 = startTime + ' ' + str(i+1) cmd = 'select avg(eth_in),avg(eth_out),avg(bytes_in),avg(bytes_out),avg(load_five),avg(cpu_user),avg(cpu_system) from audit_performance where collect_time >= (UNIX_TIMESTAMP("%s"))*1000 and collect_time < (UNIX_TIMESTAMP("%s"))*1000' %(time1,time2) data1 = mysqlconn.mysql_conn(cmd) if data1[0][0] or data1[0][1] or data1[0][2] or data1[0][3] or data1[0][4] or data1[0][5] or data1[0][6]: eth_in_list.append(int(data1[0][0])) eth_out_list.append(int(data1[0][1])) bytes_in_list.append(int(data1[0][2])) bytes_out_list.append(int(data1[0][3])) load_five_list.append(int(data1[0][4])) cpu_user_list.append(int(data1[0][5])) cpu_system_list.append(int(data1[0][6])) else: eth_in_list.append(0) eth_out_list.append(0) bytes_in_list.append(0) bytes_out_list.append(0) load_five_list.append(0) cpu_user_list.append(0) cpu_system_list.append(0) if 'beginTimeshow' in req.GET: eth_in_list = [] eth_out_list = [] bytes_in_list = [] bytes_out_list = [] load_five_list = [] cpu_user_list = [] cpu_system_list = [] startTime = req.GET.get('beginTimeshow') st = re.split(" ",startTime)[0] for i in range(24): time1 = st + ' ' + str(i) time2 = st + ' ' + str(i+1) cmd = 'select sum(eth_in),sum(eth_out),sum(bytes_in),sum(bytes_out),sum(load_five),sum(cpu_user),sum(cpu_system) from audit_performance where collect_time >= (UNIX_TIMESTAMP("%s"))*1000 and collect_time < (UNIX_TIMESTAMP("%s"))*1000' %(time1,time2) data1 = mysqlconn.mysql_conn(cmd) if data1[0][0] or data1[0][1] or data1[0][2] or data1[0][3] or data1[0][4] or data1[0][5] or data1[0][6]: eth_in_list.append(int(data1[0][0])) eth_out_list.append(int(data1[0][1])) bytes_in_list.append(int(data1[0][2])) bytes_out_list.append(int(data1[0][3])) load_five_list.append(int(data1[0][4])) cpu_user_list.append(int(data1[0][5])) cpu_system_list.append(int(data1[0][6])) else: eth_in_list.append(0) eth_out_list.append(0) bytes_in_list.append(0) bytes_out_list.append(0) load_five_list.append(0) cpu_user_list.append(0) cpu_system_list.append(0) return render_to_response('performance.html',{'startTime':startTime,'eth_in_list':eth_in_list,'eth_out_list':eth_out_list,'bytes_in_list':bytes_in_list,'bytes_out_list':bytes_out_list,'load_five_list':load_five_list,'cpu_user_list':cpu_user_list,'cpu_system_list':cpu_system_list}) return render_to_response('performance.html',{'startTime':startTime,'eth_in_list':eth_in_list,'eth_out_list':eth_out_list,'bytes_in_list':bytes_in_list,'bytes_out_list':bytes_out_list,'load_five_list':load_five_list,'cpu_user_list':cpu_user_list,'cpu_system_list':cpu_system_list})