formalizing models

community
Steve L. Nyemba 6 years ago
parent f47b1cc50f
commit 57cab8b854

@ -19,45 +19,43 @@ class model :
self.cache[key] = value self.cache[key] = value
def get(self,key): def get(self,key):
return self.cache[key] return self.cache[key]
class simple: # class simple:
class app_status(model): # class app_status(model):
""" # """
This model will perform a simple count of application status # This model will perform a simple count of application status
The intent is to quickly inform the user if there's a crash # The intent is to quickly inform the user if there's a crash
""" # """
def __init(self,**args): # def __init(self,**args):
model.__init__(self,**args) # model.__init__(self,**args)
def compute(self): # def compute(self):
""" # """
This function performs the actual counts associated with the status of an application # This function performs the actual counts associated with the status of an application
""" # """
df = self.data[df.name.str.contains('other',na=False)==False] # df = self.data[df.name.str.contains('other',na=False)==False]
x_crash = df.status.str.contains('X').sum() # x_crash = df.status.str.contains('X').sum()
x_idle = df.status.str.contains('S').sum() # x_idle = df.status.str.contains('S').sum()
x_run = df.shape[0] - x_crash - x_idle # x_run = df.shape[0] - x_crash - x_idle
odf = pd.DataFrame({"labels":['crash','idle','running'],"counts":[x_crash,x_idle,x_run]}) # odf = pd.DataFrame({"labels":['crash','idle','running'],"counts":[x_crash,x_idle,x_run]})
self.set("type","doughnut") # self.set("type","doughnut")
# self.set("labels",["crash","idle","running"]) # # self.set("labels",["crash","idle","running"])
# self.set("data",{"data":[x_crash,x_idle,x_run]}) # # self.set("data",{"data":[x_crash,x_idle,x_run]})
self.set('data',odf) # self.set('data',odf)
if x_crash > 0 : # if x_crash > 0 :
self.set("analysis"," ".join([x_crash,"applications found out of ",str(df.shape[0]),"monitored" ])) # self.set("analysis"," ".join([x_crash,"applications found out of ",str(df.shape[0]),"monitored" ]))
class app_ranking(model): # class app_resource(model):
""" # """
This model will group the applications that are monitored and the rest of the system to guage resource consumption (CPU,RAM) # 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): # def __init__(self,**args):
model.__init__(self,**args) # model.__init__(self,**args)
def compute(self): # def compute(self):
N = self.data.shape[0] - 1 # N = self.data.shape[0] - 1
df = pd.DataFrame(self.data[self.data.name == 'other'].sum()[['cpu','mem']] ) .T # 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 = df.append(pd.DataFrame( self.data[self.data.name != 'other'].sum()[['cpu','mem']] ).T)
df['labels'] = ['other','monitored'] # df['labels'] = ['other','monitored']
# other_df = pd.DataFrame(self.data[self.data.name.str.contains('other',na=False)]) # # 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]) # # 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()]] # # datasets = [[other_df.cpu.sum(),watch_df.cpu.sum()],[other_df.mem.sum(),watch_df.mem.sum()]]
self.set("data",odf) # self.set("data",df)
self.set("type","bar") # self.set("type","bar")

@ -0,0 +1,70 @@
"""
(c) 2018 Smart Top - Free Models
Steve L. Nyemba, steve@the-phi.com
This file contains free models for smart-top, these are basic models that will serve as data visualization
The most we will do here is a basic regression (basis for prediction).
@TODO: Include process counts in the equation so as to add another variable (good for ml)
"""
from models.basic import model
class 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 resource(model):
"""
This model will group the applications that are monitored and the rest of the system to guage resource consumption (CPU,RAM)
The intent of this model is to see how resource intensive the selected applications are relative to the rest of the system
"""
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']
self.set("data",df)
self.set("type","bar")
class trend(model):
"""
This model is designed to display the trends for a given attribute over a period of time
Additionally there will be a regression line associated with it
"""
def __init__(self,**args):
model.__init__(self,**args)
self.attr_name = args['name']
self.attr_values= args['values']
def compute(self):
df = self.data[self.data[self.attr_name].isin(self.attr_values)]
cols = ['cpu','mem']
pass
model = keras.Sequential([keras.layers.Dense(2, activation=tf.nn.relu,input_shape=(x.shape[1],)),keras.layers.Dense(2, activation=tf.nn.relu),keras.layers.Dense(1)])
optimizer = tf.train.RMSPropOptimizer(0.001)
model.compile(loss='mse', optimizer=optimizer,metrics=['mae'])

@ -0,0 +1,10 @@
"""
(c) 2018 Smart-Top, Paid Models
Steve L. Nyemba <steve@the-phi.com>
The Paid models are largely based around machine learning and will deliver insights into :
- Anomaly detection
- Clustering
- And Crash Prediction (regression)
"""
Loading…
Cancel
Save