コード例 #1
0
ファイル: dpDB.py プロジェクト: rybafish/rybafish
    def initHosts(self, hosts, hostKPIs, srvcKPIs):

        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, [])

        if cfg('hostmapping'):
            for i in range(0, len(rows)):

                hm = cfg('hostmapping')
                pm = cfg('portmapping')

                hosts.append({
                    'host': rows[i][0].replace(hm[0], hm[1]),
                    'port': rows[i][1].replace(pm[0], pm[1]),
                    'from': rows[i][2],
                    'to': rows[i][3]
                })
        else:
            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, [])

        kpiDescriptions.initKPIDescriptions(rows, hostKPIs, srvcKPIs)

        t1 = time.time()

        try:
            dpDBCustom.scanKPIsN(hostKPIs, srvcKPIs,
                                 kpiDescriptions.kpiStylesNN)
        except Exception as e:
            log('[e] error loading custom kpis')
            log('[e] fix or delete the problemmatic yaml for proper connect')
            raise e

        t2 = time.time()

        kpiDescriptions.clarifyGroups()

        log('hostsInit time: %s/%s' %
            (str(round(t1 - t0, 3)), str(round(t2 - t1, 3))))
コード例 #2
0
ファイル: hslWindow.py プロジェクト: jbiju94/rybafish
    def menuReloadCustomKPIs(self):
    
        kpiStylesNN = kpiDescriptions.kpiStylesNN
        
        for type in ('host', 'service'):
            for kpiName in list(kpiStylesNN[type]):

                kpi = kpiStylesNN[type][kpiName]
                
                if kpi['sql'] is not None:
                    del(kpiStylesNN[type][kpiName])
                    
                    if type == 'host':
                        self.chartArea.hostKPIs.remove(kpiName)
                    else:
                        self.chartArea.srvcKPIs.remove(kpiName)
        
        # del host custom groups
        for i in range(len(self.chartArea.hostKPIs)):
            if self.chartArea.hostKPIs[i][:1] == '.' and (i == len(self.chartArea.hostKPIs) - 1 or self.chartArea.hostKPIs[i+1][:1] == '.'):
                del(self.chartArea.hostKPIs[i])

        # del service custom groups
        for i in range(len(self.chartArea.srvcKPIs)):
            if self.chartArea.srvcKPIs[i][:1] == '.' and (i == len(self.chartArea.srvcKPIs) - 1 or self.chartArea.srvcKPIs[i+1][:1] == '.'):
                del(self.chartArea.srvcKPIs[i])

        dpDBCustom.scanKPIsN(self.chartArea.hostKPIs, self.chartArea.srvcKPIs, kpiStylesNN)
        self.chartArea.widget.initPens()
        self.chartArea.widget.update()
        
        #really unsure if this one can be called twice...
        kpiDescriptions.clarifyGroups()
        
        #trigger refill        
        self.kpisTable.refill(self.hostTable.currentRow())
        
        self.statusMessage('Custom KPIs reload finish', False)
コード例 #3
0
    def initHosts(self, hosts, hostKPIs, srvcKPIs):
        '''
            performs initial load, extract hosts and metadata
            
            plus actual KPIs data loaded and calculated
            
            KPIDescriptions? not sure
            
        '''

        max_lines = 0
        row_len = 0

        ii = {}  # row counter per port

        data = self.data

        for filename in self.files:
            t0 = time.time()

            if max_lines > 0:
                trace_lines = max_lines
            else:
                trace_lines = len(open(filename).readlines())

            f = open(filename)

            #scan first lines to count number of ports
            i = -1
            host = ''
            for line in f:
                row = line.rstrip().split(';')

                if i == -1:  # header row
                    #titles = row

                    titles = []

                    for r in row:
                        titles.append(r.lower())

                    row_len = len(row)

                    if 'port' in titles:
                        portIdx = titles.index('port')
                    elif 'tenant' in titles:
                        portIdx = titles.index('tenant')
                    else:
                        portIdx = None

                    hostIdx = titles.index('host')

                else:

                    if portIdx is not None:
                        port = row[portIdx]
                    else:
                        port = 0

                    if host == '':
                        host = row[hostIdx]

                    if port in self.ports:
                        #break
                        continue
                    else:
                        self.ports.append(port)

                i += 1

            trace_lines = int((trace_lines - 1) / i)

            t1 = time.time()
            log('ports: %s' % str(self.ports))
            log('ports scan time: %s' % str(round(t1 - t0, 3)))

            rows = []
            for kpi in titles:
                (type, kpiName) = getKPI(kpi)

                if type:

                    desc = (getKpiDesc(type, kpiName))

                    #desc[4] = int(desc[4])

                    if desc is not None:

                        desc[2] = kpi  # replace name by nameserver naming...

                        try:
                            desc[3] = int(desc[3])  #group
                            desc[8] = int(desc[8])  #color
                            desc[9] = int(desc[9])  #style
                        except:
                            log(
                                '--> kpi style exception: %s, %s, %s' %
                                (desc[3], desc[8], desc[9]), 2)

                        rows.append(desc)

                    else:
                        log(
                            'KPI %s not defined in default kpis description' %
                            kpi, 3)

                else:
                    log('KPI %s not defined in nameserver mapping' % kpi, 6)

            kpiDescriptions.initKPIDescriptions(rows, hostKPIs, srvcKPIs)

            t1 = time.time()

            log('lines per port: %i' % trace_lines)
            log('init time: %s' % str(round(t1 - t0, 3)))

            # allocate stuff
            for port in self.ports:

                #data[port] = [0]* (row_len)
                if port == '':
                    data[port] = [0] * (len(hostKPIs) + 1)
                else:
                    data[port] = [0] * (len(srvcKPIs) + 1)

                ii[port] = 0

                if port == '':
                    for i in range(0, len(hostKPIs) + 1):
                        data[port][i] = [-1] * (trace_lines + 1)
                else:
                    for i in range(0, len(srvcKPIs) + 1):
                        data[port][i] = [-1] * (trace_lines + 1)

            f.seek(0)  # and destroy

            i = -1
            prow = [0] * row_len

            ctime = None

            # main data parsing here
            for line in f:
                row = line.rstrip().split(';')

                if i == -1:
                    i += 1
                    continue

                if portIdx is not None:
                    port = row[portIdx]
                else:
                    port = 0

                #iterrate values
                for j in range(0, len(row)):
                    col = titles[j]
                    value = row[j]

                    indx = ii[port]  # actual row number
                    '''
                        check the kpi name
                        and skip it if it is not in the corresponding list
                    '''
                    if col != 'time':
                        if port == '':
                            if col not in hostKPIs:
                                continue
                            else:
                                colindx = hostKPIs.index(col) + 1
                        else:
                            if col not in srvcKPIs:
                                continue
                            else:
                                #log('%s --> %i' % (col, srvcKPIs.index(col)))
                                colindx = srvcKPIs.index(col) + 1

                    if col != 'time' and value == '':
                        #if port == '30003' and col == 'indexserverCpu':
                        #    log('repeat %s %i %i --> %i' % (port, colindx, indx, data[port][colindx][indx - 1]))

                        #data[port][colindx][indx] = data[port][colindx][indx - 1] # god knows what that means actually.
                        data[port][colindx][indx] = prow[
                            j]  # god knows what that means actually.
                        continue

                    #log('%s = %s' % (col, value))

                    if col == 'time':
                        if i == 0:
                            ctime = float(value)  #init time
                            #log('initidal time: %f' % ctime)
                        else:
                            if value == '':
                                ctime = ctime
                            else:
                                ctime = ctime + float(
                                    value[1:])  #init time + delta
                            #log('next time: %f' % ctime)

                        data[port][0][indx] = ctime

                    else:
                        if value[:1] == '>':
                            value = prow[j] + int(value[1:])
                        elif value[:1] == '<':
                            value = prow[j] - int(value[1:])

                    if col not in ('host', 'tenant', 'time'):
                        if value == '':
                            value = prow[j]

                        value = int(value)
                        data[port][colindx][indx] = value

                    if col == 'time':
                        prow[j] = ctime
                    else:
                        prow[j] = value

                ii[port] += 1
                i += 1

                if ii[port] >= trace_lines:
                    log('line count reached: %i', trace_lines)
                    break

        t2 = time.time()
        log('parsing time %s' % str(round(t2 - t1, 3)))

        port = ''
        s = ''

        # here in ns notation
        self.hostKPIs = hostKPIs.copy()
        self.srvcKPIs = srvcKPIs.copy()

        kpiDescriptions.clarifyGroups()

        self.lastIndx = ii.copy()
        for port in self.ports:
            lastIndx = ii[port] - 1

            stime = datetime.datetime.fromtimestamp(data[port][0][0])
            etime = datetime.datetime.fromtimestamp(data[port][0][lastIndx])

            hosts.append({
                'host': host,
                'port': port,
                'from': stime,
                'to': etime
            })
コード例 #4
0
ファイル: hslWindow.py プロジェクト: rybafish/rybafish
    def menuReloadCustomKPIs(self):

        kpiStylesNN = kpiDescriptions.kpiStylesNN

        for type in ('host', 'service'):
            for kpiName in list(kpiStylesNN[type]):

                kpi = kpiStylesNN[type][kpiName]

                if kpi['sql'] is not None:
                    del (kpiStylesNN[type][kpiName])

                    if type == 'host':
                        self.chartArea.hostKPIs.remove(kpiName)
                    else:
                        self.chartArea.srvcKPIs.remove(kpiName)

        # del host custom groups
        kpis_len = len(self.chartArea.hostKPIs)
        i = 0

        while i < kpis_len:
            if self.chartArea.hostKPIs[i][:1] == '.' and (
                    i == len(self.chartArea.hostKPIs) - 1
                    or self.chartArea.hostKPIs[i + 1][:1] == '.'):
                del (self.chartArea.hostKPIs[i])
                kpis_len -= 1
            else:
                i += 1

        # del service custom groups
        kpis_len = len(self.chartArea.srvcKPIs)
        i = 0

        while i < kpis_len:
            if self.chartArea.srvcKPIs[i][:1] == '.' and (
                    i == len(self.chartArea.srvcKPIs) - 1
                    or self.chartArea.srvcKPIs[i + 1][:1] == '.'):
                del (self.chartArea.srvcKPIs[i])
                kpis_len -= 1
            else:
                i += 1

        try:
            dpDBCustom.scanKPIsN(self.chartArea.hostKPIs,
                                 self.chartArea.srvcKPIs, kpiStylesNN)
        except Exception as e:
            self.chartArea.disableDeadKPIs()
            msgDialog(
                'Custom KPIs Error',
                'There were errors during custom KPIs load. Load of the custom KPIs STOPPED because of that.\n\n'
                + str(e))

        self.chartArea.widget.initPens()
        self.chartArea.widget.update()

        #really unsure if this one can be called twice...
        kpiDescriptions.clarifyGroups()

        #trigger refill
        self.kpisTable.refill(self.hostTable.currentRow())

        self.statusMessage('Custom KPIs reload finish', False)
コード例 #5
0
    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))))