The end of the graphic display is such a plan, the choice of classification and host after the default display is 1 days of graphics, click on the default of a graph and then again show the Monitor item 1 days, 1 weeks, January, 1 years of graphics, reference cacti.
The display of the default graphic has been completed in the 5th view function (PNGs is the PNG image path passed to the template) and the template finishes rendering.
The code of the template is very concise without too much modification, enough is good:
<! DOCTYPE html>
<title>{{Privatetitle}}</title>
<link rel= "icon" href= "{{static_url}}/favicon.ico" type= "Image/x-icon"/>
<!--Bootstrap-->
<link rel= "stylesheet" href= "{static_url}}/css/bootstrap.min.css" >
<link rel= "stylesheet" href= "{static_url}}/css/bootstrap-theme.min.css" >
{% block othercss%} {% Endblock%}
<script src= "{{static_url}}/js/jquery.min.js" ></script>
<script src= "{{static_url}}/js/bootstrap.min.js" ></script>
{% block Otherjs%} {% Endblock%}
<body>
<div class= "Container" >
<div class= "Col-md-9" >
{{Value}}
</div>
{% for PNG in pngs%}
<p>
<a href= "/graph/drawall/?graphid={{Png.graphid}" >
</a>
</p>
{% ENDFOR%}
</div>
</body>
A URL is attached to each picture that is displayed by default, and the function is to display the graphics of the monitor data for 1 days, 1 weeks, January, and 1 years when the picture is clicked.
The default day display is as follows (as with cacti, after all, it is rrdtool whole):
Memory stack diagram (the default is 1000, which can be specified as 1024 when drawing)
Draw a 1-day, 1-week, January, 1-year monitoring data graphic for the picture by adding a GET request for the default picture:
Get requests generated when clicking on a picture
The view function that handles the request is as follows:
def drawall (Request):
Gdatas = []
PNGs = []
Dir = r "/opt/rrd/"
Graphid = Request. get[' Graphid ']
sql = "Select HostID, Graphname, hostname from Zabbixapp_drawtree where graphid=" +graphid
Graph = DrawTree.objects.getclass (SQL)
HostID = graph[0][0]
Graphname = graph[0][1]
hostname = Graph[0][2]
rpath = dir + HostID + R "/" + Graphid + R ". Rrd"
Pngdir = r "/opt/www/diewu/static/images/rrdpng/cache/"
If not os.path.exists (Pngdir + graphid):
Os.makedirs (Pngdir + Graphid + R "/")
Png2d = Pngdir + Graphid + R "/" + R "2d.png"
Pngs.append (str (png2d). Replace (R "/opt/www/diewu", "")
png1w = Pngdir + Graphid + R "/" + R "1w.png"
Pngs.append (str (PNG1W). Replace (R "/opt/www/diewu", "")
png1m = Pngdir + Graphid + R "/" + R "1m.png"
Pngs.append (str (png1m). Replace (R "/opt/www/diewu", "")
png1y = Pngdir + Graphid + R "/" + R "1y.png"
Pngs.append (str (png1y). Replace (R "/opt/www/diewu", "")
#######################################################
sql = "Select Itemid,itemname,units from zabbixapp_drawgraphs where graphid=" +graphid
Pitem = DrawGraphs.objects.getdata (SQL)
##### #取自定义颜色和绘制方法
sql = "SELECT cols from Zabbixapp_drawdef where graphid=" +graphid
cols = DrawDef.objects.getdata (SQL)
If cols:
cols = (Cols[0][0].split (":"),)
sql = "Select types from Zabbixapp_drawdef where graphid=" +graphid
itypes = DrawDef.objects.getdata (SQL)
If Itypes:
Itypes = (Itypes[0][0].split (":"),)
############################
sql = "Select Itemid,itemname,units from zabbixapp_drawgraphs where graphid=" +graphid
Pitem = DrawGraphs.objects.getdata (SQL)
###########################
Strtime = str (int (time.time ()-86400))
Gdata = {' PName ':p ng2d, ' gname ': graphname, ' Rrdpath ': rpath, ' Pitem ':p item, ' Graphid ': Graphid,
' cols ': cols, ' itypes ': itypes, ' host ': hostname, ' stime ': strtime, ' flag ': ' Daily '}
Gdatas.append (Gdata)
###########################
Strtime = str (int (time.time ()-604800))
Gdata = {' PName ':p ng1w, ' gname ': graphname, ' Rrdpath ': rpath, ' Pitem ':p item, ' Graphid ': Graphid,
' cols ': cols, ' itypes ': itypes, ' host ': hostname, ' stime ': strtime, ' flag ': ' Weekly '}
Gdatas.append (Gdata)
###########################
Strtime = str (int (time.time ()-2592000))
Gdata = {' PName ':p ng1m, ' gname ': graphname, ' Rrdpath ': rpath, ' Pitem ':p item, ' Graphid ': Graphid,
' cols ': cols, ' itypes ': itypes, ' host ': hostname, ' stime ': strtime, ' flag ': ' Monthly '}
Gdatas.append (Gdata)
###########################
Strtime = str (int (time.time ()-31536000))
Gdata = {' PName ':p ng1y, ' gname ': graphname, ' Rrdpath ': rpath, ' Pitem ':p item, ' Graphid ': Graphid,
' cols ': cols, ' itypes ': itypes, ' host ': hostname, ' stime ': strtime, ' flag ': ' Yearly '}
Gdatas.append (Gdata)
##########################
Drawrrd.drawmain (Gdatas)
#value = Pitem
#avg = {' Privatetitle ': ' Zabbix monitor data display ', ' static_url ': '/static ', ' value ': value, ' PNGs ': PNGs}
Avg = {' Privatetitle ': ' Zabbix monitor data display ', ' static_url ': '/static ', ' PNGs ': PNGs}
Return Render_to_response (' zabbixapp/drawall.html ', avg)
The template drawall.html for this view function is as follows:
<! DOCTYPE html>
<title>{{Privatetitle}}</title>
<link rel= "icon" href= "{{static_url}}/favicon.ico" type= "Image/x-icon"/>
<!--Bootstrap-->
<link rel= "stylesheet" href= "{static_url}}/css/bootstrap.min.css" >
<link rel= "stylesheet" href= "{static_url}}/css/bootstrap-theme.min.css" >
{% block othercss%} {% Endblock%}
<script src= "{{static_url}}/js/jquery.min.js" ></script>
<script src= "{{static_url}}/js/bootstrap.min.js" ></script>
{% block Otherjs%} {% Endblock%}
<body>
<div class= "Container" >
<div class= "Col-md-9" >
{{Value}}
</div>
{% for PNG in pngs%}
<p>
</p>
{% ENDFOR%}
</div>
</body>
The final display effect is as follows (1 days, 1 weeks, January, 1 graphics for a host's disk IO monitoring data):
The second version of this operational dimension platform's monitoring data graphic display is basically complete.