示例#1
0
        node_ids = global_context.bytes_per_day.keys()
        self.plot(self.plot_daily, global_context, 'overall', node_ids)
        self.plot(self.plot_daily_linear, global_context, 'overall_linear', node_ids)

        eastern = pytz.timezone('US/Eastern')
        start_time = eastern.localize(datetime(2011, 10, 3))
        end_time = eastern.localize(datetime(2012, 3, 1))

        current_time = start_time
        while current_time < end_time:
            node_ids = global_context.bytes_per_hour.keys()
            self.plot(self.plot_hourly,
                      global_context,
                      current_time.strftime('weekly_%Y-%m-%d'),
                      node_ids,
                      limits=(current_time, current_time + timedelta(weeks=1)))
            self.plot(self.plot_hourly_linear,
                      global_context,
                      current_time.strftime('weekly_linear_%Y-%m-%d'),
                      node_ids,
                      limits=(current_time, current_time + timedelta(weeks=1)))
            self.plot(self.plot_hourly_udp,
                      global_context,
                      current_time.strftime('udp_weekly_%Y-%m-%d'),
                      node_ids,
                      limits=(current_time, current_time + timedelta(weeks=1)))
            current_time += timedelta(weeks=1)

if __name__ == '__main__':
    main(TrafficPlotHarness)
        self.plot(self.plot_daily_linear, global_context, 'overall_linear',
                  node_ids)

        eastern = pytz.timezone('US/Eastern')
        start_time = eastern.localize(datetime(2011, 10, 3))
        end_time = eastern.localize(datetime(2012, 3, 1))

        current_time = start_time
        while current_time < end_time:
            node_ids = global_context.bytes_per_hour.keys()
            self.plot(self.plot_hourly,
                      global_context,
                      current_time.strftime('weekly_%Y-%m-%d'),
                      node_ids,
                      limits=(current_time, current_time + timedelta(weeks=1)))
            self.plot(self.plot_hourly_linear,
                      global_context,
                      current_time.strftime('weekly_linear_%Y-%m-%d'),
                      node_ids,
                      limits=(current_time, current_time + timedelta(weeks=1)))
            self.plot(self.plot_hourly_udp,
                      global_context,
                      current_time.strftime('udp_weekly_%Y-%m-%d'),
                      node_ids,
                      limits=(current_time, current_time + timedelta(weeks=1)))
            current_time += timedelta(weeks=1)


if __name__ == '__main__':
    main(TrafficPlotHarness)
from collections import defaultdict

import bismarkpassive

class SimpleByteCountProcessor(bismarkpassive.PersistentSessionProcessor):
    def initialize_context(self, context):
        context.number_of_bytes_this_session = 0

    def process_update_persistent(self, context, update):
        for packet in update.packet_series:
            context.number_of_bytes_this_session += packet.size

    def initialize_global_context(self, global_context):
        global_context.number_of_bytes_per_node = defaultdict(int)

    def merge_contexts_persistent(self, context, global_context):
        global_context.number_of_bytes_per_node[context.node_id] += context.number_of_bytes_this_session

class PrintByteCountsHarness(bismarkpassive.Harness):
    @property
    def processors(self):
        return [SimpleByteCountProcessor]

    def process_results(self, global_context):
        print 'Bytes transferred through each router:'
        for node_id, count in global_context.number_of_bytes_per_node.items():
            print node_id, count

if __name__ == '__main__':
    bismarkpassive.main(PrintByteCountsHarness)