os.unlink( self._filename )
class MonitoringInfo:
- def __init__(self, pyFileName, outFileName, pid):
+ def __init__(self, pyFileName, intervalInMs, outFileName, pid):
self._py_file_name = pyFileName
+ self._interval_in_ms = intervalInMs
self._out_file_name = outFileName
self._pid = pid
def outFileName(self):
return self._out_file_name
+ @property
+ def intervalInMs(self):
+ return self._interval_in_ms
+
def FileSystemMonitoring(intervalInMs, dirNameToInspect, outFileName = None):
"""
This method loops indefinitely every intervalInMs milliseconds to scan
import datetime
with open("{tempOutFile}","a") as f:
f.write( "{{}}\\n".format( "{dirNameToInspect2}" ) )
+ f.write( "{{}}\\n".format( "{intervalInMs}" ) )
while(True):
nbinodes = sp.check_output("{{}} | wc -l".format( " ".join(["find","{dirNameToInspect2}"]), ), shell = True).decode().strip()
szOfDirStr = re.split("[\s]+",sp.check_output(["du","-sh","{dirNameToInspect2}"]).decode())[0]
outFileName = FileDeleter( tempOutFile )
else:
outFileName = FileHolder(outFileName)
- return MonitoringInfo(pyFileName,outFileName,None)
+ return MonitoringInfo(pyFileName, intervalInMs, outFileName, None)
def CPUMemoryMonitoring( intervalInMs, outFileName = None ):
"""
process = psutil.Process( pid )
import time
with open("{}","a") as f:
+ f.write( "{{}}\\n".format( "{}" ) )
while True:
f.write( "{{}}\\n".format( str( process.cpu_percent() ) ) )
f.write( "{{}}\\n".format( str( process.memory_info().rss ) ) )
f.flush()
time.sleep( {} / 1000.0 )
-""".format(pid, tempOutFile, intervalInMs))
+""".format(pid, tempOutFile, intervalInMs, intervalInMs))
if outFileName is None:
autoOutFile = FileDeleter(tempOutFile)
else:
autoOutFile = FileHolder(tempOutFile)
return FileDeleter(tempPyFile),autoOutFile
pyFileName, outFileName = BuildPythonFileForCPUPercent( intervalInMs, outFileName )
- return MonitoringInfo(pyFileName, outFileName, None)
+ return MonitoringInfo(pyFileName, intervalInMs, outFileName, None)
class GenericPythonMonitoringLauncherCtxMgr:
def __init__(self, monitoringParams):
import KernelBasis
KernelBasis.StopMonitoring(monitoringInfo.pid)
+class CPUMemInfo:
+ def __init__(self, intervalInMs, cpu, mem_rss):
+ """
+ Args:
+ ----
+ intervalInMs (int)
+ cpu (list<float>) CPU usage
+ mem_rss (list<int>) rss memory usage
+ """
+ self._interval_in_ms = intervalInMs
+ self._data = [(a,b) for a,b in zip(cpu,mem_rss)]
+ def __str__(self):
+ st = """Interval in ms : {self.intervalInMs}
+Data : ${self.data}
+""".format( **locals() )
+ return st
+ @property
+ def intervalInMs(self):
+ return self._interval_in_ms
+ @property
+ def data(self):
+ """
+ list of triplets. First param of pair is cpu usage
+ Second param of pair is memory usage
+ """
+ return self._data
+
def ReadCPUMemInfoInternal( fileName ):
- import KernelBasis
- ret = KernelBasis.ReadFloatsInFile( fileName )
- cpu = ret[::2]
- mem_rss = [ int(elt) for elt in ret[1::2]]
- return [(a,b) for a,b in zip(cpu,mem_rss)]
+ with open(fileName, "r") as f:
+ coarseData = [ elt.strip() for elt in f.readlines() ]
+ intervalInMs = int( coarseData[0] )
+ coarseData = coarseData[1:]
+ cpu = [float(elt) for elt in coarseData[::2]]
+ mem_rss = [ int(elt) for elt in coarseData[1::2]]
+ return CPUMemInfo(intervalInMs,cpu,mem_rss)
def ReadCPUMemInfo( monitoringInfo ):
"""
Returns
-------
- list<float,str> : list of pairs. First param of pair is CPU usage. Second param of pair is rss memory usage
+ CPUMemInfo instance
"""
return ReadCPUMemInfoInternal( monitoringInfo.outFileName.filename )
class InodeSizeInfo:
- def __init__(self, dirNameMonitored, timeStamps, nbInodes, volumeOfDir):
+ def __init__(self, dirNameMonitored, intervalInMs, timeStamps, nbInodes, volumeOfDir):
"""
Args:
----
volumeOfDir (list<str>)
"""
self._dir_name_monitored = dirNameMonitored
+ self._interval_in_ms = intervalInMs
self._data = [(t,a,b) for t,a,b in zip(timeStamps,nbInodes,volumeOfDir)]
def __str__(self):
st = """Filename monitored : {self.dirNameMonitored}
+Interval in ms : ${self.intervalInMs}
Data : ${self.data}
""".format( **locals() )
return st
def dirNameMonitored(self):
return self._dir_name_monitored
@property
+ def intervalInMs(self):
+ return self._interval_in_ms
+ @property
def data(self):
"""
list of triplets. First param of triplet is datetimestruct
import os
with open(fileName, "r") as f:
coarseData = [ elt.strip() for elt in f.readlines() ]
- dirNameMonitored = coarseData[0] ; coarseData = coarseData[1:]
+ dirNameMonitored = coarseData[0] ; intervalInMs = int( coarseData[1] ) ; coarseData = coarseData[2:]
tss = [ datetime.datetime.fromtimestamp( float(elt) ) for elt in coarseData[::3] ]
nbInodes = [int(elt) for elt in coarseData[1::3]]
volumeOfDir = coarseData[2::3]
- return InodeSizeInfo(dirNameMonitored,tss,nbInodes,volumeOfDir)
+ return InodeSizeInfo(dirNameMonitored,intervalInMs,tss,nbInodes,volumeOfDir)
def ReadInodeSizeInfo( monitoringInfo ):
"""