From f47b1cc50f97cd38e45edb3bef4297a7282a8750 Mon Sep 17 00:00:00 2001 From: "Steve L. Nyemba -- The Architect" Date: Tue, 13 Nov 2018 13:36:56 -0600 Subject: [PATCH] bug fix and layout fix --- src/api/templates/dashboard/graphs/chart.html | 12 ++-- src/models/basic.py | 63 +++++++++++++++++++ 2 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 src/models/basic.py diff --git a/src/api/templates/dashboard/graphs/chart.html b/src/api/templates/dashboard/graphs/chart.html index 40f4c21..b8cdaca 100644 --- a/src/api/templates/dashboard/graphs/chart.html +++ b/src/api/templates/dashboard/graphs/chart.html @@ -32,17 +32,19 @@
{% endif %} {% for config in info %} - {% if info|length > 1%} -
+ {% if info|length > 1 %} +
{% else %}
{% endif %}
{{config.title}}
-
-
{{config.info}} -
+ {% if config.info %} +
+
{{config.info}} +
+ {% endif %} diff --git a/src/models/basic.py b/src/models/basic.py new file mode 100644 index 0000000..f8a41be --- /dev/null +++ b/src/models/basic.py @@ -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") + + \ No newline at end of file