日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

django oracle 性能,4.利用Django在前端展示Oracle 状态趋势

發布時間:2024/9/27 HTML 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 django oracle 性能,4.利用Django在前端展示Oracle 状态趋势 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

利用Django在前端展示Oracle 狀態趨勢

2017-12-15 Python 宅必備

開發環境

操作系統:CentOS 7.4

Python版本 :3.6

Django版本: 1.10.5

操作系統用戶:oms

數據處理:pandas

前端展示:highcharts

通過上面我們已介紹了如何定時獲取系統Oracle狀態語句以及如何利用pandas處理成highcharts識別的格式

這節講如何讓其在前端顯示

建立頁面的步驟

我們還是通過這張圖的步驟來說明如何建立頁面

1. urls.py頁面

from django.conf.urls import url, include

from monitor import views

urlpatterns = [

url(r'^$', views.index, name='index'),

url(r'^oracle_command/$',views.oracle_command, name='oracle_command'),

url(r'^commandresult/$',views.commandresult, name='commandresult'),

url(r'^oracle_status$',views.oracle_status, name='oracle_status'),

url(r'^oracle_performance$',views.oracle_performance, name='oracle_performance'),

url(r'^performance$',views.performance, name='performance'),

url(r'^oracle_topevent$',views.oracle_topevent, name='oracle_topevent'),

url(r'^check_topsql$',views.check_topsql, name='check_topsql'),

url(r'^addbaseline$',views.addbaseline, name='addbaseline'),

url(r'^check_hitratio$',views.check_hitratio, name='check_hitratio'),

url(r'^linux_list$',views.linux_list, name='linux_list'),

]

oracle_performance分別為系統狀態趨勢的頁面(以天為單位)

performance分別為系統狀態趨勢的頁面(以小時為單位)

2. views.py

這里以oracle_performance函數做例子講解

def oracle_performance(request):

baseline=[]

ip=[]

ip1=oraclelist.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 data

if form.is_valid(): # All validation rules pass

starttime1 = request.POST['starttime']

endtime1 = request.POST['endtime']

performance_type= form.cleaned_data['performance_type']

ipaddress_tnsname_list=form.cleaned_data['ipaddress']

interval=request.POST['interval']

if starttime1 =='' or endtime1 =='':

return HttpResponse('Please give the Start and End time')

else:

starttime=int(str(time.mktime(time.strptime(starttime1,'%Y%m%d'))).split('.')[0])

endtime=int(str(time.mktime(time.strptime(endtime1,'%Y%m%d'))).split('.')[0])

if starttime>endtime:

return HttpResponse('The Start time must larger than the End time')

#starttime=int(str(time.mktime(time.strptime(starttime1,'%Y%m%d %H:%M:%S'))))

#endtime=int(str(time.mktime(time.strptime(endtime1,'%Y%m%d %H:%M:%S'))))

else:

title='Oracle Performance '+'-'+performance_type

subtitle=performance_type

title_y=' Blocks/Seconds'

if performance_type in ['PhysicalReads','LogicalReads']:

unit='blocks/s'

elif performance_type in ['RedoSize']:

unit='bytes/s'

elif performance_type in ['DBTime','CPUTime']:

unit='Minites'

else:

unit='times/s'

final_series=[]

#final_series=oracle_performance_day(performance_type,ipaddress_tnsname_list,starttime,endtime,interval)

#return HttpResponse(final_series)

if interval=='day':

final_series=oracle_performance_day(performance_type,ipaddress_tnsname_list,starttime,endtime,interval)

x_categories=final_series[0]['x']

elif interval=='week':

final_series=oracle_performance_week(performance_type,ipaddress_tnsname_list,starttime,endtime,interval)

x_categories=final_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 POST

else:

return render(request, 'oracle_performance.html', {'form': form})

else:

form = charts_oracle_performance() # An unbound form

d1=datetime.datetime.now()

etime= d1.strftime("%Y%m%d")

stime=(d1-datetime.timedelta(hours=720)).strftime("%Y%m%d")

#etime= d1.strftime("%Y%m%d %H")

#stime=(d1-datetime.timedelta(hours=24)).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.y+'s'+this.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主頁查看源碼

總結

以上是生活随笔為你收集整理的django oracle 性能,4.利用Django在前端展示Oracle 状态趋势的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。