def traffic_report(self, host, timefilter, report_type):
        """ Generate average statistics for host given `timefilter` time period

            `report_type` is one of ('timeseries', 'summary')
        """
        print('Running {0} report for {1} over {2}/{3}'
              ''.format(report_type,
                        host,
                        timefilter.start,
                        timefilter.end))

        texpr = TrafficFilter('host %s' % host)

        if report_type == 'timeseries':
            columns = [c[0] for c in TCOLUMNS]
            report = TrafficOverallTimeSeriesReport(self.netprofiler)
            report.run(columns,
                       timefilter=timefilter,
                       trafficexpr=texpr,
                       resolution=self.options.resolution)
        elif report_type == 'summary':
            columns = [c[0] for c in SCOLUMNS]
            report = TrafficSummaryReport(self.netprofiler)

            if self.options.groupby_application:
                columns.insert(0, 'app_name')
                groupby = 'app'
            elif self.options.groupby_interface:
                columns.insert(0, 'interface_alias')
                columns.insert(0, 'interface')
                groupby = 'ifc'
            else:
                groupby = 'hos'

            report.run(groupby,
                       columns,
                       timefilter=timefilter,
                       trafficexpr=texpr,
                       resolution=self.options.resolution)
        else:
            raise RuntimeError('unknown report type: %s' % report_type)

        print('Report complete, gathering data ...')
        data = report.get_data()
        if not data:
            print("Empty data results.")
        elif len(data) == 10000:
            print('WARNING: data size exceeds max length of 10000 rows')
        legend = report.get_legend()
        report.delete()

        return legend, data
    def test_traffic_overall_time_series_report(self):

        columns = [
            self.profiler.columns.key.time,
            self.profiler.columns.value.avg_bytes,
            self.profiler.columns.value.avg_pkts
        ]

        timerange = TimeFilter.parse_range("last 1 h")
        trafficexpr = TrafficFilter("host 10/8")
        resolution = "15min"
        report = TrafficOverallTimeSeriesReport(self.profiler)
        report.run(columns, timerange, trafficexpr, resolution=resolution)

        legend = report.get_legend()
        keys = [c.key for c in legend]

        data = report.get_data()

        for item in data:
            d = dict(zip(keys, item))
            # resolution assumes 15-minute responses
            self.assertTrue(
                timerange.compare_time(d['time'], resolution=15 * 60))
        report.delete()
Esempio n. 3
0
    def main(self):
        self.timefilter = TimeFilter.parse_range(self.options.timefilter)
        if self.options.trafficexpr:
            self.trafficexpr = TrafficFilter(self.options.trafficexpr)
        else:
            self.trafficexpr = None

        with TrafficOverallTimeSeriesReport(self.netprofiler) as report:
            report.run(columns=self.options.columns.split(','),
                       timefilter=self.timefilter,
                       trafficexpr=self.trafficexpr,
                       centricity=self.centricity)
            data = report.get_data()
            legend = [c.label for c in report.get_legend()]

        self.print_data(data, legend)
    def test_traffic_overall_time_series_report(self):
        columns = [self.profiler.columns.key.time,
                   self.profiler.columns.value.avg_bytes,
                   self.profiler.columns.value.avg_pkts]

        timerange = self.yesterday 
        trafficexpr = TrafficFilter("host 10/8")
        resolution = "15min"
        report = TrafficOverallTimeSeriesReport(self.profiler)
        report.run(columns, timerange, trafficexpr, resolution=resolution)

        legend = report.get_legend()
        keys = [c.key for c in legend]

        data = report.get_data()

        for item in data:
            d = dict(zip(keys, item))
            # resolution assumes 15-minute responses
            self.assertTrue(timerange.compare_time(d['time'], resolution=15*60))
        report.delete()
Esempio n. 5
0
    def traffic_report(self, host, timefilter, report_type):
        """ Generate average statistics for host given `timefilter` time period

            `report_type` is one of ('timeseries', 'summary')
        """
        print 'Running %s report for %s over %s/%s' % (
            report_type, host, timefilter.start, timefilter.end)

        texpr = TrafficFilter('host %s' % host)

        if report_type == 'timeseries':
            columns = [c[0] for c in TCOLUMNS]
            report = TrafficOverallTimeSeriesReport(self.netprofiler)
            report.run(columns,
                       timefilter=timefilter,
                       trafficexpr=texpr,
                       resolution=self.options.resolution)
        elif report_type == 'summary':
            columns = [c[0] for c in SCOLUMNS]
            report = TrafficSummaryReport(self.netprofiler)

            if self.options.groupby_application:
                columns.insert(0, 'app_name')
                groupby = 'app'
            elif self.options.groupby_interface:
                columns.insert(0, 'interface_alias')
                columns.insert(0, 'interface')
                groupby = 'ifc'
            else:
                groupby = 'hos'

            report.run(groupby,
                       columns,
                       timefilter=timefilter,
                       trafficexpr=texpr,
                       resolution=self.options.resolution)
        else:
            raise RuntimeError('unknown report type: %s' % report_type)

        print 'Report complete, gathering data ...'
        data = report.get_data()
        if not data:
            print "Empty data results."
        elif len(data) == 10000:
            print 'WARNING: data size exceeds max length of 10000 rows'
        legend = report.get_legend()
        report.delete()

        return legend, data