|
|
@ -10,13 +10,14 @@
|
|
|
|
from flask import Flask, session, request, redirect, Response
|
|
|
|
from flask import Flask, session, request, redirect, Response
|
|
|
|
from flask.templating import render_template
|
|
|
|
from flask.templating import render_template
|
|
|
|
from flask_session import Session
|
|
|
|
from flask_session import Session
|
|
|
|
|
|
|
|
import time
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
import monitor
|
|
|
|
import monitor
|
|
|
|
import Queue
|
|
|
|
import Queue
|
|
|
|
|
|
|
|
from utils.transport import *
|
|
|
|
PARAMS = {'context':''}
|
|
|
|
PARAMS = {'context':''}
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
|
|
|
|
|
|
|
@ -54,10 +55,14 @@ f.close()
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
from threading import Timer,Thread
|
|
|
|
from threading import Thread, RLock
|
|
|
|
ProcessQueue = Queue.LifoQueue()
|
|
|
|
p = {'uri':'http://dev.the-phi.com:5984','dbname':'monitor','uid':'logs','filename':'logs.JSON'}
|
|
|
|
mthread = monitor.Monitor(HANDLERS,ProcessQueue,'processes')
|
|
|
|
factory = DataSourceFactory()
|
|
|
|
|
|
|
|
gWriter = factory.instance(type='CouchdbWriter',args=p)
|
|
|
|
|
|
|
|
gReader = factory.instance(type='CouchdbReader',args=p)
|
|
|
|
|
|
|
|
mthread = monitor.Monitor(HANDLERS,gWriter,'processes',)
|
|
|
|
mthread.start()
|
|
|
|
mthread.start()
|
|
|
|
|
|
|
|
|
|
|
|
#(Timer(10,mthread.run)).start()
|
|
|
|
#(Timer(10,mthread.run)).start()
|
|
|
|
#mthread = Process(target=monitor.Monitor,args=(HANDLERS,ProcessQueue,'processes'))
|
|
|
|
#mthread = Process(target=monitor.Monitor,args=(HANDLERS,ProcessQueue,'processes'))
|
|
|
|
#mthread.start()
|
|
|
|
#mthread.start()
|
|
|
@ -76,14 +81,21 @@ def procs(id):
|
|
|
|
def trends ():
|
|
|
|
def trends ():
|
|
|
|
id = request.args.get('id')
|
|
|
|
id = request.args.get('id')
|
|
|
|
# key = request.args.get('key')
|
|
|
|
# key = request.args.get('key')
|
|
|
|
|
|
|
|
global mthread
|
|
|
|
|
|
|
|
# mLock.acquire()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
doc = gReader.read()
|
|
|
|
|
|
|
|
doc['row']
|
|
|
|
handler = monitor.mapreducer()
|
|
|
|
handler = monitor.mapreducer()
|
|
|
|
r = handler.filter(id,mthread.logs)
|
|
|
|
r = handler.filter(id,logs)
|
|
|
|
print r
|
|
|
|
|
|
|
|
if 'kate' in r:
|
|
|
|
|
|
|
|
for item in r['kate']:
|
|
|
|
|
|
|
|
print item['hour'],item['minute']
|
|
|
|
|
|
|
|
r = handler.run(r,handler.mapper,handler.reducer)
|
|
|
|
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)
|
|
|
|
return json.dumps(r)
|
|
|
|
@app.route('/dashboard')
|
|
|
|
@app.route('/dashboard')
|
|
|
|
def dashboard():
|
|
|
|
def dashboard():
|
|
|
|