def _iter_fragments(self, headers_only=False, page_size=None): """Yield all time series fragments selected by the query. There may be multiple fragments per time series. These will be contiguous. The parameters and return value are as for :meth:`Query.iter`. """ if self._end_time is None: raise ValueError('Query time interval not specified.') path = '/projects/{project}/timeSeries/'.format( project=self._client.project) page_token = None while True: params = list( self._build_query_params( headers_only=headers_only, page_size=page_size, page_token=page_token, )) response = self._client.connection.api_request( method='GET', path=path, query_params=params, ) for info in response.get('timeSeries', ()): yield TimeSeries._from_dict(info) page_token = response.get('nextPageToken') if not page_token: break
def _iter_fragments(self, headers_only=False, page_size=None): """Yield all time series fragments selected by the query. There may be multiple fragments per time series. These will be contiguous. The parameters and return value are as for :meth:`Query.iter`. """ if self._end_time is None: raise ValueError('Query time interval not specified.') path = '/projects/{project}/timeSeries/'.format( project=self._client.project) page_token = None while True: params = list(self._build_query_params( headers_only=headers_only, page_size=page_size, page_token=page_token, )) response = self._client._connection.api_request( method='GET', path=path, query_params=params, ) for info in response.get('timeSeries', ()): yield TimeSeries._from_dict(info) page_token = response.get('nextPageToken') if not page_token: break
def generate_query_results(): # pragma: NO COVER from google.cloud.monitoring.metric import Metric from google.cloud.monitoring.resource import Resource from google.cloud.monitoring.timeseries import Point from google.cloud.monitoring.timeseries import TimeSeries def P(timestamp, value): return Point( start_time=timestamp, end_time=timestamp, value=value, ) for metric_labels, resource_labels, value in zip( METRIC_LABELS, RESOURCE_LABELS, VALUES): yield TimeSeries( metric=Metric(type=METRIC_TYPE, labels=metric_labels), resource=Resource(type=RESOURCE_TYPE, labels=resource_labels), metric_kind=METRIC_KIND, value_type=VALUE_TYPE, points=[P(t, value) for t in TIMESTAMPS], )
def time_series(metric, resource, value, end_time=None, start_time=None): """Construct a time series object for a single data point. .. note:: While :class:`~google.cloud.monitoring.timeseries.TimeSeries` objects returned by the API typically have multiple data points, :class:`~google.cloud.monitoring.timeseries.TimeSeries` objects sent to the API must have at most one point. For example:: >>> timeseries = client.time_series(metric, resource, 1.23, ... end_time=end) For more information, see: https://cloud.google.com/monitoring/api/ref_v3/rest/v3/TimeSeries :type metric: :class:`~google.cloud.monitoring.metric.Metric` :param metric: A :class:`~google.cloud.monitoring.metric.Metric`. :type resource: :class:`~google.cloud.monitoring.resource.Resource` :param resource: A :class:`~google.cloud.monitoring.resource.Resource` object. :type value: bool, int, string, or float :param value: The value of the data point to create for the :class:`~google.cloud.monitoring.timeseries.TimeSeries`. .. note:: The Python type of the value will determine the :class:`~ValueType` sent to the API, which must match the value type specified in the metric descriptor. For example, a Python float will be sent to the API as a :data:`ValueType.DOUBLE`. :type end_time: :class:`~datetime.datetime` :param end_time: The end time for the point to be included in the time series. Assumed to be UTC if no time zone information is present. Defaults to the current time, as obtained by calling :meth:`datetime.datetime.utcnow`. :type start_time: :class:`~datetime.datetime` :param start_time: The start time for the point to be included in the time series. Assumed to be UTC if no time zone information is present. Defaults to None. If the start time is unspecified, the API interprets the start time to be the same as the end time. :rtype: :class:`~google.cloud.monitoring.timeseries.TimeSeries` :returns: A time series object. """ if end_time is None: end_time = _UTCNOW() end_time = _datetime_to_rfc3339(end_time, ignore_zone=False) if start_time: start_time = _datetime_to_rfc3339(start_time, ignore_zone=False) point = Point(value=value, start_time=start_time, end_time=end_time) return TimeSeries(metric=metric, resource=resource, metric_kind=None, value_type=None, points=[point])