Exemple #1
0
    def test_collect_only_alive_interfaces(self):
        container = SystemManager()
        container._discover_objects()

        os_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]
        collector = SystemMetricsCollector(object=os_obj)
        collector.collect()
        collector.collect()  # double collect is needed, because otherwise we do not collect metrics properly

        # get interfaces info
        all_interfaces = netifaces.interfaces()
        alive_interfaces = set()
        down_interfaces = set()
        for interface_name, interface in psutil.net_if_stats().iteritems():
            if interface.isup:
                alive_interfaces.add(interface_name)
            else:
                down_interfaces.add(interface_name)

        # check
        collected_metrics = os_obj.statsd.current
        net_metrics_found = False
        for metric in collected_metrics['counter'].keys():
            if metric.startswith('system.net.') and '|' in metric:
                net_metrics_found = True
                metric_name, label_name = metric.split('|')
                assert_that(all_interfaces, has_item(label_name))
                assert_that(alive_interfaces, has_item(label_name))
                assert_that(down_interfaces, not_(has_item(label_name)))
        assert_that(net_metrics_found, equal_to(True))
Exemple #2
0
 def setup_method(self, method):
     super(SystemMetricsCollectorTestCase, self).setup_method(method)
     manager = SystemManager()
     manager._discover_objects()
     system_obj = manager.objects.objects[manager.objects.objects_by_type[manager.type][0]]
     collector = SystemMetricsCollector(object=system_obj)
     collector.collect()
     collector.collect() # second collect is needed to properly collect all metrics
     self.metrics = system_obj.statsd.current
 def get_collector(self, collect=True):
     manager = SystemManager()
     manager._discover_objects()
     obj = manager.objects.find_all(types=manager.types)[0]
     collector = SystemMetricsCollector(object=obj)
     if collect:
         collector.collect()
         collector.collect()  # second collect is needed to properly collect all metrics
     return collector
Exemple #4
0
    def test_flush_aggregation(self):
        container = SystemManager()
        container._discover_objects()

        os_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]
        collector = SystemMetricsCollector(object=os_obj)
        collector.collect()
        collector.collect()  # double collect is needed, because otherwise we do not collect metrics properly

        flush = collector.object.statsd.flush()

        for type in flush['metrics'].keys():  # e.g. 'timer', 'counter', 'gauge', 'average'
            for key in flush['metrics'][type].keys():
                # Make sure there is only one item per item in the flush.
                assert_that(len(flush['metrics'][type][key]), equal_to(1))