fixed trends with better delay & no-sql @TODO: try Messaging Queue

master
Steve L. Nyemba 8 years ago
parent 5eaec8b8ee
commit 2ddede65a3

@ -56,7 +56,7 @@ f.close()
# #
# #
from threading import Thread, RLock from threading import Thread, RLock
p = {'uri':'http://dev.the-phi.com:5984','dbname':'monitor','uid':'logs','filename':'logs.JSON'} p = {'uri':'http://localhost:5984','dbname':'monitor','uid':'logs','filename':'logs.JSON'}
factory = DataSourceFactory() factory = DataSourceFactory()
gWriter = factory.instance(type='CouchdbWriter',args=p) gWriter = factory.instance(type='CouchdbWriter',args=p)
gReader = factory.instance(type='CouchdbReader',args=p) gReader = factory.instance(type='CouchdbReader',args=p)
@ -69,34 +69,39 @@ mthread.start()
@app.route('/get/<id>') @app.route('/get/<id>')
def procs(id): def procs(id):
if id in HANDLERS and len(mthread.logs)>0: try:
# r = ProcessQueue.get(block=True,timeout=15) d = gReader.basic_read()
index = len(mthread.logs) -1 r = {}
r = mthread.logs[index] for label in d :
return json.dumps(r) index = len(d[label]) - 1
else: r[label] = d[label][index]
return "[]"
pass except Exception, e:
print e
r = []
return json.dumps(r)
@app.route('/trends') @app.route('/trends')
def trends (): def trends ():
id = request.args.get('id') id = request.args.get('id')
# key = request.args.get('key') r = gReader.basic_read()
global mthread if id in r:
# mLock.acquire() r = r[id]
series = {}
time.sleep(2) for row in r:
doc = gReader.read()
doc['row'] for item in row:
handler = monitor.mapreducer() id = item['label']
r = handler.filter(id,logs) if id not in series :
r = handler.run(r,handler.mapper,handler.reducer) series[id] = []
# mLock.release() series[id].append(item)
if 'Google Chrome' in r: if len(series[id]) > 24 :
for item in r['Google Chrome']: beg = len(series[id]) - 25
print item['hour'],item['minute'] series[id] = series[id][beg:]
return json.dumps(series)
return json.dumps(r) else:
return "[]"
@app.route('/dashboard') @app.route('/dashboard')
def dashboard(): def dashboard():
context = PARAMS['context'] context = PARAMS['context']

File diff suppressed because one or more lines are too long

@ -65,6 +65,7 @@ monitor.processes.trend.init = function (label) {
var uri = '/trends?id='+label var uri = '/trends?id='+label
httpclient.get(uri, function (x) { httpclient.get(uri, function (x) {
var logs = JSON.parse(x.responseText) var logs = JSON.parse(x.responseText)
console.log(logs)
// jx.dom.set.attribute(label,'logs',logs) // jx.dom.set.attribute(label,'logs',logs)
monitor.processes.trend.render(logs) monitor.processes.trend.render(logs)
}) })
@ -109,7 +110,7 @@ monitor.processes.trend.render = function (logs, key) {
return {x:x,y:y} return {x:x,y:y}
}) })
serie.backgroundColor = ['transparent'] serie.backgroundColor = ['#ffffff']
serie.borderColor = COLORS[i] serie.borderColor = COLORS[i]
serie.borderWidth = 1 serie.borderWidth = 1
++i ++i

@ -210,6 +210,8 @@ class Monitor (Thread):
self.handler = self.config['class'] self.handler = self.config['class']
self.mconfig = self.config['config'] self.mconfig = self.config['config']
def stop(self): def stop(self):
self.keep_running = False self.keep_running = False
def run(self): def run(self):
@ -227,7 +229,7 @@ class Monitor (Thread):
self.prune() self.prune()
HALF_HOUR = 60*1 HALF_HOUR = 60*5
time.sleep(HALF_HOUR) time.sleep(HALF_HOUR)
print "Stopped ..." print "Stopped ..."
def prune(self) : def prune(self) :

@ -475,6 +475,10 @@ class CouchdbReader(Couchdb,Reader):
break break
i = i + 1 i = i + 1
def basic_read(self):
document = self.dbase.get(self.uid)
del document['_id'], document['_rev']
return document
""" """
This class will write on a couchdb document provided a scope This class will write on a couchdb document provided a scope
The scope is the attribute that will be on the couchdb document The scope is the attribute that will be on the couchdb document

Loading…
Cancel
Save