返利网app网站开发,wordpress目录页如何关闭左侧目录,阿里企业邮箱收费标准,重庆是哪个省份利用Django在前端展示Oracle 状态趋势2017-12-15 Python 宅必备开发环境操作系统:CentOS 7.4Python版本 :3.6Django版本: 1.10.5操作系统用户:oms数据处理:pandas前端展示:highcharts通过上面我们已介绍了如何定时获取系统Oracle状态语句以及如何利用pandas处理成highcharts识别…利用Django在前端展示Oracle 状态趋势2017-12-15 Python 宅必备开发环境操作系统:CentOS 7.4Python版本 :3.6Django版本: 1.10.5操作系统用户:oms数据处理:pandas前端展示:highcharts通过上面我们已介绍了如何定时获取系统Oracle状态语句以及如何利用pandas处理成highcharts识别的格式这节讲如何让其在前端显示建立页面的步骤我们还是通过这张图的步骤来说明如何建立页面1. urls.py页面from django.conf.urls import url, includefrom monitor import viewsurlpatterns [url(r^$, views.index, nameindex),url(r^oracle_command/$,views.oracle_command, nameoracle_command),url(r^commandresult/$,views.commandresult, namecommandresult),url(r^oracle_status$,views.oracle_status, nameoracle_status),url(r^oracle_performance$,views.oracle_performance, nameoracle_performance),url(r^performance$,views.performance, nameperformance),url(r^oracle_topevent$,views.oracle_topevent, nameoracle_topevent),url(r^check_topsql$,views.check_topsql, namecheck_topsql),url(r^addbaseline$,views.addbaseline, nameaddbaseline),url(r^check_hitratio$,views.check_hitratio, namecheck_hitratio),url(r^linux_list$,views.linux_list, namelinux_list),]oracle_performance分别为系统状态趋势的页面(以天为单位)performance分别为系统状态趋势的页面(以小时为单位)2. views.py这里以oracle_performance函数做例子讲解def oracle_performance(request):baseline[]ip[]ip1oraclelist.objects.all().order_by(ipaddress)for i in ip1:ip.append(i.ipaddress:i.tnsname)if request.method POST: # If the form has been submitted...#return HttpResponse(ss)form charts_oracle_performance(request.POST) # A form bound to the POST dataif form.is_valid(): # All validation rules passstarttime1 request.POST[starttime]endtime1 request.POST[endtime]performance_type form.cleaned_data[performance_type]ipaddress_tnsname_listform.cleaned_data[ipaddress]intervalrequest.POST[interval]if starttime1 or endtime1 :return HttpResponse(Please give the Start and End time)else:starttimeint(str(time.mktime(time.strptime(starttime1,%Y%m%d))).split(.)[0])endtimeint(str(time.mktime(time.strptime(endtime1,%Y%m%d))).split(.)[0])if starttimeendtime:return HttpResponse(The Start time must larger than the End time)#starttimeint(str(time.mktime(time.strptime(starttime1,%Y%m%d %H:%M:%S))))#endtimeint(str(time.mktime(time.strptime(endtime1,%Y%m%d %H:%M:%S))))else:titleOracle Performance -performance_typesubtitleperformance_typetitle_y Blocks/Secondsif performance_type in [PhysicalReads,LogicalReads]:unitblocks/selif performance_type in [RedoSize]:unitbytes/selif performance_type in [DBTime,CPUTime]:unitMiniteselse:unittimes/sfinal_series[]#final_seriesoracle_performance_day(performance_type,ipaddress_tnsname_list,starttime,endtime,interval)#return HttpResponse(final_series)if intervalday:final_seriesoracle_performance_day(performance_type,ipaddress_tnsname_list,starttime,endtime,interval)x_categoriesfinal_series[0][x]elif intervalweek:final_seriesoracle_performance_week(performance_type,ipaddress_tnsname_list,starttime,endtime,interval)x_categoriesfinal_series[0][x]#return HttpResponse(final_series)dic{categories:x_categories,series:final_series,title:title,subtitle:subtitle,unit:unit,title_y:title_y}#return render_to_response(highcharts_histogram.html,dic) # Redirect after POST#return HttpResponse (final_series)return render_to_response(highcharts.html,dic) # Redirect after POSTelse:return render(request, oracle_performance.html, {form: form})else:form charts_oracle_performance() # An unbound formd1datetime.datetime.now()etime d1.strftime(%Y%m%d)stime(d1-datetime.timedelta(hours720)).strftime(%Y%m%d)#etime d1.strftime(%Y%m%d %H)#stime(d1-datetime.timedelta(hours24)).strftime(%Y%m%d %H)dic{form:form,etime:etime,stime:stime}#dic{form:form,ip:ip,ipaddress_checked:ipaddress_checked,etime:etime,stime:stime}return render(request, oracle_performance.html, dic)上面的url设定调用views.py里面的oracle_performance函数该函数讲解如下:首先判断请求的方法是不是post(提交表单前)如果不是则打开oracle_performance.html页面charts_oracle_performance为定义的表单可在forms.py中定义如果请求方法为post(提交表单后)首先验证输入是否正确如果正确则获取相应的ipaddress,tnsname,performance_type等信息,接下来根据performance_type的类型(物理读逻辑读等)调用monitor/command/views_oracleperformance.py文件里面的方法来得到我们想要的数据这个方法的讲解在昨天的公众号大家可自行查看最后我们将TOP SQL相关的内容封装成字典重定向到相应的template文件中3. template文件这里我们使用highcharts.html文件来显示趋势图$(function () {$(#container).highcharts({title: {text: {{title|safe}},x: -20 //center},xAxis: {categories: {{categories|safe}}},yAxis: {title: {text: {{unit}}},plotLines: [{value: 0,width: 1,color: #808080}]},legend: {layout: vertical,align: right,verticalAlign: middle,borderWidth: 0},plotOptions: {series: {cursor: pointer,point: {events: {click: function(e) {$(#test3).val(this.ysthis.x);//上面是当前页跳转如果是要跳出新页面那就用//window.open(e.point.url);//这里的url要后面的data里给出}}},}},series:[{% for i in series %}{name: {{i.name}},data: {{i.data}}},{% endfor %}]});});这里通过highcharts来展现数据库性能趋势状态Django允许在html文件内部使用程for循环的形式来迭代列表关于oracle_peforance页面就说到这了performance页面可自行参考源码4. 效果展示1.数据库系统状态趋势(天为单位)首先是表单提交之前的界面这里选择需要查询的数据库支持多个数据库同时查询然后是起止时间以及性能类型最后可以选择天和周为单位点击提交后会展示各个数据库该时间段的趋势图2.数据库系统状态趋势(小时为单位)首先是表单提交之前的界面这里选择需要查询的数据库然后是起止时间以及性能类型最后是是否比较基线,这个后续会有单独介绍点击提交后会展示出每天各个时间段的趋势图5. 源代码位置欢迎访问我的github主页查看源码