コード例 #1
0
ファイル: services.py プロジェクト: yunhaia/poppy
    def read(self, metric_names, from_timestamp, to_timestamp, resolution):
        """read metrics from metrics driver.

        """
        curr_resolution = \
            helper.resolution_converter_seconds_to_enum(resolution)
        context_dict = context_utils.get_current().to_dict()

        project_id = context_dict['tenant']
        auth_token = None
        if self.driver.metrics_conf.use_keystone_auth:
            auth_token = context_dict['auth_token']

        tenanted_blueflood_url = \
            self.driver.metrics_conf.blueflood_url.format(
                project_id=project_id
            )
        from_timestamp = int(helper.datetime_to_epoch(from_timestamp))
        to_timestamp = int(helper.datetime_to_epoch(to_timestamp))
        urls = []
        params = {
            'to': to_timestamp,
            'from': from_timestamp,
            'resolution': curr_resolution
        }
        for metric_name in metric_names:
            tenanted_blueflood_url_with_metric = helper.join_url(
                tenanted_blueflood_url,
                metric_name.strip().replace(" ", ""))
            LOG.info("Querying BlueFlood Metric: {0}".format(
                tenanted_blueflood_url_with_metric))
            urls.append(
                helper.set_qs_on_url(tenanted_blueflood_url_with_metric,
                                     **params))
        executors = self.driver.metrics_conf.no_of_executors
        blueflood_client = client.BlueFloodMetricsClient(token=auth_token,
                                                         project_id=project_id,
                                                         executors=executors)
        results = blueflood_client.async_requests(urls)
        reordered_metric_names = []
        for result in results:
            metric_name = helper.retrieve_last_relative_url(result.url)
            reordered_metric_names.append(metric_name)

        formatted_results = []
        for metric_name, result in zip(reordered_metric_names, results):
            formatted_result = self._result_formatter(result)
            # NOTE(TheSriram): Tuple to pass the associated metric name, along
            # with the formatted result
            formatted_results.append((metric_name, formatted_result))

        return formatted_results
コード例 #2
0
ファイル: services.py プロジェクト: openstack/poppy
    def read(self, metric_names, from_timestamp, to_timestamp, resolution):
        """read metrics from metrics driver.

        """
        curr_resolution = \
            helper.resolution_converter_seconds_to_enum(resolution)
        context_dict = context_utils.get_current().to_dict()

        project_id = context_dict['tenant']
        auth_token = None
        if self.driver.metrics_conf.use_keystone_auth:
            auth_token = context_dict['auth_token']

        tenanted_blueflood_url = \
            self.driver.metrics_conf.blueflood_url.format(
                project_id=project_id
            )
        from_timestamp = int(helper.datetime_to_epoch(from_timestamp))
        to_timestamp = int(helper.datetime_to_epoch(to_timestamp))
        urls = []
        params = {
            'to': to_timestamp,
            'from': from_timestamp,
            'resolution': curr_resolution
        }
        for metric_name in metric_names:
            tenanted_blueflood_url_with_metric = helper.join_url(
                tenanted_blueflood_url, metric_name.strip().replace(" ", ""))
            LOG.info("Querying BlueFlood Metric: {0}".format(
                tenanted_blueflood_url_with_metric))
            urls.append(helper.set_qs_on_url(
                        tenanted_blueflood_url_with_metric,
                        **params))
        executors = self.driver.metrics_conf.no_of_executors
        blueflood_client = client.BlueFloodMetricsClient(token=auth_token,
                                                         project_id=project_id,
                                                         executors=executors)
        results = blueflood_client.async_requests(urls)
        reordered_metric_names = []
        for result in results:
            metric_name = helper.retrieve_last_relative_url(result.url)
            reordered_metric_names.append(metric_name)

        formatted_results = []
        for metric_name, result in zip(reordered_metric_names, results):
            formatted_result = self._result_formatter(result)
            # NOTE(TheSriram): Tuple to pass the associated metric name, along
            # with the formatted result
            formatted_results.append((metric_name, formatted_result))

        return formatted_results
コード例 #3
0
ファイル: test_utils.py プロジェクト: taicai/poppy
 def test_helper_join_url(self):
     relative_url = 'requestCount'
     expected_url = self.url + '/' + relative_url
     self.assertEqual(helper.join_url(self.url, relative_url), expected_url)
コード例 #4
0
ファイル: test_utils.py プロジェクト: openstack/poppy
 def test_helper_join_url(self):
     relative_url = 'requestCount'
     expected_url = self.url + '/' + relative_url
     self.assertEqual(helper.join_url(self.url, relative_url),
                      expected_url)