added cpu/memory on same chart and download of requirements file in virtual environment analysis @TODO: multivariate anomaly detection

master
Steve L. Nyemba 8 years ago
parent 056fef24c6
commit a374e06721

@ -113,6 +113,13 @@ def trends ():
return json.dumps(series) return json.dumps(series)
else: else:
return "[]" return "[]"
@app.route('/download',methods=['POST'])
def requirements():
stream = request.form['missing']
print stream
stream = "\n".join(json.loads(stream))
headers = {"content-disposition":"attachment; filename=requirements.txt"}
return Response(stream,mimetype='text/plain',headers=headers)
@app.route('/dashboard') @app.route('/dashboard')
def dashboard(): def dashboard():
context = PARAMS['context'] context = PARAMS['context']

@ -109,14 +109,14 @@ monitor.processes.trend.init = function (label,app) {
}) })
} }
monitor.processes.trend.render = function (logs, key,label) { monitor.processes.trend.render = function (logs, key,label) {
if (key == null) { // if (key == null) {
key = 'memory_usage' // key = 'memory_usage'
} // }
if (logs == null || label == null){ // if (logs == null || label == null){
logs = jx.dom.get.instance('trend_info').logs // logs = jx.dom.get.instance('trend_info').logs
label= jx.dom.get.value('trend_info') ; // label= jx.dom.get.value('trend_info') ;
} // }
var frame = $('#trends_chart') var frame = $('#trends_chart')
jx.dom.set.value('trends_chart','') jx.dom.set.value('trends_chart','')
var context = jx.dom.get.instance('CANVAS') var context = jx.dom.get.instance('CANVAS')
@ -127,7 +127,7 @@ monitor.processes.trend.render = function (logs, key,label) {
conf.data = {} conf.data = {}
conf.options = { legend: { position: 'bottom' } } conf.options = { legend: { position: 'bottom' } }
conf.options.scales = {} conf.options.scales = {}
conf.options.scales.yAxes = [ {scaleLabel:{display:true,labelString:key.replace(/_/,' ').toUpperCase()},ticks:{min:0,beginAtZero:true},gridLines: {display:false}}] conf.options.scales.yAxes = [ {scaleLabel:{display:true,labelString:'CPU & MEMORY USAGE'},ticks:{min:0,beginAtZero:true},gridLines: {display:false}}]
conf.options.scales.xAxes = [ conf.options.scales.xAxes = [
{ {
@ -144,33 +144,28 @@ monitor.processes.trend.render = function (logs, key,label) {
conf.data.datasets = [ ] conf.data.datasets = [ ]
var x_axis = [] var x_axis = []
var _x = {} var _x = {}
var _y = {} // var _y = {}
var values = jx.utils.patterns.visitor(logs,function(item){ var cpu = { label: 'CPU Usage (%)', data: [] ,backgroundColor:'transparent',borderColor:COLORS[187],fill:false,borderWidth:1}
var mem = {label : 'Memory Usage(%)',data:[],backgroundColor:'transparent',borderColor:COLORS[32],fill:false,borderWidth:1}
jx.utils.patterns.visitor(logs,function(item){
x = new Date(item.year,item.month-1,item.day,item.hour,item.minute) x = new Date(item.year,item.month-1,item.day,item.hour,item.minute)
y = item[key] y = item[key]
if (_x[x] == null ||(_x[x] == null && _y[y] == null)) { if (_x[x] == null ){//||(_x[x] == null && _y[y] == null)) {
_x[x] = 1 _x[x] = 1
_y[y] = 1 // _y[y] = 1
x_axis.push(x) x_axis.push(x)
cpu.data.push({ x: x, y: item.cpu_usage })
mem.data.push({x:x,y:item.memory_usage})
// return {x:x,y:y}
return {x:x,y:y}
} else {
return null
} }
}) })
var serie = {label:label,data:values}
i = parseInt(Math.random() * (COLORS.length - 1))
serie.backgroundColor = 'transparent'
serie.borderColor = COLORS[2]
serie.borderWidth = 1
serie.type = 'line'
conf.data.datasets.push(serie)
x_axis = jx.utils.unique(x_axis)
conf.data.datasets = [cpu,mem]
x_axis = jx.utils.unique(x_axis)
conf.data.labels = x_axis conf.data.labels = x_axis
// console.log(conf) // console.log(conf)
jx.dom.append('trends_chart',context) jx.dom.append('trends_chart',context)
@ -282,19 +277,19 @@ monitor.sandbox.init = function () {
}) })
} }
monitor.sandbox.render = function (logs) { monitor.sandbox.render = function (logs) {
months = {1:'Jan',2:'Feb',3:'Mar',4:'Apr',5:'May',6:'Jun',7:'Jul',8:'Aug',9:'Sep',10:'Oct',11:'Nov',12:'Dec'} months = { 1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr', 5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug', 9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec' }
var d = ([logs[0].day, '-', months[logs[0].month],'-', logs[0].year, ' ', logs[0].hour, ':', logs[0].minute]).join('') var d = ([logs[0].day, '-', months[logs[0].month], '-', logs[0].year, ' ', logs[0].hour, ':', logs[0].minute]).join('')
jx.dom.set.value('sandbox_date',d) jx.dom.set.value('sandbox_date', d)
var options = {width:$('#sandbox_status').width(),height:'auto'} var options = { width: $('#sandbox_status').width(), height: 'auto' }
options.data = logs options.data = logs
options.paging = true options.paging = true
options.pageSize = 4 options.pageSize = 4
options.pageIndex = 1 options.pageIndex = 1
options.pageButtonCount = 4 options.pageButtonCount = 4
options.pagerContainer = '#latest_process_pager' options.pagerContainer = '#sandbox_pager'
options.pagerFormat= "{prev} Page {pageIndex} of {pageCount} {next}" options.pagerFormat = "{prev} Page {pageIndex} of {pageCount} {next}"
options.pagePrevText= '<i class="fa fa-chevron-left"></i>' options.pagePrevText = '<i class="fa fa-chevron-left"></i>'
options.pageNextText = "<i class='fa fa-chevron-right small' title='Next'> </i>"; options.pageNextText = "<i class='fa fa-chevron-right small' title='Next'> </i>";
options.rowClass = function (item) { options.rowClass = function (item) {
@ -306,7 +301,22 @@ monitor.sandbox.render = function (logs) {
return 'good' return 'good'
} }
} }
options.rowClick = function (args) {
var item = args.item;
if (item.missing.length > 0) {
var form = jx.dom.get.instance('FORM')
var dom = jx.dom.get.instance('INPUT')
dom.type = 'hidden'
dom.name = 'missing'
dom.value = JSON.stringify(item.missing)
form.action = '/download'
form.method = 'POST'
form.appendChild(dom)
form.submit()
}
}
options.fields = [ options.fields = [
{ name: 'label',title:'Virtual Environment Label',type:'text',css:'small',headercss:'small bold' }, { name: 'label',title:'Virtual Environment Label',type:'text',css:'small',headercss:'small bold' },
{ name: 'value', title:'Completeness %',type: 'number', css: 'small', headercss: 'small bold' } { name: 'value', title:'Completeness %',type: 'number', css: 'small', headercss: 'small bold' }

@ -58,14 +58,10 @@
</div> </div>
<div class="left info"> <div class="left info">
<div>History of Processes <span id="trend_info" class="bold"></span> <div class="">CPU & Memory Usage Trend for <span id="trend_info" class=""></span>
</div> </div>
<div class="menu" style="margin:4px">
<div class="left menu-item small padding-2x margin-2x" onclick="monitor.processes.trend.render(null,'cpu_usage',null)"><i class="fa fa-chevron-right" ></i> CPU used</div> <div style="height:270px; margin-top:10px">
<div class="left menu-item small padding-2x margin-2x" onclick="monitor.processes.trend.render(null,'memory_usage',null)"><i class="fa fa-chevron-right" ></i> Mem. Used</div>
<div class="left menu-item small padding-2x margin-2x" onclick="monitor.processes.trend.render(null,'memory_available',null)"><i class="fa fa-chevron-right"></i> Mem. Avail</div>
</div>
<div style="height:270px">
<div id="trends_chart" class="small grid" style="height:250px"></div> <div id="trends_chart" class="small grid" style="height:250px"></div>
</div> </div>
<div class="border-top" style="padding:4px;"> <div class="border-top" style="padding:4px;">
@ -74,9 +70,16 @@
<div id="inspect_sandbox" class="right button border" style="display:none" onclick="monitor.sandbox.init()">Inspect</div> <div id="inspect_sandbox" class="right button border" style="display:none" onclick="monitor.sandbox.init()">Inspect</div>
<div class="small">Last Lookup <span id="sandbox_date"></span></div> <div class="small">Last Lookup <span id="sandbox_date"></span></div>
</div> </div>
<div class="">
<div class="small">
<i class="fa fa-warning" style="color:orange"></i>
Click on a row that is not complete to download requirements file
</div>
<div class="" style="margin-top:10px">
<div id="sandbox_status" class="grid"> <div id="sandbox_status" class="grid">
</div> </div>
<div id="sandbox_pager"></div>
</div> </div>
</div> </div>

Loading…
Cancel
Save