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
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()
gWriter = factory.instance(type='CouchdbWriter',args=p)
gReader = factory.instance(type='CouchdbReader',args=p)
@ -69,34 +69,39 @@ mthread.start()
@app.route('/get/<id>')
def procs(id):
if id in HANDLERS and len(mthread.logs)>0:
# r = ProcessQueue.get(block=True,timeout=15)
index = len(mthread.logs) -1
r = mthread.logs[index]
try:
d = gReader.basic_read()
r = {}
for label in d :
index = len(d[label]) - 1
r[label] = d[label][index]
except Exception, e:
print e
r = []
return json.dumps(r)
else:
return "[]"
pass
@app.route('/trends')
def trends ():
id = request.args.get('id')
# key = request.args.get('key')
global mthread
# mLock.acquire()
time.sleep(2)
doc = gReader.read()
doc['row']
handler = monitor.mapreducer()
r = handler.filter(id,logs)
r = handler.run(r,handler.mapper,handler.reducer)
# mLock.release()
if 'Google Chrome' in r:
for item in r['Google Chrome']:
print item['hour'],item['minute']
return json.dumps(r)
r = gReader.basic_read()
if id in r:
r = r[id]
series = {}
for row in r:
for item in row:
id = item['label']
if id not in series :
series[id] = []
series[id].append(item)
if len(series[id]) > 24 :
beg = len(series[id]) - 25
series[id] = series[id][beg:]
return json.dumps(series)
else:
return "[]"
@app.route('/dashboard')
def dashboard():
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
httpclient.get(uri, function (x) {
var logs = JSON.parse(x.responseText)
console.log(logs)
// jx.dom.set.attribute(label,'logs',logs)
monitor.processes.trend.render(logs)
})
@ -109,7 +110,7 @@ monitor.processes.trend.render = function (logs, key) {
return {x:x,y:y}
})
serie.backgroundColor = ['transparent']
serie.backgroundColor = ['#ffffff']
serie.borderColor = COLORS[i]
serie.borderWidth = 1
++i

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

@ -475,6 +475,10 @@ class CouchdbReader(Couchdb,Reader):
break
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
The scope is the attribute that will be on the couchdb document

Loading…
Cancel
Save