예제 #1
0
    def get_all(self, metric_name, time_delta, host_name=None,
                service_description=None):
        """Return all metrics."""

        cli = self.request.influxdb_client
        query = influxdb_time_query.build_influxdb_query(
            metric_name,
            time_delta,
            host_name,
            service_description
        )
        response = cli.query(query)

        metric_dicts = []

        for item in response[None]:
            metric_dict = self._metric_dict_from_influx_item(item, metric_name)
            metric_dicts.append(metric_dict)

        metrics = []
        for metric_dict in metric_dicts:
            metric = live_metric.LiveMetric(**metric_dict)
            metrics.append(metric)

        return metrics
    def test_build_query_basic(self):
        query_time = time_delta.TimeDelta(begin='2015-01-29T21:50:44Z',
                                          end='2015-01-29T22:50:44Z', )
        query_metric_name = 'pl'

        result = influxdb_time_query.build_influxdb_query(query_metric_name,
                                                          query_time
                                                          )
        expected = ("SELECT * "
                    "FROM metric_pl "
                    "WHERE time >= '2015-01-29T21:50:44Z' "
                    "AND time <= '2015-01-29T22:50:44Z' "
                    "GROUP BY host_name, "
                    "service_description ORDER BY time DESC")

        self.assert_count_equal_backport(result, expected)
    def test_build_query_basic(self):
        query_time = time_delta.TimeDelta(
            begin='2015-01-29T21:50:44Z',
            end='2015-01-29T22:50:44Z',
        )
        query_metric_name = 'pl'

        result = influxdb_time_query.build_influxdb_query(
            query_metric_name, query_time)
        expected = ("SELECT * "
                    "FROM metric_pl "
                    "WHERE time >= '2015-01-29T21:50:44Z' "
                    "AND time <= '2015-01-29T22:50:44Z' "
                    "GROUP BY host_name, "
                    "service_description ORDER BY time DESC")

        self.assert_count_equal_backport(result, expected)
    def test_build_query_complete(self):
        query_time = time_delta.TimeDelta(
            begin='2015-01-29T21:50:44Z',
            end='2015-01-29T22:50:44Z',
        )
        query_metric_name = 'pl'
        query_host_name = 'localhost'
        query_service_description = 'mySQL'

        result = influxdb_time_query.build_influxdb_query(
            query_metric_name, query_time, query_host_name,
            query_service_description)
        expected = ("SELECT * "
                    "FROM metric_pl "
                    "WHERE time >= '2015-01-29T21:50:44Z' "
                    "AND time <= '2015-01-29T22:50:44Z' "
                    "AND host_name ='localhost' "
                    "AND service_description ='mySQL' "
                    "ORDER BY time DESC")

        self.assert_count_equal_backport(result, expected)
    def test_build_query_complete(self):
        query_time = time_delta.TimeDelta(begin='2015-01-29T21:50:44Z',
                                          end='2015-01-29T22:50:44Z', )
        query_metric_name = 'pl'
        query_host_name = 'localhost'
        query_service_description = 'mySQL'

        result = influxdb_time_query.build_influxdb_query(
            query_metric_name,
            query_time,
            query_host_name,
            query_service_description
        )
        expected = ("SELECT * "
                    "FROM metric_pl "
                    "WHERE time >= '2015-01-29T21:50:44Z' "
                    "AND time <= '2015-01-29T22:50:44Z' "
                    "AND host_name ='localhost' "
                    "AND service_description ='mySQL' "
                    "ORDER BY time DESC")

        self.assert_count_equal_backport(result, expected)
예제 #6
0
    def get_all(self,
                metric_name,
                time_delta,
                host_name=None,
                service_description=None):
        """Return all metrics."""

        cli = self.request.influxdb_client
        query = influxdb_time_query.build_influxdb_query(
            metric_name, time_delta, host_name, service_description)
        response = cli.query(query)

        metric_dicts = []

        for item in response[None]:
            metric_dict = self._metric_dict_from_influx_item(item, metric_name)
            metric_dicts.append(metric_dict)

        metrics = []
        for metric_dict in metric_dicts:
            metric = live_metric.LiveMetric(**metric_dict)
            metrics.append(metric)

        return metrics