parent
9d61485274
commit
f47b1cc50f
@ -0,0 +1,63 @@
|
||||
""""
|
||||
This class defines the basic structure for a model, models can be either statistical or machine learning
|
||||
and will be tightly coupled with the rendering engines (matplotlib or chartjs)
|
||||
""""
|
||||
|
||||
class model :
|
||||
def __init__(**args):
|
||||
self.data = args['data']
|
||||
self.node = args['node']
|
||||
self.months = {1:"Jan",2:"Feb",3:"Mar",4:"Apr",5:"May",6:"Jun",7:"Jul",8:"Aug",9:"Sep",10:"Oct",11:"Nov",12:"Dec"}
|
||||
self.cache = {}
|
||||
def can_do(self):
|
||||
return False
|
||||
def format_date(self,row):
|
||||
m = {1:"Jan",2:"Feb",3:"Mar",4:"Apr",5:"May",6:"Jun",7:"Jul",8:"Aug",9:"Sep",10:"Oct",11:"Nov",12:"Dec"}
|
||||
return "-".join([m[row['month']],str(row['day']),str(row['year'])]) +" "+ " ".join([str(row['hour']),'h :',str(row['minute']),'min' ])
|
||||
|
||||
def set(self,key,value):
|
||||
self.cache[key] = value
|
||||
def get(self,key):
|
||||
return self.cache[key]
|
||||
class simple:
|
||||
class app_status(model):
|
||||
"""
|
||||
This model will perform a simple count of application status
|
||||
The intent is to quickly inform the user if there's a crash
|
||||
"""
|
||||
def __init(self,**args):
|
||||
model.__init__(self,**args)
|
||||
def compute(self):
|
||||
"""
|
||||
This function performs the actual counts associated with the status of an application
|
||||
"""
|
||||
df = self.data[df.name.str.contains('other',na=False)==False]
|
||||
x_crash = df.status.str.contains('X').sum()
|
||||
x_idle = df.status.str.contains('S').sum()
|
||||
x_run = df.shape[0] - x_crash - x_idle
|
||||
odf = pd.DataFrame({"labels":['crash','idle','running'],"counts":[x_crash,x_idle,x_run]})
|
||||
self.set("type","doughnut")
|
||||
# self.set("labels",["crash","idle","running"])
|
||||
# self.set("data",{"data":[x_crash,x_idle,x_run]})
|
||||
self.set('data',odf)
|
||||
if x_crash > 0 :
|
||||
self.set("analysis"," ".join([x_crash,"applications found out of ",str(df.shape[0]),"monitored" ]))
|
||||
class app_ranking(model):
|
||||
"""
|
||||
This model will group the applications that are monitored and the rest of the system to guage resource consumption (CPU,RAM)
|
||||
"""
|
||||
def __init__(self,**args):
|
||||
model.__init__(self,**args)
|
||||
def compute(self):
|
||||
N = self.data.shape[0] - 1
|
||||
|
||||
df = pd.DataFrame(self.data[self.data.name == 'other'].sum()[['cpu','mem']] ) .T
|
||||
df = df.append(pd.DataFrame( self.data[self.data.name != 'other'].sum()[['cpu','mem']] ).T)
|
||||
df['labels'] = ['other','monitored']
|
||||
# other_df = pd.DataFrame(self.data[self.data.name.str.contains('other',na=False)])
|
||||
# watch_df = pd.DataFrame(self.data[self.data.name.str.contains('other',na=False)==False])
|
||||
# datasets = [[other_df.cpu.sum(),watch_df.cpu.sum()],[other_df.mem.sum(),watch_df.mem.sum()]]
|
||||
self.set("data",odf)
|
||||
self.set("type","bar")
|
||||
|
||||
|
Loading…
Reference in new issue