def testFlattenAndClear(self):
   application_metric_map = ApplicationMetricMap("host", "10.10.10.10")
   application_metric_map.put_metric("A1", { "a" : "b" }, int(round(1415390657.3806491 * 1000)))
   json_data = json.loads(application_metric_map.flatten('A1', True))
   self.assertEqual(len(json_data['metrics']), 1)
   self.assertTrue(json_data['metrics'][0]['metricname'] == 'a')
   self.assertFalse(application_metric_map.app_metric_map)
Ejemplo n.º 2
0
 def testFlattenAndClear(self):
     application_metric_map = ApplicationMetricMap("host", "10.10.10.10")
     application_metric_map.put_metric(
         "A1", {"a": "b"}, int(round(1415390657.3806491 * 1000)))
     json_data = json.loads(application_metric_map.flatten('A1', True))
     self.assertEqual(len(json_data['metrics']), 1)
     self.assertTrue(json_data['metrics'][0]['metricname'] == 'a')
     self.assertFalse(application_metric_map.app_metric_map)
Ejemplo n.º 3
0
  def testRetryFetch(self, url_open_mock):
    stop_handler = bind_signal_handlers()

    config = Configuration()
    application_metric_map = ApplicationMetricMap("host","10.10.10.10")
    application_metric_map.clear()
    application_metric_map.put_metric("APP1", {"metric1":1}, 1)
    emitter = Emitter(config, application_metric_map, stop_handler)
    emitter.RETRY_SLEEP_INTERVAL = .001
    emitter.submit_metrics()
    
    self.assertEqual(url_open_mock.call_count, 3)
    self.assertUrlData(url_open_mock)
Ejemplo n.º 4
0
 def __init__(self, config, stop_handler):
   # Process initialization code
   threading.Thread.__init__(self)
   logger.debug('Initializing Controller thread.')
   self.lock = threading.Lock()
   self.config = config
   self.metrics_config = config.getMetricGroupConfig()
   self.events_cache = []
   hostinfo = HostInfo(config)
   self.application_metric_map = ApplicationMetricMap(hostinfo.get_hostname(),
                                                      hostinfo.get_ip_address())
   self.event_queue = Queue(config.get_max_queue_size())
   self.metric_collector = MetricsCollector(self.event_queue, self.application_metric_map, hostinfo)
   self.server_url = config.get_server_address()
   self.sleep_interval = config.get_collector_sleep_interval()
   self._stop_handler = stop_handler
   self.initialize_events_cache()
   self.emitter = Emitter(self.config, self.application_metric_map, stop_handler)
   self._t = None
Ejemplo n.º 5
0
  def testRetryFetchAndRoundRobin(self, request_mock):
    stop_handler = bind_signal_handlers()

    request_mock.return_value = MagicMock()

    config = Configuration()
    application_metric_map = ApplicationMetricMap("host","10.10.10.10")
    application_metric_map.clear()
    application_metric_map.put_metric("APP1", {"metric1":1}, 1)
    emitter = Emitter(config, application_metric_map, stop_handler)
    emitter.RETRY_SLEEP_INTERVAL = .001
    emitter.submit_metrics()

    self.assertEqual(request_mock.call_count, 9)
    self.assertUrlData(request_mock)
Ejemplo n.º 6
0
    def test_submit_metrics(self, getresponse_mock, request_mock):
        request_mock.return_value = MagicMock()
        getresponse_mock.return_value = MagicMock()
        getresponse_mock.return_value.status = 200

        stop_handler = bind_signal_handlers()

        config = Configuration()
        application_metric_map = ApplicationMetricMap("host", "10.10.10.10")
        application_metric_map.clear()
        application_metric_map.put_metric("APP1", {"metric1": 1}, 1)
        emitter = Emitter(config, application_metric_map, stop_handler)
        emitter.submit_metrics()

        self.assertEqual(request_mock.call_count, 1)
        self.assertUrlData(request_mock)
Ejemplo n.º 7
0
  def testJavaHomeAvailableCheck(self, url_open_mock):
    url_open_mock.return_value = MagicMock()
    url_open_mock.return_value.getcode.return_value = 200
    self.assertEqual(urllib2.urlopen(None, None).getcode(), 200)
    url_open_mock.reset_mock()

    stop_handler = bind_signal_handlers()

    config = Configuration()
    application_metric_map = ApplicationMetricMap("host","10.10.10.10")
    application_metric_map.clear()
    application_metric_map.put_metric("APP1", {"metric1":1}, 1)
    emitter = Emitter(config, application_metric_map, stop_handler)
    emitter.submit_metrics()
    
    self.assertEqual(url_open_mock.call_count, 1)
    self.assertUrlData(url_open_mock)
 def testEmptyMapReturnNone(self):
   application_metric_map = ApplicationMetricMap("host","10.10.10.10")
   self.assertTrue(application_metric_map.flatten() == None)
  def testApplicationMetricMap(self):
    application_metric_map = ApplicationMetricMap("host1", "10.10.10.10")
    
    application_id = application_metric_map.format_app_id("A","1")
    timestamp = int(round(1415390657.3806491 * 1000))
    
    metrics = {}
    metrics.update({"b" : 'bv'})
    
    application_metric_map.put_metric(application_id, metrics, timestamp)
    application_metric_map.put_metric(application_id, metrics, timestamp + 1)
    application_metric_map.put_metric(application_id, metrics, timestamp + 2)
    application_metric_map.put_metric(application_id, metrics, timestamp + 3)
    
    p = json.loads(application_metric_map.flatten(application_id))
    self.assertEqual(len(p['metrics']), 1)
    self.assertEqual(p['metrics'][0]['metricname'], "b")
#     self.assertEqual(p['metrics'][0]['appid'], application_id)
    self.assertEqual(p['metrics'][0]['hostname'], "host1")
    self.assertEqual(len(p['metrics'][0]['metrics']), 4)
    self.assertEqual(p['metrics'][0]['metrics'][str(timestamp)], 'bv')
    
    self.assertEqual(application_metric_map.get_start_time(application_id, "b"), timestamp)
    
    metrics = {}
    metrics.update({"b" : 'bv'})
    metrics.update({"a" : 'av'})
    application_metric_map.put_metric(application_id, metrics, timestamp)
    p = json.loads(application_metric_map.flatten(application_id))
    self.assertEqual(len(p['metrics']), 2)
    self.assertTrue((p['metrics'][0]['metricname'] == 'a' and p['metrics'][1]['metricname'] == 'b') or 
                    (p['metrics'][1]['metricname'] == 'a' and p['metrics'][0]['metricname'] == 'b'))
Ejemplo n.º 10
0
    def test_flatten_and_align_values_by_minute_mark(self):
        application_metric_map = ApplicationMetricMap("host", "10.10.10.10")
        second = 1000
        timestamp = int(round(1415390640.3806491 * second))
        application_id = application_metric_map.format_app_id("A", "1")
        metrics = {}
        metrics.update({"b": 'bv'})

        #   0s    60s   120s
        #   (0) (1)   (2)    (3)
        # (3) should be cut off and cached
        application_metric_map.put_metric(application_id, metrics, timestamp)
        application_metric_map.put_metric(application_id, metrics,
                                          timestamp + second * 24)
        application_metric_map.put_metric(application_id, metrics,
                                          timestamp + second * 84)
        application_metric_map.put_metric(application_id, metrics,
                                          timestamp + second * 124)

        json_data = json.loads(
            application_metric_map.flatten(application_id, True))
        self.assertEqual(len(json_data['metrics'][0]['metrics']), 3)
        self.assertEqual(
            len(
                application_metric_map.cached_metric_map.get(
                    application_id).get("b")), 1)
        self.assertEqual(
            application_metric_map.cached_metric_map.get(application_id).get(
                "b"), {timestamp + second * 124: 'bv'})

        #   120s    180s
        #      (3)  (4)
        # cached (3) should be added to the post;
        # (4) should be posted as well because there can't be more data points in the minute
        application_metric_map.put_metric(application_id, metrics,
                                          timestamp + second * 176)

        json_data = json.loads(
            application_metric_map.flatten(application_id, True))
        self.assertEqual(len(json_data['metrics'][0]['metrics']), 2)

        # starttime should be set to (3)
        self.assertEqual(json_data['metrics'][0]['starttime'],
                         timestamp + second * 124)
        self.assertEqual(
            len(application_metric_map.cached_metric_map.get(application_id)),
            0)
Ejemplo n.º 11
0
 def testEmptyMapReturnNone(self):
     application_metric_map = ApplicationMetricMap("host", "10.10.10.10")
     self.assertTrue(application_metric_map.flatten() == None)
Ejemplo n.º 12
0
    def testApplicationMetricMap(self):
        application_metric_map = ApplicationMetricMap("host1", "10.10.10.10")

        application_id = application_metric_map.format_app_id("A", "1")
        timestamp = int(round(1415390657.3806491 * 1000))

        metrics = {}
        metrics.update({"b": 'bv'})

        application_metric_map.put_metric(application_id, metrics, timestamp)
        application_metric_map.put_metric(application_id, metrics,
                                          timestamp + 1)
        application_metric_map.put_metric(application_id, metrics,
                                          timestamp + 2)
        application_metric_map.put_metric(application_id, metrics,
                                          timestamp + 3)

        p = json.loads(application_metric_map.flatten(application_id))
        self.assertEqual(len(p['metrics']), 1)
        self.assertEqual(p['metrics'][0]['metricname'], "b")
        #     self.assertEqual(p['metrics'][0]['appid'], application_id)
        self.assertEqual(p['metrics'][0]['hostname'], "host1")
        self.assertEqual(len(p['metrics'][0]['metrics']), 4)
        self.assertEqual(p['metrics'][0]['metrics'][str(timestamp)], 'bv')

        self.assertEqual(
            application_metric_map.get_start_time(application_id, "b"),
            timestamp)

        metrics = {}
        metrics.update({"b": 'bv'})
        metrics.update({"a": 'av'})
        application_metric_map.put_metric(application_id, metrics, timestamp)
        p = json.loads(application_metric_map.flatten(application_id))
        self.assertEqual(len(p['metrics']), 2)
        self.assertTrue((p['metrics'][0]['metricname'] == 'a'
                         and p['metrics'][1]['metricname'] == 'b')
                        or (p['metrics'][1]['metricname'] == 'a'
                            and p['metrics'][0]['metricname'] == 'b'))