using couchdb as store

master
Steve L. Nyemba 8 years ago
parent ac04d2d2cd
commit f2e36701d8

@ -1,9 +1,13 @@
click==6.6
couchdbkit==0.6.5
Flask==0.11.1 Flask==0.11.1
Flask-Session==0.3.0 Flask-Session==0.3.0
http-parser==0.8.3
itsdangerous==0.24
Jinja2==2.8 Jinja2==2.8
MarkupSafe==0.23 MarkupSafe==0.23
numpy==1.11.3
pika==0.10.0
restkit==4.2.2
socketpool==0.5.3
Werkzeug==0.11.11 Werkzeug==0.11.11
argparse==1.2.1
click==6.6
itsdangerous==0.24
wsgiref==0.1.2

@ -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():

@ -201,35 +201,35 @@ class DetailProcess(Analysis):
return ma return ma
class Monitor (Thread): class Monitor (Thread):
def __init__(self,pConfig,pQueue,id='processes') : def __init__(self,pConfig,pWriter,id='processes') :
Thread.__init__(self) Thread.__init__(self)
self.config = pConfig[id] self.config = pConfig[id]
self.queue = pQueue; self.writer = pWriter;
self.logs = [] self.logs = []
self.handler = self.config['class'] self.handler = self.config['class']
self.mconfig = self.config['config'] self.mconfig = self.config['config']
self.lock = RLock()
def stop(self):
self.keep_running = False
def run(self): def run(self):
r = {} r = {}
self.keep_running = True
while True: lock = RLock()
while self.keep_running:
for label in self.mconfig: for label in self.mconfig:
lock.acquire()
self.handler.init(self.mconfig[label])
self.handler.init(self.mconfig[label]) r = self.handler.composite()
r[label] = self.handler.composite() self.writer.write(label=label,row = r)
lock.release()
self.queue.put(r)
#self.logs.append(r)
self.prune()
self.queue.task_done() self.prune()
self.logs.append(self.queue.get(block=False))
HALF_HOUR = 60*1 HALF_HOUR = 60*1
time.sleep(HALF_HOUR) time.sleep(HALF_HOUR)
print "Stopped ..."
def prune(self) : def prune(self) :
MAX_ENTRIES = 100 MAX_ENTRIES = 100
if len(self.logs) > MAX_ENTRIES : if len(self.logs) > MAX_ENTRIES :

Loading…
Cancel
Save