コード例 #1
0
    def run_top_n(self, config, args, base_col, minpct, maxpct):
        columns = config.columns + [base_col.name]
        with lock:
            report = SingleQueryReport(args.profiler)
            report.run(
                realm='traffic_summary',
                centricity=args.centricity,
                groupby=args.profiler.groupbys[self.table.options.groupby],
                columns=columns,
                timefilter=args.timefilter,
                trafficexpr=args.trafficexpr,
                resolution=args.resolution,
                sort_col=base_col.name,
                sync=False
                )

        rows = self._wait_for_data(report, minpct=minpct, maxpct=maxpct)

        if not rows:
            msg = ('Error computing top-n columns for TimeSeries report, '
                   'no columns were found.')
            logger.error(msg)
            return []

        defs = []
        parser = getattr(self, config.parser)

        for row in rows[:int(self.table.options.top_n)]:
            defs.append(parser(row))

        return defs
コード例 #2
0
    def run(self):
        """ Main execution method
        """
        args = self._prepare_report_args()

        with lock:
            report = SingleQueryReport(args.profiler)
            report.run(
                realm=self.table.options.realm,
                groupby=args.profiler.groupbys[self.table.options.groupby],
                centricity=args.centricity,
                columns=args.columns,
                timefilter=args.timefilter,
                trafficexpr=args.trafficexpr,
                data_filter=args.datafilter,
                resolution=args.resolution,
                sort_col=args.sortcol,
                sync=False,
                limit=args.limit
            )

        data = self._wait_for_data(report)

        if self.table.rows > 0:
            data = data[:self.table.rows]

        logger.info("Report %s returned %s rows" % (self.job, len(data)))
        return QueryComplete(data)
コード例 #3
0
    def run_top_n(self, config, args, base_col, minpct, maxpct):
        columns = config.columns + [base_col.name]
        with lock:
            report = SingleQueryReport(args.profiler)
            report.run(
                realm='traffic_summary',
                centricity=args.centricity,
                groupby=args.profiler.groupbys[self.table.options.groupby],
                columns=columns,
                timefilter=args.timefilter,
                trafficexpr=args.trafficexpr,
                resolution=args.resolution,
                sort_col=base_col.name,
                sync=False
                )

        rows = self._wait_for_data(report, minpct=minpct, maxpct=maxpct)

        if not rows:
            msg = ('Error computing top-n columns for TimeSeries report, '
                   'no columns were found.')
            logger.error(msg)
            return []

        defs = []
        parser = getattr(self, config.parser)

        for row in rows[:int(self.table.options.top_n)]:
            defs.append(parser(row))

        return defs
コード例 #4
0
    def run(self):
        """ Main execution method
        """
        args = self._prepare_report_args()

        with lock:
            report = SingleQueryReport(args.profiler)
            report.run(
                realm=self.table.options.realm,
                groupby=args.profiler.groupbys[self.table.options.groupby],
                centricity=args.centricity,
                columns=args.columns,
                timefilter=args.timefilter,
                trafficexpr=args.trafficexpr,
                data_filter=args.datafilter,
                resolution=args.resolution,
                sort_col=args.sortcol,
                sync=False,
                limit=args.limit
            )

        data = self._wait_for_data(report)

        if self.table.rows > 0:
            data = data[:self.table.rows]

        logger.info("Report %s returned %s rows" % (self.job, len(data)))
        return QueryComplete(data)
コード例 #5
0
    def run_top_n(self, config, args, base_col, minpct, maxpct):
        columns = config.columns + [base_col.name]
        with lock:
            report = SingleQueryReport(args.profiler)
            report.run(
                realm='traffic_summary',
                groupby=args.profiler.groupbys[self.table.options.groupby],
                columns=columns,
                timefilter=args.timefilter,
                trafficexpr=args.trafficexpr,
                resolution=args.resolution,
                sort_col=base_col.name,
                sync=False)

        rows = self._wait_for_data(report, minpct=minpct, maxpct=maxpct)

        defs = []
        parser = getattr(self, config.parser)

        for row in rows[:int(self.table.options.top_n)]:
            defs.append(parser(row))

        return defs
コード例 #6
0
    def run_top_n(self, config, args, base_col, minpct, maxpct):
        columns = config.columns + [base_col.name]
        with lock:
            report = SingleQueryReport(args.profiler)
            report.run(
                realm='traffic_summary',
                groupby=args.profiler.groupbys[self.table.options.groupby],
                columns=columns,
                timefilter=args.timefilter,
                trafficexpr=args.trafficexpr,
                resolution=args.resolution,
                sort_col=base_col.name,
                sync=False
                )

        rows = self._wait_for_data(report, minpct=minpct, maxpct=maxpct)

        defs = []
        parser = getattr(self, config.parser)

        for row in rows[:int(self.table.options.top_n)]:
            defs.append(parser(row))

        return defs
コード例 #7
0
    def run(self):
        """ Main execution method
        """
        args = self._prepare_report_args()

        with lock:
            report = SingleQueryReport(args.profiler)
            report.run(
                realm=self.table.options.realm,
                groupby=args.profiler.groupbys[self.table.options.groupby],
                centricity=args.centricity,
                columns=args.columns,
                timefilter=args.timefilter,
                trafficexpr=args.trafficexpr,
                data_filter=args.datafilter,
                resolution=args.resolution,
                sort_col=self.table.options.sort_col,
                sync=False,
                limit=args.limit
            )

        data = self._wait_for_data(report)

        if not data:
            msg = 'Report %s returned no data' % self.job
            logger.error(msg)
            return QueryError(msg)

        def tonumber(s):
            # return an int if the string represents an integer,
            # a float if it represents a float
            # None otherwise.
            # check the int first since float() captures both
            try:
                return int(s)
            except ValueError:
                try:
                    return float(s)
                except:
                    return None

        others = []
        totals = []
        for i, col in enumerate(args.columns):
            if i == 0:
                others.append(u'Others')
                totals.append(u'Total')
            elif tonumber(data[0][i]):
                others.append(0)
                totals.append(0)
            else:
                others.append(u'')
                totals.append(u'')

        for i, row in enumerate(data):
            for j, col in enumerate(args.columns):
                val = tonumber(row[j])
                if val:
                    row[j] = val
                    totals[j] += row[j]
                    if i > self.table.rows:
                        others[j] += row[j]

        # Clip the table at the row limit, then add two more
        # for other and total
        if self.table.rows > 0:
            data = data[:self.table.rows]
        self.table.rows += 2

        data.append(others)
        data.append(totals)
        
        # Formatting:
        #  - Add percents of total to numeric columns
        #  - Strip "ByLocation|" from the groups if it exists
        #  - Parse dns
        for row in data:
            for j, col in enumerate(args.columns):
                if isinstance(row[j], float):
                    row[j] = u"%.2f  (%.0f%%)" % \
                            (row[j], 100 * row[j] / totals[j])
                elif isinstance(row[j], int):
                    row[j] = u"%d  (%.0f%%)" % \
                            (row[j], 100 * row[j] / totals[j])
                elif isinstance(row[j], unicode):
                    if row[j].startswith(u'ByLocation|'):
                        row[j] = row[j][11:]
                    elif (col == u'cli_host_dns' or col == u'srv_host_dns') \
                        and (u'|' in row[j]):
                        # If we're using dns columns, they are ip|name
                        # We should use the name if it's non-empty,
                        # ip otherwise
                        ip, name = row[j].split(u'|')
                        if name:
                            row[j] = name
                        else:
                            row[j] = ip
        logger.info("Report %s returned %s rows" % (self.job, len(data)))
        return QueryComplete(data)
コード例 #8
0
    def run(self):
        """ Main execution method
        """
        args = self._prepare_report_args()

        with lock:
            report = SingleQueryReport(args.profiler)
            report.run(
                realm=self.table.options.realm,
                groupby=args.profiler.groupbys[self.table.options.groupby],
                centricity=args.centricity,
                columns=args.columns,
                timefilter=args.timefilter,
                trafficexpr=args.trafficexpr,
                data_filter=args.datafilter,
                resolution=args.resolution,
                sort_col=self.table.options.sort_col,
                sync=False,
                limit=args.limit
            )

        data = self._wait_for_data(report)

        if not data:
            msg = 'Report %s returned no data' % self.job
            logger.error(msg)
            return QueryError(msg)

        def tonumber(s):
            # return an int if the string represents an integer,
            # a float if it represents a float
            # None otherwise.
            # check the int first since float() captures both
            try:
                return int(s)
            except ValueError:
                try:
                    return float(s)
                except:
                    return None

        others = []
        totals = []
        for i, col in enumerate(args.columns):
            if i == 0:
                others.append(u'Others')
                totals.append(u'Total')
            elif tonumber(data[0][i]):
                others.append(0)
                totals.append(0)
            else:
                others.append(u'')
                totals.append(u'')

        for i, row in enumerate(data):
            for j, col in enumerate(args.columns):
                val = tonumber(row[j])
                if val:
                    row[j] = val
                    totals[j] += row[j]
                    if i > self.table.rows:
                        others[j] += row[j]

        # Clip the table at the row limit, then add two more
        # for other and total
        if self.table.rows > 0:
            data = data[:self.table.rows]
        self.table.rows += 2

        data.append(others)
        data.append(totals)

        # Formatting:
        #  - Add percents of total to numeric columns
        #  - Strip "ByLocation|" from the groups if it exists
        #  - Parse dns
        for row in data:
            for j, col in enumerate(args.columns):
                if isinstance(row[j], float):
                    row[j] = "%.2f  (%.0f%%)" % \
                            (row[j], 100 * row[j] / totals[j])
                elif isinstance(row[j], int):
                    row[j] = "%d  (%.0f%%)" % \
                            (row[j], 100 * row[j] / totals[j])
                elif isinstance(row[j], str):
                    if row[j].startswith('ByLocation|'):
                        row[j] = row[j][11:]
                    elif ((col == 'cli_host_dns' or col == 'srv_host_dns')
                          and ('|' in row[j])):
                        # If we're using dns columns, they are ip|name
                        # We should use the name if it's non-empty,
                        # ip otherwise
                        ip, name = row[j].split('|')
                        if name:
                            row[j] = name
                        else:
                            row[j] = ip
        logger.info("Report %s returned %s rows" % (self.job, len(data)))
        return QueryComplete(data)