将Oracle监控指标在前端展现
这节讲述自定义命令相关的知识
这个专题主要内容有:
如何新建自定义命令
如何使用自定义命令获取Oracle自定义命令并写入数据库
如何将获取到的数据库监控指标在前端显示
经过前面的介绍我们已经把日常需要监控的指标存入了oraclestatus表中
下面我们将其在前端展现
开发环境
操作系统:CentOS 7.3
Python版本 :2.7
Django版本: 1.10.5
操作系统用户:oracle
建立页面的步骤
我们还是通过这张图的步骤来说明如何建立页面
urls.py页面
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'),
]
oracle_status为展示Oracle监控指标的页面
views.py
def oracle_status(request):
result=oraclestatus.objects.all().order_by('tnsname')
dic ={'result':result}
return render_to_response('oracle_status.html',dic)
该函数将oraclestatus表中数据取出来之后传递给oracle_status.html文件
template文件
这里我们使用oracle_status.html文件来显示
{% block content %}
数据库概况------每天零点更新
数据库名IP地址数据库大小SGA大小表空间状态版本开启时间归档状态
{% for i in result %}
{{i.tnsname|upper}}{{i.ipaddress|upper}}{{i.dbsize|upper}}G{{i.sga_size|upper}}M{% if i.tbstatus != "normal" %}{% endfor %}
{% endblock %}
这里通过一个表格来展现数据库指标的整体情况
Django允许在html文件内部使用程序动态控制页面的显示,代码中用到了if判断功能
对于表空间使用率不正常的以及未开启归档的以红色显示
注意:这里base.html,index.html文件都需要修改,具体见源码
最终效果
http://10.65.202.218:8081/monitor/oracle_status
可以看到已经显示出了有异常的表空间和归档状态的数据库
源代码位置
欢迎访问我的github主页查看源码
日常的监控指标展现在前端页面已经讲完了,这可以更方便我们日常的运维