def push(self, dataframes, scope_id=None): for frame in dataframes: period = tzutils.diff_seconds(frame.end, frame.start) for type_, point in frame.iterpoints(): self._conn.append_point(type_, frame.start, period, point) self._conn.commit()
def test_diff_seconds_negative_arg_aware_objects_on_summer_change(self): one = datetime.datetime(2019, 3, 31, 1, tzinfo=tz.gettz('Europe/Paris')) two = datetime.datetime(2019, 3, 31, 3, tzinfo=tz.gettz('Europe/Paris')) self.assertEqual(tzutils.diff_seconds(two, one), 3600)
def fetch_all(self, metric_name, start, end, scope_id, q_filter=None): """Returns metrics to be valorized.""" scope_key = CONF.collect.scope_key method = self.conf[metric_name]['extra_args']['aggregation_method'] query_function = self.conf[metric_name]['extra_args'].get( 'query_function') range_function = self.conf[metric_name]['extra_args'].get( 'range_function') groupby = self.conf[metric_name].get('groupby', []) metadata = self.conf[metric_name].get('metadata', []) period = tzutils.diff_seconds(end, start) time = end # The metric with the period query = '{0}{{{1}="{2}"}}[{3}s]'.format(metric_name, scope_key, scope_id, period) # Applying the aggregation_method or the range_function on # a Range Vector if range_function is not None: query = "{0}({1})".format(range_function, query) else: query = "{0}_over_time({1})".format(method, query) # Applying the query_function if query_function is not None: query = "{0}({1})".format(query_function, query) # Applying the aggregation_method on a Instant Vector query = "{0}({1})".format(method, query) # Filter by groupby and metadata query = "{0} by ({1})".format(query, ', '.join(groupby + metadata)) try: res = self._conn.get_instant( query, time.isoformat(), ) except PrometheusResponseError as e: raise CollectError(*e.args) # If the query returns an empty dataset, # return an empty list if not res['data']['result']: return [] formatted_resources = [] for item in res['data']['result']: metadata, groupby, qty = self._format_data( metric_name, scope_key, scope_id, start, end, item, ) formatted_resources.append( dataframe.DataPoint( self.conf[metric_name]['unit'], qty, 0, groupby, metadata, )) return formatted_resources
def test_diff_seconds_negative_arg_aware_objects(self): one = datetime.datetime(2019, 1, 1, 1, 1, 30, tzinfo=tz.tzutc()) two = datetime.datetime(2019, 1, 1, 1, 1, tzinfo=tz.tzutc()) self.assertEqual(tzutils.diff_seconds(two, one), 30)
def test_diff_seconds_negative_arg_naive_objects(self): one = datetime.datetime(2019, 1, 1, 1, 1, 30) two = datetime.datetime(2019, 1, 1, 1, 1) self.assertEqual(tzutils.diff_seconds(two, one), 30)
def test_diff_seconds_positive_arg_aware_objects(self): one = datetime.datetime(2019, 1, 1, 1, 1, 30, tzinfo=tz.UTC) two = datetime.datetime(2019, 1, 1, 1, 1, tzinfo=tz.UTC) self.assertEqual(tzutils.diff_seconds(one, two), 30)