basic monitoring functions implemented @TODO aggregate the basics

master
Steve L. Nyemba 8 years ago
parent 2d545423d7
commit 55b62aba21

@ -86,20 +86,24 @@ class Sandbox(Analysis):
This class performs the analysis of a list of processes and determines
The class provides a quantifiable measure of how many processes it found over all
"""
class Processes(Analysis):
class ProcessCounter(Analysis):
def __init__(self,names):
Analysis.__init__(self)
self.names = names
def evaluate(self,name):
cmd = "".join(['ps aux |grep -E "^ {0,}',name,'" |wc -l'])
cmd = "".join(['ps -eo comm |grep ',name,' |wc -l'])
handler = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
return int(handler.communicate()[0].replace('\n','')) > 0
return int(handler.communicate()[0].replace("\n","") )
def composite(self):
r = [ self.evaluate(name) for name in self.names]
N = len(r)
n = sum(r)
return n/N
r = {}
for name in self.names :
r[name] = self.evaluate(name)
#N = len(r)
#n = sum(r)
#return n/N
return r
"""
This class returns an application's both memory and cpu usage
"""

@ -1,6 +1,6 @@
from __future__ import division
import unittest
from monitor import Env, DetailProcess
from monitor import Env, DetailProcess, ProcessCounter
class TestMonitorServer(unittest.TestCase):
@ -14,6 +14,14 @@ class TestMonitorServer(unittest.TestCase):
self.assertTrue(p.evaluate('PATH') == 0)
def test_RunningProcess(self):
p = DetailProcess(['rabbitmq-server','python'])
print p.composite()
r = p.composite()
print r
self.assertTrue(r)
def test_ProcessCount(self):
p= ProcessCounter(['apache2','VBoxClient','rabbitmq-server','foo'])
r = p.composite()
self.assertTrue( sum(r.values()) > 0 )
self.assertTrue( r['foo'] == 0)
if __name__ == '__main__' :
unittest.main()
Loading…
Cancel
Save