def export_metrics(self, metrics): if metrics: envelopes = [] for metric in metrics: # No support for histogram aggregations type_ = metric.descriptor.type if type_ != MetricDescriptorType.CUMULATIVE_DISTRIBUTION: md = metric.descriptor # Each time series will be uniquely # identified by it's label values for time_series in metric.time_series: # Using stats, time_series should # only have one point which contains # the aggregated value data_point = self.create_data_points(time_series, md)[0] # The timestamp is when the metric was recorded time_stamp = time_series.points[0].timestamp # Get the properties using label keys from metric # and label values of the time series properties = self.create_properties(time_series, md) envelopes.append( self.create_envelope(data_point, time_stamp, properties)) # Send data in batches of max_batch_size if envelopes: batched_envelopes = list( common_utils.window(envelopes, self.max_batch_size)) for batch in batched_envelopes: self._transmit_without_retry(batch)
def create_batched_time_series(self, view_data, batch_size): """ Create the data structure that will be sent to Stackdriver Monitoring """ time_series_list = itertools.chain.from_iterable( self.create_time_series_list(v_data, self.options.resource, self.options.metric_prefix) for v_data in view_data) return list(utils.window(time_series_list, batch_size))
def export_metrics(self, metrics): envelopes = [] for metric in metrics: envelopes.extend(self.metric_to_envelopes(metric)) # Send data in batches of max_batch_size batched_envelopes = list(common_utils.window( envelopes, self.max_batch_size)) for batch in batched_envelopes: batch = self.apply_telemetry_processors(batch) result = self._transmit(batch) if result > 0: self.storage.put(batch, result) # If there is still room to transmit envelopes, transmit from storage # if available if len(envelopes) < self.options.max_batch_size: self._transmit_from_storage()
def create_batched_time_series(self, metrics, batch_size=MAX_TIME_SERIES_PER_UPLOAD): time_series_list = itertools.chain.from_iterable( self.create_time_series_list(metric) for metric in metrics) return list(utils.window(time_series_list, batch_size))