def makeKPIsN(path, file, hostKPIs, srvcKPIs, kpiStylesN, grpname='Custom'): log('loading custom kpis file: %s' % (os.path.join(path, file))) try: f = open(os.path.join(path, file), 'r') kpiFile = safe_load(f) #except parser.ParserError as e: except Exception as e: log('Error loading custom KPI file %s: %s' % (os.path.join(path, file), str(e))) raise e kpis = kpiFile['kpis'] grpname = '.' + grpname srcIdx = file customSql[srcIdx] = kpiFile['sql'] for kpi in kpis: type = kpi['type'] csName = 'cs-' + kpi['name'] if not grpname in grouplist[type]: grouplist[type].append(grpname) if type == 'host': hostKPIs.append(grpname) else: srvcKPIs.append(grpname) if type == 'host': hostKPIs.append(csName) else: srvcKPIs.append(csName) if csName in kpiStylesN[type]: log('[W] this custom KPI already exists: %s' % (csName)) else: kpiStylesN[type][csName] = createStyle(kpi, True, srcIdx)
def initHosts(self, hosts, hostKPIs, srvcKPIs): kpiDummy = { 'hierarchy': '1', 'type': 'service', 'name': 'cpu', 'group': 'cpu', 'label': 'CPU', 'description': 'Service CPU', 'sUnit': '%', 'dUnit': '%', 'color': '#F00', 'style': 'solid' } kpiDummyMem = { 'hierarchy': '2', 'type': 'service', 'name': 'indexserverMemUsed', 'group': 'mem', 'sUnit': 'Byte/sample', 'dUnit': 'MB/sec', 'label': 'Memory used', 'description': 'Service Memory Usage', 'color': '#0D0', 'style': 'solid' } kpiDescriptions.kpiStylesNN['service'][ 'cpu'] = kpiDescriptions.createStyle(kpiDummy) kpiDescriptions.kpiStylesNN['service'][ 'indexserverMemUsed'] = kpiDescriptions.createStyle(kpiDummyMem) kpiDummy['type'] = 'host' kpiDummy['style'] = 'dashed' kpiDummy['description'] = 'Host CPU' kpiDescriptions.kpiStylesNN['host'][ 'cpu'] = kpiDescriptions.createStyle(kpiDummy) hostKPIs.append('cpu') srvcKPIs.append('cpu') srvcKPIs.append('indexserverMemUsed') #srvcKPIs.append('memory_allocation_limit') stime = datetime.datetime.now() - datetime.timedelta(seconds=18 * 3600) stime -= datetime.timedelta(seconds=stime.timestamp() % 3600) #etime = stime + datetime.timedelta(seconds = 5*3600) etime = datetime.datetime.now() hosts.append({ 'host': 'dummy1', 'port': '', 'from': stime, 'to': etime }) hosts.append({ 'host': 'dummy1', 'port': '30040', 'from': stime, 'to': etime }) hosts.append({ 'host': 'dummy1', 'port': '30041', 'from': stime, 'to': etime }) if cfg('experimental'): dpDBCustom.scanKPIsN(hostKPIs, srvcKPIs, kpiDescriptions.kpiStylesNN)
def initHosts(self, hosts, hostKPIs, srvcKPIs): # kpis_sql = 'select view_name, column_name, display_line_color, display_line_style from m_load_history_info order by display_hierarchy' #kpis_sql = 'select view_name, column_name from m_load_history_info order by display_hierarchy' kpis_sql = sql.kpis_info if not self.connection: log('no db connection...') return log('init hosts: %s' % str(hosts)) log('init hosts, hostKPIs: %s' % str(hostKPIs)) log('init hosts, srvcKPIs: %s' % str(srvcKPIs)) sql_string = sql.hosts_info t0 = time.time() rows = db.execute_query(self.connection, sql_string) for i in range(0, len(rows)): hosts.append({ 'host': rows[i][0], 'port': rows[i][1], 'from': rows[i][2], 'to': rows[i][3] }) rows = db.execute_query(self.connection, kpis_sql) for kpi in rows: if kpi[1].lower() == 'm_load_history_host': type = 'host' else: type = 'service' if kpi[1] == '': #hierarchy nodes if len(kpi[0]) == 1: continue # top level hierarchy node (Host/Service) else: # Normal hierarchy node kpiName = '.' + kpi[4] else: kpiName = kpi[2].lower() kpiDummy = { 'hierarchy': kpi[0], 'type': type, 'name': kpiName, 'group': kpi[3], 'label': kpi[4], 'description': kpi[5], 'sUnit': kpi[6], 'dUnit': kpi[7], 'color': kpi[8], 'style': kpiDescriptions.nsStyle(kpi[9]) } kpiStylesNN[type][kpiName] = kpiDescriptions.createStyle( kpiDummy) if kpi[1].lower() == 'm_load_history_host': hostKPIs.append(kpiName) else: srvcKPIs.append(kpiName) t1 = time.time() if cfg('experimental'): dpDBCustom.scanKPIsN(hostKPIs, srvcKPIs, kpiDescriptions.kpiStylesNN) t2 = time.time() kpiDescriptions.clarifyGroups() log('hostsInit time: %s/%s' % (str(round(t1 - t0, 3)), str(round(t2 - t1, 3))))
def initHosts(self, hosts, hostKPIs, srvcKPIs): kpiDummy = { 'hierarchy': '1', 'type': 'service', 'name': 'cpu', 'group': 'cpu', 'label': 'CPU', 'description': 'Service CPU', 'sUnit': '%', 'dUnit': '%', 'color': '#F00', 'style': 'solid' } kpiDummyMem = { 'hierarchy': '2', 'type': 'service', 'name': 'indexserverMemUsed', 'group': 'mem', 'sUnit': 'Byte', 'dUnit': 'MB', 'label': 'Memory used', 'description': 'Service Memory Usage', 'color': '#0D0', 'style': 'solid' } kpiDescriptions.kpiStylesNN['service'][ 'cpu'] = kpiDescriptions.createStyle(kpiDummy) kpiDescriptions.kpiStylesNN['service'][ 'indexserverMemUsed'] = kpiDescriptions.createStyle(kpiDummyMem) kpiDummy['type'] = 'host' kpiDummy['style'] = 'dashed' kpiDummy['description'] = 'Host CPU' kpiDescriptions.kpiStylesNN['host'][ 'cpu'] = kpiDescriptions.createStyle(kpiDummy) hostKPIs.append('cpu') srvcKPIs.append('cpu') srvcKPIs.append('indexserverMemUsed') #srvcKPIs.append('memory_allocation_limit') stime = datetime.datetime.now() - datetime.timedelta(seconds=18 * 3600) stime -= datetime.timedelta(seconds=stime.timestamp() % 3600) #etime = stime + datetime.timedelta(seconds = 5*3600) etime = datetime.datetime.now() hosts.append({ 'host': 'dummy1', 'port': '', 'from': stime, 'to': etime }) hosts.append({ 'host': 'dummy1', 'port': '30040', 'from': stime, 'to': etime }) hosts.append({ 'host': 'dummy1', 'port': '30041', 'from': stime, 'to': etime }) try: dpDBCustom.scanKPIsN(hostKPIs, srvcKPIs, kpiDescriptions.kpiStylesNN) except Exception as e: kpiDescriptions.removeDeadKPIs(srvcKPIs, 'service') kpiDescriptions.removeDeadKPIs(hostKPIs, 'host') msgDialog( 'Custom KPIs Error', 'There were errors during custom KPIs load.\n\n' + str(e))