analysis of anomalies @TODO: road test

master
Steve L. Nyemba 8 years ago
parent 8c47d28c44
commit 584cc86b56

@ -23,7 +23,7 @@ import monitor
import Queue import Queue
from utils.transport import * from utils.transport import *
from utils.workers import ThreadManager, Factory from utils.workers import ThreadManager, Factory
from utils.ml import ML,AnomalyDetection from utils.ml import ML,AnomalyDetection,AnalyzeAnomaly
import utils.params as SYS_ARGS import utils.params as SYS_ARGS
import atexit import atexit
@ -51,7 +51,7 @@ def procs(id):
try: try:
gReader = factory.instance(type=class_read,args=p) gReader = factory.instance(type=class_read,args=p)
data = gReader.read() data = gReader.read()
ahandler = AnomalyDetection() ahandler = AnalyzeAnomaly()
learn = {} learn = {}
for row in data['learn'] : for row in data['learn'] :
label = row['label'] label = row['label']
@ -66,15 +66,19 @@ def procs(id):
# Let us determine if this is a normal operation or not # Let us determine if this is a normal operation or not
# We will update the status of the information ... # We will update the status of the information ...
# #
for row in r[label] :
for row in r[label] :
index = r[label].index(row)
if row['label'] in learn: if row['label'] in learn:
id = row['label'] id = row['label']
px = ahandler.predict([row],learn[id]) px = ahandler.predict([row],learn[id])
if px : if px :
px = px[0]
row['anomaly'] = px[1]==1 # row['anomaly'] = px[1]==1
print row print ""
print label,' *** ',index
row = dict(row,**px)
r[label][index] =row
# #
# @TODO: # @TODO:
# Compile a report here that will be sent to the mailing list # Compile a report here that will be sent to the mailing list
@ -243,7 +247,7 @@ if __name__== '__main__':
# ThreadManager.start(CONFIG) # ThreadManager.start(CONFIG)
if 'port' not in SYS_ARGS.PARAMS : if 'port' not in SYS_ARGS.PARAMS :
SYS_ARGS.PARAMS['port'] = 5000 SYS_ARGS.PARAMS['port'] = 5000
PORT = SYS_ARGS.PARAMS['port'] PORT = int(SYS_ARGS.PARAMS['port'])
app.run(host='0.0.0.0',port=PORT,debug=True,threaded=True) app.run(host='0.0.0.0',port=PORT,debug=True,threaded=True)

@ -7,7 +7,8 @@ monitor.processes.fetch = function(){
} }
monitor.processes.init = function(x){ monitor.processes.init = function (x) {
var r = JSON.parse(x.responseText) var r = JSON.parse(x.responseText)
monitor.processes.summary.init(r) monitor.processes.summary.init(r)
var keys = jx.utils.keys(r) var keys = jx.utils.keys(r)
@ -79,6 +80,7 @@ monitor.processes.render = function(label,data) {
var id = jx.dom.get.value('latest_processes_label') var id = jx.dom.get.value('latest_processes_label')
var app = item.label var app = item.label
monitor.processes.trend.init(id, app) monitor.processes.trend.init(id, app)
if (item.anomaly == true) { if (item.anomaly == true) {
jx.dom.show('has_anomaly') jx.dom.show('has_anomaly')
} else { } else {
@ -155,7 +157,7 @@ monitor.processes.trend.render = function (logs, key,label) {
// var _y = {} // var _y = {}
var cpu = {yAxisID:'0', label: 'CPU Usage (%)', data: [] ,backgroundColor:'transparent',borderColor:COLORS[187],fill:false,borderWidth:1} var cpu = {yAxisID:'0', label: 'CPU Usage (%)', data: [] ,backgroundColor:'transparent',borderColor:COLORS[187],fill:false,borderWidth:1}
var mem = {yAxisID:'0',label : 'Memory Usage(%)',data:[],backgroundColor:'transparent',borderColor:COLORS[32],fill:false,borderWidth:1} var mem = {yAxisID:'0',label : 'Memory Usage(%)',data:[],backgroundColor:'transparent',borderColor:COLORS[32],fill:false,borderWidth:1}
var proc= {yAxisID:'1',label : 'Proc Count',data:[],backgroundColor:'transparent',borderColor:COLORS[42],fill:false,borderWidth:1} var proc= {yAxisID:'1',label : 'Proc Count',data:[],backgroundColor:'transparent',borderColor:COLORS[542],fill:false,borderWidth:1}
jx.utils.patterns.visitor(logs,function(item){ jx.utils.patterns.visitor(logs,function(item){
x = new Date(item.year,item.month-1,item.day,item.hour,item.minute) x = new Date(item.year,item.month-1,item.day,item.hour,item.minute)
y = item[key] y = item[key]
@ -280,6 +282,7 @@ monitor.sandbox.init = function () {
jx.dom.hide('inspect_sandbox') jx.dom.hide('inspect_sandbox')
var httpclient = HttpClient.instance() var httpclient = HttpClient.instance()
httpclient.get('/sandbox', function (x) { httpclient.get('/sandbox', function (x) {
var r = JSON.parse(x.responseText) var r = JSON.parse(x.responseText)
if (r.length > 0){ if (r.length > 0){
monitor.sandbox.render(r); monitor.sandbox.render(r);

@ -1,5 +1,5 @@
from utils import transport from utils import transport
from utils.ml import ML, AnomalyDetection from utils.ml import ML, AnomalyDetection, AnalyzeAnomaly
import unittest import unittest
import json import json
import os import os
@ -57,7 +57,7 @@ class TestML(unittest.TestCase):
features = CONFIG['learner']['anomalies']['features'] features = CONFIG['learner']['anomalies']['features']
label = CONFIG['learner']['anomalies']['label'] label = CONFIG['learner']['anomalies']['label']
x = lhandler.learn(data,'label',app,features,label) x = lhandler.learn(data,'label',app,features,label)
print x
def test_Predict(self): def test_Predict(self):
ref = CONFIG['store']['class']['read'] ref = CONFIG['store']['class']['read']
@ -68,14 +68,16 @@ class TestML(unittest.TestCase):
info = data['learn'] info = data['learn']
app = CONFIG['monitor']['processes']['config']['apps'][0] app = CONFIG['monitor']['processes']['config']['apps'][0]
print [app]
lhandler = AnomalyDetection() lhandler = AnalyzeAnomaly()
features = CONFIG['learner']['anomalies']['features'] features = CONFIG['learner']['anomalies']['features']
label = CONFIG['learner']['anomalies']['label'] label = CONFIG['learner']['anomalies']['label']
#x = lhandler.learn(data,'label',app,features,label) #x = lhandler.learn(data,'label',app,features,label)
data = data['apps'] data = data['apps']
xo = ML.Filter('label',app,data) xo = ML.Filter('label',app,data)
print app,xo info = ML.Filter('label',app,info)
lhandler.predict(xo,info[0])
if __name__ == '__main__' : if __name__ == '__main__' :
unittest.main() unittest.main()

Loading…
Cancel
Save