|
@@ -23,40 +23,17 @@ import monitor
|
|
|
import Queue
|
|
|
from utils.transport import *
|
|
|
from utils.workers import ThreadManager, Factory
|
|
|
+from utils.ml import ML,AnomalyDetection
|
|
|
+import utils.params as SYS_ARGS
|
|
|
import atexit
|
|
|
-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
|
|
|
-
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
app.config['SECRET_KEY'] = '!h8-[0v8]247-4-360'
|
|
|
#app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX=?RT'
|
|
|
|
|
|
-
|
|
|
+PARAMS = SYS_ARGS.PARAMS
|
|
|
f = open(PARAMS['path'])
|
|
|
CONFIG = json.loads(f.read())
|
|
|
-#HANDLERS= {}
|
|
|
-
|
|
|
-#for key in CONFIG['monitor'] :
|
|
|
-
|
|
|
- #className = CONFIG['monitor'][key]['class']
|
|
|
- #ref = "".join(["monitor.",className,"()"])
|
|
|
- #ref = eval(ref)
|
|
|
- #HANDLERS[key] = {"class":ref,"config":CONFIG['monitor'][key]["config"]}
|
|
|
-
|
|
|
f.close()
|
|
|
|
|
|
#
|
|
@@ -66,12 +43,7 @@ p = CONFIG['store']['args']
|
|
|
class_read = CONFIG['store']['class']['read']
|
|
|
class_write= CONFIG['store']['class']['write']
|
|
|
factory = DataSourceFactory()
|
|
|
-#gWriter = factory.instance(type='CouchdbWritera',args=p)
|
|
|
-#gReader = factory.instance(type='CouchdbReader',args=p)
|
|
|
-#p['qid'] = HANDLERS['processes']['config'].keys()
|
|
|
gReader = factory.instance(type=class_read,args=p)
|
|
|
-#gWriter = factory.instance(type=class_write,args=p)
|
|
|
-#mthread = monitor.Monitor(HANDLERS,gWriter,'processes',)
|
|
|
|
|
|
atexit.register(ThreadManager.stop)
|
|
|
@app.route('/get/<id>')
|
|
@@ -82,9 +54,13 @@ def procs(id):
|
|
|
|
|
|
r = {}
|
|
|
for label in d :
|
|
|
- index = len(d[label]) - 1
|
|
|
- r[label] = d[label][index]
|
|
|
-
|
|
|
+ if label not in ['learn'] :
|
|
|
+ index = len(d[label]) - 1
|
|
|
+ r[label] = d[label][index]
|
|
|
+ #for row in r[label] :
|
|
|
+ #yo = ML.Extract(['status'],row)
|
|
|
+ #xo = ML.Extract(['cpu_usage','memory_usage'],row)
|
|
|
+
|
|
|
except Exception, e:
|
|
|
print e
|
|
|
r = []
|
|
@@ -122,13 +98,14 @@ def trends ():
|
|
|
p = CONFIG['store']['args']
|
|
|
class_read = CONFIG['store']['class']['read']
|
|
|
|
|
|
- p['qid'] =[id] #HANDLERS['processes']['config'].keys()
|
|
|
+
|
|
|
gReader = factory.instance(type=class_read,args=p)
|
|
|
|
|
|
r = gReader.read()
|
|
|
if id in r:
|
|
|
r = r[id] #--matrix
|
|
|
series = []
|
|
|
+
|
|
|
for row in r:
|
|
|
|
|
|
series += [item for item in row if str(item['label'])== app]
|
|
@@ -156,19 +133,37 @@ def dashboard():
|
|
|
"""
|
|
|
@app.route('/learn')
|
|
|
def learn():
|
|
|
- app = request.args.get('app')
|
|
|
- id = request.args.get('id')
|
|
|
+ global CONFIG
|
|
|
p = CONFIG['store']['args']
|
|
|
- class_read = CONFIG['store']['class']['read']
|
|
|
-
|
|
|
- p['qid'] =[id] #HANDLERS['processes']['config'].keys()
|
|
|
+ class_read = CONFIG['store']['class']['read']
|
|
|
gReader = factory.instance(type=class_read,args=p)
|
|
|
-
|
|
|
- r = gReader.read()
|
|
|
- r = r[id]
|
|
|
- r = ML.Filter('label',app,r)
|
|
|
- label = ML.Extract(['status'],r)
|
|
|
- r = ML.Extract(['cpu_usage','memory_usage'],r)
|
|
|
+ d = gReader.read()
|
|
|
+ if 'learn' in d :
|
|
|
+ logs = d['learn']
|
|
|
+ del d['learn']
|
|
|
+ else :
|
|
|
+ logs = []
|
|
|
+ r = []
|
|
|
+ if 'id' in request.args:
|
|
|
+ id = request.args['id']
|
|
|
+ d = d[id]
|
|
|
+ print CONFIG['monitor']['processes']['config'][id]
|
|
|
+ print (apps)
|
|
|
+
|
|
|
+
|
|
|
+ #apps = list(set(ML.Extract(['label'],d)))
|
|
|
+ p = AnomalyDetection()
|
|
|
+ #for row in d :
|
|
|
+ #xo = ML.Filter('label',app,d)
|
|
|
+ #info = ML.Filter('label',app,logs)
|
|
|
+ #value = p.predict(xo,info)
|
|
|
+ #print app,value
|
|
|
+ #if value is not None:
|
|
|
+ # r.append(value)
|
|
|
+ print r
|
|
|
+ return json.dumps("[]")
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@app.route('/anomalies/status')
|
|
|
def anomalies_status():
|
|
@@ -180,7 +175,7 @@ def anomalies_get():
|
|
|
|
|
|
if __name__== '__main__':
|
|
|
|
|
|
- ThreadManager.start(CONFIG)
|
|
|
+ #ThreadManager.start(CONFIG)
|
|
|
app.run(host='0.0.0.0',debug=True,threaded=True)
|
|
|
|
|
|
|