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
from utils.transport import *
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 atexit
@ -51,7 +51,7 @@ def procs(id):
try:
gReader = factory.instance(type=class_read,args=p)
data = gReader.read()
ahandler = AnomalyDetection()
ahandler = AnalyzeAnomaly()
learn = {}
for row in data['learn'] :
label = row['label']
@ -66,15 +66,19 @@ def procs(id):
# Let us determine if this is a normal operation or not
# 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:
id = row['label']
px = ahandler.predict([row],learn[id])
if px :
px = px[0]
row['anomaly'] = px[1]==1
print row
# row['anomaly'] = px[1]==1
print ""
print label,' *** ',index
row = dict(row,**px)
r[label][index] =row
#
# @TODO:
# Compile a report here that will be sent to the mailing list
@ -243,7 +247,7 @@ if __name__== '__main__':
# ThreadManager.start(CONFIG)
if 'port' not in SYS_ARGS.PARAMS :
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)

@ -8,6 +8,7 @@ monitor.processes.fetch = function(){
}
monitor.processes.init = function (x) {
var r = JSON.parse(x.responseText)
monitor.processes.summary.init(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 app = item.label
monitor.processes.trend.init(id, app)
if (item.anomaly == true) {
jx.dom.show('has_anomaly')
} else {
@ -155,7 +157,7 @@ monitor.processes.trend.render = function (logs, key,label) {
// var _y = {}
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 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){
x = new Date(item.year,item.month-1,item.day,item.hour,item.minute)
y = item[key]
@ -280,6 +282,7 @@ monitor.sandbox.init = function () {
jx.dom.hide('inspect_sandbox')
var httpclient = HttpClient.instance()
httpclient.get('/sandbox', function (x) {
var r = JSON.parse(x.responseText)
if (r.length > 0){
monitor.sandbox.render(r);

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

Loading…
Cancel
Save