Merge branch 'mike/test_values' of steve/monitor into community

community
Steve L. Nyemba 7 years ago committed by Gogs
commit 7ad518d1e5

@ -1,5 +1,4 @@
aniso8601==1.2.0 aniso8601==1.2.0
certifi==2017.11.5
chardet==3.0.4 chardet==3.0.4
click==6.6 click==6.6
couchdbkit==0.6.5 couchdbkit==0.6.5
@ -23,7 +22,6 @@ MarkupSafe==0.23
ngram==3.3.0 ngram==3.3.0
numpy==1.11.3 numpy==1.11.3
pika==0.10.0 pika==0.10.0
pkg-resources==0.0.0
pycparser==2.18 pycparser==2.18
pyOpenSSL==17.3.0 pyOpenSSL==17.3.0
python-dateutil==2.6.0 python-dateutil==2.6.0

@ -68,7 +68,7 @@ def home():
apps = [] apps = []
try: try:
# #
# The user must pass a key in heref # The user must pass a key in href
key = request.header['key'] key = request.header['key']
args= dict(p) args= dict(p)
args['uid'] = key args['uid'] = key
@ -76,10 +76,11 @@ def home():
gReader = factory.instance(type=class_read,args=p) gReader = factory.instance(type=class_read,args=p)
apps = gReader.view('summary/nodes',key=p['uid']) apps = gReader.view('summary/nodes',key=p['uid'])
except Exception, e: except Exception as e:
print (e) print (e)
return render_template('dashboard.html',context=context,title=title,app_names=apps) return render_template('dashboard.html',context=context,title=title,app_names=apps)
@app.route('/register', methods=['POST']) @app.route('/register', methods=['POST'])
def register(): def register():
""" """
@ -126,7 +127,7 @@ def get_nodes():
gReader = factory.instance(type=class_read, args=p) gReader = factory.instance(type=class_read, args=p)
r = gReader.view('summary/nodes', key=app_key) r = gReader.view('summary/nodes', key=app_key)
session['default.node'] = r[0] session['default.node'] = r[0]
except Exception,e: except Exception as e:
print (e) print (e)
return json.dumps(r) return json.dumps(r)
@ -143,7 +144,7 @@ def get_apps():
r = gReader.view('summary/app_names',key=p['uid']) r = gReader.view('summary/app_names',key=p['uid'])
r = r[node_id] r = r[node_id]
session['default.app'] = r[0] session['default.app'] = r[0]
except Exception,e: except Exception as e:
print (e) print (e)
return json.dumps(r) return json.dumps(r)
@ -183,7 +184,7 @@ def get_logs() :
for id in session['logs'] : for id in session['logs'] :
r[id] = session['logs'][id] r[id] = session['logs'][id]
# r[id] = r[node_id] # r[id] = r[node_id]
except Exception,e: except Exception as e:
print (e) print (e)
return json.dumps(r) return json.dumps(r)
@app.route("/1/set/logs",methods=['PUT']) @app.route("/1/set/logs",methods=['PUT'])
@ -231,7 +232,7 @@ def get_usage_trend():
try: try:
gReader = factory.instance(type=class_read,args=p) gReader = factory.instance(type=class_read,args=p)
r = gReader.view('summary/resource_usage_trend',key=p['uid']) r = gReader.view('summary/resource_usage_trend',key=p['uid'])
except Exception,e: except Exception as e:
print (e) print (e)
return json.dumps(r) return json.dumps(r)
@ -269,7 +270,7 @@ def get_usage_detail():
else : else :
r = r[id] r = r[id]
except Exception,e: except Exception as e:
print ' *** ',(e) print ' *** ',(e)
return json.dumps(r) return json.dumps(r)
@ -295,7 +296,7 @@ def app_status() :
print[nid,aid] print[nid,aid]
r = r[nid][aid] r = r[nid][aid]
except Exception,e: except Exception as e:
print e print e
return json.dumps(r) return json.dumps(r)
@ -464,7 +465,7 @@ def sandbox():
try: try:
handler.init(conf[id]) handler.init(conf[id])
r.append (dict(handler.composite(),**{"label":id})) r.append (dict(handler.composite(),**{"label":id}))
except Exception,e: except Exception as e:
pass pass
else: else:
@ -579,7 +580,7 @@ def user():
#_info = params[name] #_info = params[name]
#try: #try:
#xo = ML.Filter('label',name,d) #xo = ML.Filter('label',name,d)
#except Exception,e: #except Exception as e:
#xo = [] #xo = []
##print name,e ##print name,e
#if len(xo) == 0: #if len(xo) == 0:

@ -1,12 +1,5 @@
type = ['','info','success','warning','danger']; type = ['','info','success','warning','danger'];
function getNode(name){
var nodeName = {}
nodeName.name = name
console.log('nodename...', nodeName.name)
dashboard.initChartist(nodeName)
}
dashboard = { dashboard = {
initPickColor: function(){ initPickColor: function(){
$('.pick-class-label').click(function(){ $('.pick-class-label').click(function(){
@ -22,38 +15,39 @@ dashboard = {
}); });
}, },
initChartist: function(nodeName){ initChartist: function(){
function make_array() {
triple_array = [];
for (i=0;i<3;i++){
myarray = Array.from({length: 24}, () => Math.floor(Math.random() * 100))
triple_array.push(myarray)
}
return triple_array
}
// monitoring apps chart
var getData = $.get('/1/app/usage/trend'); var getData = $.get('/1/app/usage/trend');
getData.done(function(results) { getData.done(function(results) {
var data = JSON.parse(results) var app_usage_trend = JSON.parse(results);
if (typeof nodeName === 'undefined'){ if ($.isEmptyObject(app_usage_trend)){
var node = data['apps@michaels-MBP']; console.log('app_usage_trend is empty, setting testing values.');
console.log("undefined nodename.........") app_usage_trend = [];
} else { random_array = make_array();
console.log('this is nodeName...', nodeName) app_usage_trend = random_array
console.log('this is nodeName.name...', nodeName.name)
var node = data[nodeName.name]
console.log('data.name..', data[name])
} }
var app = node['chrome'];
var cpu = app['cpu'];
var memory_used = app['memory_used'];
console.log('data...',data)
console.log('node...',node)
console.log('app...',app)
console.log('cpu...',cpu)
console.log('memory_used...', memory_used)
// monitoring apps chart
var dataChart = { var dataChart = {
labels: ['24','23','22','21','20','19','18','17','16','15','14','13','12','11','10','9','8','7','6','5','4','3','2','1' ], labels: ['24','23','22','21','20','19','18','17','16','15','14','13','12','11','10','9','8','7','6','5','4','3','2','1' ],
series: [cpu, memory_used, [0,0.1,0.3,0.2,0.4,0.6,0.2], ] // TODO: Check the order, the graph is by index not name. series: app_usage_trend //TODO: Check the order, the graph is by index not name.
}; };
dataChartArray = dataChart.series dataChartArray = dataChart.series;
var maxlist = dataChartArray.map(dataChartArray => Math.max.apply(null, dataChartArray)); var maxlist = dataChartArray.map(function (dataChartArray) {
maxNum = Math.max.apply(null, maxlist) return Math.max.apply(null, dataChartArray);
});
maxNum = Math.max.apply(null, maxlist);
var optionsChart = { var optionsChart = {
lineSmooth: false, lineSmooth: false,
@ -62,13 +56,13 @@ dashboard = {
showArea: true, showArea: true,
height: "245px", height: "245px",
axisX: { axisX: {
showGrid: false, showGrid: false
}, },
lineSmooth: Chartist.Interpolation.simple({ lineSmooth: Chartist.Interpolation.simple({
divisor: 1 divisor: 1
}), }),
showLine: true, showLine: true,
showPoint: false, showPoint: false
}; };
var responsiveChart = [ var responsiveChart = [
@ -83,10 +77,10 @@ dashboard = {
Chartist.Line('#chartHours', dataChart, optionsChart, responsiveChart); Chartist.Line('#chartHours', dataChart, optionsChart, responsiveChart);
// cpu and memory -------------------------- // cpu and memory usage--------------------------
var data = { var data = {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], labels: ['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
series: [cpu, memory_used] series: make_array()
}; };
@ -111,16 +105,21 @@ dashboard = {
Chartist.Line('#chartActivity', data, options, responsiveOptions); Chartist.Line('#chartActivity', data, options, responsiveOptions);
var getStatus = $.get('1/get/summary/app_status'); //app status pie chart, idle, running, crash
var getStatus = $.get('1/app/status');
getStatus.done(function(results) { getStatus.done(function(results) {
var data = JSON.parse(results) var pie_chart = JSON.parse(results);
let getStatusList = [] if ($.isEmptyObject(pie_chart)){
getStatusList.push(data.idle) console.log('pie_chart is empty, setting testing values.');
getStatusList.push(data.crash) app_status = [1,2,3]
getStatusList.push(data.running) }
// var app_status = [];
// app_status.push(pie_chart.idle);
// app_status.push(pie_chart.crash);
// app_status.push(pie_chart.running);
Chartist.Pie('#chartPreferences', { Chartist.Pie('#chartPreferences', {
labels: getStatusList, labels: app_status,
series: getStatusList series: app_status
},{donut:true}); },{donut:true});
}) /// end getStatus }) /// end getStatus
}) })
@ -135,7 +134,7 @@ dashboard = {
scrollwheel: false, //we disable de scroll over the map, it is a really annoing when you scroll through page scrollwheel: false, //we disable de scroll over the map, it is a really annoing when you scroll through page
styles: [{"featureType":"water","stylers":[{"saturation":43},{"lightness":-11},{"hue":"#0088ff"}]},{"featureType":"road","elementType":"geometry.fill","stylers":[{"hue":"#ff0000"},{"saturation":-100},{"lightness":99}]},{"featureType":"road","elementType":"geometry.stroke","stylers":[{"color":"#808080"},{"lightness":54}]},{"featureType":"landscape.man_made","elementType":"geometry.fill","stylers":[{"color":"#ece2d9"}]},{"featureType":"poi.park","elementType":"geometry.fill","stylers":[{"color":"#ccdca1"}]},{"featureType":"road","elementType":"labels.text.fill","stylers":[{"color":"#767676"}]},{"featureType":"road","elementType":"labels.text.stroke","stylers":[{"color":"#ffffff"}]},{"featureType":"poi","stylers":[{"visibility":"off"}]},{"featureType":"landscape.natural","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"color":"#b8cb93"}]},{"featureType":"poi.park","stylers":[{"visibility":"on"}]},{"featureType":"poi.sports_complex","stylers":[{"visibility":"on"}]},{"featureType":"poi.medical","stylers":[{"visibility":"on"}]},{"featureType":"poi.business","stylers":[{"visibility":"simplified"}]}] styles: [{"featureType":"water","stylers":[{"saturation":43},{"lightness":-11},{"hue":"#0088ff"}]},{"featureType":"road","elementType":"geometry.fill","stylers":[{"hue":"#ff0000"},{"saturation":-100},{"lightness":99}]},{"featureType":"road","elementType":"geometry.stroke","stylers":[{"color":"#808080"},{"lightness":54}]},{"featureType":"landscape.man_made","elementType":"geometry.fill","stylers":[{"color":"#ece2d9"}]},{"featureType":"poi.park","elementType":"geometry.fill","stylers":[{"color":"#ccdca1"}]},{"featureType":"road","elementType":"labels.text.fill","stylers":[{"color":"#767676"}]},{"featureType":"road","elementType":"labels.text.stroke","stylers":[{"color":"#ffffff"}]},{"featureType":"poi","stylers":[{"visibility":"off"}]},{"featureType":"landscape.natural","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"color":"#b8cb93"}]},{"featureType":"poi.park","stylers":[{"visibility":"on"}]},{"featureType":"poi.sports_complex","stylers":[{"visibility":"on"}]},{"featureType":"poi.medical","stylers":[{"visibility":"on"}]},{"featureType":"poi.business","stylers":[{"visibility":"simplified"}]}]
} };
var map = new google.maps.Map(document.getElementById("map"), mapOptions); var map = new google.maps.Map(document.getElementById("map"), mapOptions);
var marker = new google.maps.Marker({ var marker = new google.maps.Marker({
@ -162,10 +161,10 @@ dashboard = {
align: align align: align
} }
}); });
},
} }
};
/** /**
* Global information about the dashboard * Global information about the dashboard
@ -178,29 +177,29 @@ g.summary = {}
* Initializing the top section of the dashboard (apps and folders) * Initializing the top section of the dashboard (apps and folders)
*/ */
g.summary.factory = function (url,pointer) { g.summary.factory = function (url,pointer) {
var object = {} var object = {};
object.url = url object.url = url;
var observer = null var observer = null;
var TIME_ELLAPSED = 2000 ; var TIME_ELLAPSED = 2000 ;
object.callback = function (r) { object.callback = function (r) {
r = JSON.parse(r.responseText) r = JSON.parse(r.responseText);
pointer(r) pointer(r)
//observer.notify() //observer.notify()
} };
object.init = function (observer) { object.init = function (observer) {
observer = observer observer = observer
var httpclient = HttpClient.instance() var httpclient = HttpClient.instance();
//httpclient.setAsync(false) //httpclient.setAsync(false)
httpclient.get(this.url, this.callback) httpclient.get(this.url, this.callback);
setTimeout(function(){ setTimeout(function(){
observer.notify() observer.notify()
},TIME_ELLAPSED) ; },TIME_ELLAPSED) ;
//observer.notify() //observer.notify()
} };
return object return object
} };

@ -46,39 +46,40 @@
<!-- Dashboard DEMO methods, don't include it in your project! --> <!-- Dashboard DEMO methods, don't include it in your project! -->
<script src="{{context}}/static/js/dashboard.js"></script> <script src="{{context}}/static/js/dashboard.js"></script>
<script src="{{context}}/static/js/jx/dom.js"></script> {# <script src="{{context}}/static/js/jx/dom.js"></script>#}
<script src="{{context}}/static/js/jx/rpc.js"></script> {# <script src="{{context}}/static/js/jx/rpc.js"></script>#}
<script src="{{context}}/static/js/jx/utils.js"></script> {# <script src="{{context}}/static/js/jx/utils.js"></script>#}
<script type="text/javascript"> <script type="text/javascript">
var URI_CONTEXT="{{context}}" var URI_CONTEXT="{{context}}";
$(document).ready(function(){ $(document).ready(function(){
var lobservers = [ {#var lobservers = [#}
g.summary.factory('/1/get/summary/app_resources',function(r){ {# g.summary.factory('/1/get/summary/app_resources',function(r){#}
{##}
//r = JSON.parse(r.responseText) {# //r = JSON.parse(r.responseText)#}
jx.dom.set.value('total_cpu',r.cpu_usage) {# jx.dom.set.value('total_cpu',r.cpu_usage)#}
jx.dom.set.value('total_mem',r.memory_usage) {# jx.dom.set.value('total_mem',r.memory_usage)#}
jx.dom.set.value('mem_units',r.units) {# jx.dom.set.value('mem_units',r.units)#}
{##}
}), {# }),#}
g.summary.factory('/1/get/summary/folder_size',function(r){ {# g.summary.factory('/1/get/summary/folder_size',function(r){#}
//console.log(r.responseText) {# //console.log(r.responseText)#}
//r = JSON.parse(r.responseText) {# //r = JSON.parse(r.responseText)#}
if (r.length == 0){ {# if (r.length == 0){#}
r.size = "0.0" {# r.size = "0.0"#}
r.units = 'MB' {# r.units = 'MB'#}
} {# }#}
jx.dom.set.value('total_folder_size',r.size) {# jx.dom.set.value('total_folder_size',r.size)#}
jx.dom.set.value('folder_units',r.units) {# jx.dom.set.value('folder_units',r.units)#}
}), {# }),#}
g.summary.factory('/1/get/summary/app_status',function(r){ {# g.summary.factory('/1/get/summary/app_status',function(r){#}
{##}
jx.dom.set.value('total_app_crashes',r.crash) {# jx.dom.set.value('total_app_crashes',r.crash)#}
}) {# })#}
] {#]#}
{##}
jx.utils.patterns.observer(lobservers,"init") {#jx.utils.patterns.observer(lobservers,"init")#}
//TODO Do we need the above JX stuff ?
dashboard.initChartist(); dashboard.initChartist();
}); });
@ -190,7 +191,7 @@
</div> </div>
<div class="col-xs-7"> <div class="col-xs-7">
<div class="numbers"> <div class="numbers">
<div id="total_cpu" align="center">00</div> <div id="total_cpu" align="center"></div>
<div class="small" align="right">Percent</div> <div class="small" align="right">Percent</div>
</div> </div>

@ -13,6 +13,8 @@ from datetime import datetime
from utils.transport import * from utils.transport import *
import monitor import monitor
import requests import requests
class Manager() : class Manager() :
def version(self): def version(self):
return 1.1 return 1.1

Loading…
Cancel
Save