parent
f3d9e03b95
commit
b0cd031b07
@ -0,0 +1,9 @@
|
||||
from flask import Flask, render_template
|
||||
from flask_socketio import SocketIO
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SECRET_KEY'] = '[0v8-247]-4qdm-h8r5!'
|
||||
socketio = SocketIO(app)
|
||||
|
||||
if __name__ == '__main__':
|
||||
socketio.run(app)
|
@ -0,0 +1,17 @@
|
||||
import sys
|
||||
PARAMS = {'context':''}
|
||||
if len(sys.argv) > 1:
|
||||
|
||||
N = len(sys.argv)
|
||||
for i in range(1,N):
|
||||
value = None
|
||||
if sys.argv[i].startswith('--'):
|
||||
key = sys.argv[i].replace('-','')
|
||||
|
||||
if i + 1 < N:
|
||||
value = sys.argv[i + 1] = sys.argv[i+1].strip()
|
||||
if key and value:
|
||||
PARAMS[key] = value
|
||||
|
||||
i += 2
|
||||
|
@ -0,0 +1,96 @@
|
||||
import multiprocessing
|
||||
from utils import transport
|
||||
import time
|
||||
import monitor
|
||||
import sys
|
||||
"""
|
||||
This class is intended to collect data given a configuration
|
||||
|
||||
"""
|
||||
class Top(multiprocessing.Process):
|
||||
def __init__(self,_config,lock):
|
||||
multiprocessing.Process.__init__(self)
|
||||
self.lock = lock
|
||||
self.reader_class = _config['store']['class']['read']
|
||||
self.write_class = _config['store']['class']['write']
|
||||
self.rw_args = _config['store']['args']
|
||||
self.factory = transport.DataSourceFactory()
|
||||
|
||||
self.name = 'Zulu-Top'
|
||||
self.quit = False
|
||||
print sys.argv
|
||||
sys.argv[0] = self.name
|
||||
print sys.argv
|
||||
# multiprocessing.current_process().name = 'Zulu-Top'
|
||||
self.exit = multiprocessing.Event()
|
||||
|
||||
|
||||
className = ''.join(['monitor.',_config['monitor']['processes']['class'],'()'])
|
||||
self.handler = eval(className)
|
||||
self.config = _config['monitor']['processes']['config']
|
||||
def stop(self):
|
||||
self.quit = True
|
||||
def run(self):
|
||||
while self.quit == False:
|
||||
for label in self.config :
|
||||
self.lock.acquire()
|
||||
gwriter = self.factory.instance(type=self.write_class,args=self.rw_args)
|
||||
for app in self.config[label] :
|
||||
self.handler.init(app)
|
||||
r = self.handler.composite()
|
||||
gwriter.write(label=label,row=r)
|
||||
time.sleep(5)
|
||||
self.lock.release()
|
||||
ELLAPSED_TIME = 60*30
|
||||
time.sleep(ELLAPSED_TIME)
|
||||
print "Exiting ",self.name
|
||||
|
||||
class Learner(multiprocessing.Process) :
|
||||
|
||||
"""
|
||||
This function expects paltform config (store,learner)
|
||||
It will leverage store and learner in order to operate
|
||||
"""
|
||||
def __init__(self,config,lock):
|
||||
multiprocessing.Process.__init__(self)
|
||||
self.name='Zulu-Learner'
|
||||
self.lock = lock
|
||||
self.reader_class = config['store']['class']['read']
|
||||
self.write_class = config['store']['class']['write']
|
||||
self.rw_args = config['store']['args']
|
||||
self.features = config['learner']['anomalies']['features']
|
||||
self.yo = config['learner']['anomalies']['label']
|
||||
self.apps = config['learner']['anomalies']['apps']
|
||||
self.factory = transport.DataSourceFactory()
|
||||
"""
|
||||
This function will initiate learning every (x-hour)
|
||||
If there is nothing to learn the app will simply go to sleep
|
||||
"""
|
||||
def run(self):
|
||||
reader = self.factory.instance(type=self.reader_class,args=self.rw_args)
|
||||
data = reader.read()
|
||||
#
|
||||
# This is the motherload of innefficiency ...
|
||||
#
|
||||
while True:
|
||||
r = {}
|
||||
for key in data :
|
||||
logs = data[key]
|
||||
r[key] = {}
|
||||
for app in self.apps:
|
||||
handler = AnomalyDetection()
|
||||
r[key][app] = lhandler.learn(data,'label',app,self.features,self.yo)
|
||||
#
|
||||
# At this point we've already learnt every thing we need to learn
|
||||
#
|
||||
self.lock.aquire()
|
||||
writer = sef.factory.instance(type.self.write_class,args=self.rw_args)
|
||||
writer.write('learn',r)
|
||||
self.lock.release()
|
||||
|
||||
TIME_ELLAPSED = 60*120 #-- Every 2 hours
|
||||
time.sleep(TIME_ELLAPSED)
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1,14 @@
|
||||
|
||||
import os
|
||||
import json
|
||||
from utils.workers import *
|
||||
from utils.params import PARAMS
|
||||
f = open(PARAMS['path'])
|
||||
config = json.loads(f.read())
|
||||
f.close()
|
||||
from multiprocessing import Lock
|
||||
lock = Lock()
|
||||
p = Top(config,lock)
|
||||
p.daemon = True
|
||||
p.start()
|
||||
p.join()
|
Loading…
Reference in new issue