|
|
@ -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']
|
|
|
|