jmx @TODO: Remove it and use process details

master
Steve L. Nyemba 8 years ago
parent 2c0905091b
commit f29eb0d4c0

@ -11,7 +11,7 @@ import subprocess
from sets import Set
import re
import datetime
import Queue
import urllib2 as http, base64
from threading import Thread, RLock
import time
class Analysis:
@ -66,10 +66,13 @@ class Env(Analysis):
N = len(r)
n = sum(r)
value = 100 * round(n/N,2)
print '*** ',value
missing = [self.values[i] for i in range(0,N) if r[i] == 0]
return dict(self.getNow(),**{"value":value,"missing":missing})
"""
This class is designed to handle analaysis of the a python virtual environment i.e deltas between requirments file and a virtualenv
@TODO: update the virtual environment
"""
class Sandbox(Analysis):
def __init__(self):
Analysis.__init__(self)
@ -200,14 +203,8 @@ class DetailProcess(Analysis):
status = self.status(r)
r['status'] = status
return r
#return dict(self.getNow(),**r)
def composite(self):
#Analysis.init(self)
#value = self.evaluate(self.name)
#row= {"memory_usage":value[0],"cpu_usage":value[1]}
#return row
#ma = [self.evaluate(name) for name in self.names]
def composite(self):
ma = []
now = self.getNow()
for name in self.names:
@ -216,9 +213,8 @@ class DetailProcess(Analysis):
ma += [ dict(now, **self.format(row)) for row in matrix]
#return [{"memory_usage":row[0],"cpu_usage":row[1],"memory_available":row[2]/1000,"label":row[3]} for row in ma]
return ma
class FileWatch(Analysis):
def __init__(self,conf):
pass
@ -228,10 +224,12 @@ class FileWatch(Analysis):
months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
if 'K' in x[0]:
size = x[0].replace('K','').replace('KB','') / 1000
elif 'MB' in x[0] :
elif 'M' in x[0] :
size = x[0].replace('MB','')
elif 'GB' in x[0] :
elif 'G' in x[0] :
size = x[0].replace('GB','') * 1000
elif 'T' in x[0] :
pass
month = months.index(m[1]) + 1
day = x[2]
hour,minute = x[3].split(':')
@ -244,6 +242,33 @@ class FileWatch(Analysis):
ostream = handler.communicate()[0].split('\n')
[self.split(stream) for stream in ostream if stream.strip() != '']
pass
"""
This class attempts to retrieve information form a jmxproxy
The resulting is a dataset that will be used for mining, and detection of anomalies
"""
class Jmx (Analysis):
def __init__(self,conf):
self.conf = conf
def evaluate(self,**param):
app = param['app']
r = param['host'].split('@')
host = r[1].strip()
login = base64.b64encode("%s" % (r[0]))
uri = "".join(['http://',host,'/manager/jmxproxy/?qry=*:j2eeType=Servlet,*'])
request = http.Request(uri)
request.add_header('Authorization','Basic '+login)
r = http.urlopen(request)
stream= r.read()
r.close()
self.parse(stream)
def parse(self,stream):
print stream
return {}
class Monitor (Thread):
def __init__(self,pConfig,pWriter,id='processes') :

@ -1,6 +1,6 @@
from __future__ import division
import unittest
from monitor import Env, DetailProcess, ProcessCounter, Sandbox
from monitor import Env, DetailProcess, ProcessCounter, Sandbox, Jmx
import monitor
import os
import json
@ -56,7 +56,10 @@ class TestMonitorServer(unittest.TestCase):
lock = Lock()
p = Learner(CONFIG,lock)
p.start()
def test_JMX(self):
conf =CONFIG['monitor']['jmx']
jmx = Jmx(conf)
print jmx.evaluate(host='jmx:!mx@localhost:8080',app='teamcity')
if __name__ == '__main__' :
unittest.main()

Loading…
Cancel
Save