コード例 #1
0
    def write_log_entries(self,
                          entries,
                          log_name='',
                          resource=None,
                          labels=None,
                          partial_success=False,
                          options=None):
        """
        Writes log entries to Stackdriver Logging.  All log entries are
        written by this method.

        Example:
          >>> from google.cloud.gapic.logging.v2.logging_service_v2_api import LoggingServiceV2Api
          >>> from google.logging.v2 import log_entry_pb2
          >>> api = LoggingServiceV2Api()
          >>> entries = []
          >>> response = api.write_log_entries(entries)

        Args:
          log_name (string): Optional. A default log resource name for those log entries in ``entries``
            that do not specify their own ``logName``.  Example:
            ``\"projects/my-project/logs/syslog\"``.  See
            ``LogEntry``.
          resource (:class:`google.api.monitored_resource_pb2.MonitoredResource`): Optional. A default monitored resource for those log entries in ``entries``
            that do not specify their own ``resource``.
          labels (dict[string -> :class:`google.logging.v2.logging_pb2.WriteLogEntriesRequest.LabelsEntry`]): Optional. User-defined ``key:value`` items that are added to
            the ``labels`` field of each log entry in ``entries``, except when a log
            entry specifies its own ``key:value`` item with the same key.
            Example: ``{ \"size\": \"large\", \"color\":\"red\" }``
          entries (list[:class:`google.logging.v2.log_entry_pb2.LogEntry`]): Required. The log entries to write. The log entries must have values for
            all required fields.

            To improve throughput and to avoid exceeding the quota limit for calls
            to ``entries.write``, use this field to write multiple log entries at once
            rather than  // calling this method for each log entry.
          partial_success (bool): Optional. Whether valid entries should be written even if some other
            entries fail due to INVALID_ARGUMENT or PERMISSION_DENIED errors. If any
            entry is not written, the response status will be the error associated
            with one of the failed entries and include error details in the form of
            WriteLogEntriesPartialErrors.
          options (:class:`google.gax.CallOptions`): Overrides the default
            settings for this call, e.g, timeout, retries etc.

        Raises:
          :exc:`google.gax.errors.GaxError` if the RPC is aborted.
        """
        if resource is None:
            resource = monitored_resource_pb2.MonitoredResource()
        if labels is None:
            labels = []
        request = logging_pb2.WriteLogEntriesRequest(
            entries=entries,
            log_name=log_name,
            resource=resource,
            labels=labels,
            partial_success=partial_success)
        self._write_log_entries(request, options)
コード例 #2
0
def generate_query_results():
    def P(timestamp, value):
        interval = monitoring_v3.TimeInterval()
        interval.start_time = datetime_helpers.from_rfc3339(timestamp).replace(
            tzinfo=None)
        interval.end_time = datetime_helpers.from_rfc3339(timestamp).replace(
            tzinfo=None)
        return monitoring_v3.Point(interval=interval,
                                   value={"double_value": value})

    for metric_labels, resource_labels, value in zip(METRIC_LABELS,
                                                     RESOURCE_LABELS, VALUES):
        yield monitoring_v3.TimeSeries(
            metric=metric_pb2.Metric(type=METRIC_TYPE, labels=metric_labels),
            resource=monitored_resource_pb2.MonitoredResource(
                type=RESOURCE_TYPE, labels=resource_labels),
            metric_kind=METRIC_KIND,
            value_type=VALUE_TYPE,
            points=[P(t, value) for t in TIMESTAMPS],
        )
    def write_log_entries(self,
                          entries,
                          log_name='',
                          resource=None,
                          labels=None,
                          partial_success=False,
                          options=None):
        """
        Writes log entries to Stackdriver Logging.  All log entries are
        written by this method.

        Example:
          >>> from google.cloud.gapic.logging.v2 import logging_service_v2_api
          >>> from google.logging.v2 import log_entry_pb2
          >>> api = logging_service_v2_api.LoggingServiceV2Api()
          >>> entries = []
          >>> response = api.write_log_entries(entries)

        Args:
          log_name (string): Optional. A default log resource name that is assigned to all log entries
            in ``entries`` that do not specify a value for ``log_name``.  Example:
            ``\"projects/my-project/logs/syslog\"``.  See
            ``LogEntry``.
          resource (:class:`google.api.monitored_resource_pb2.MonitoredResource`): Optional. A default monitored resource object that is assigned to all log
            entries in ``entries`` that do not specify a value for ``resource``. Example:

                { \"type\": \"gce_instance\",
                  \"labels\": {
                    \"zone\": \"us-central1-a\", \"instance_id\": \"00000000000000000000\" }}

            See ``LogEntry``.
          labels (dict[string -> :class:`google.logging.v2.logging_pb2.WriteLogEntriesRequest.LabelsEntry`]): Optional. Default labels that are added to the ``labels`` field of all log
            entries in ``entries``. If a log entry already has a label with the same key
            as a label in this parameter, then the log entry's label is not changed.
            See ``LogEntry``.
          entries (list[:class:`google.logging.v2.log_entry_pb2.LogEntry`]): Required. The log entries to write. Values supplied for the fields
            ``log_name``, ``resource``, and ``labels`` in this ``entries.write`` request are
            added to those log entries that do not provide their own values for the
            fields.

            To improve throughput and to avoid exceeding the
            `quota limit <https://cloud.google.com/logging/quota-policy>`_ for calls to ``entries.write``,
            you should write multiple log entries at once rather than
            calling this method for each individual log entry.
          partial_success (bool): Optional. Whether valid entries should be written even if some other
            entries fail due to INVALID_ARGUMENT or PERMISSION_DENIED errors. If any
            entry is not written, the response status will be the error associated
            with one of the failed entries and include error details in the form of
            WriteLogEntriesPartialErrors.
          options (:class:`google.gax.CallOptions`): Overrides the default
            settings for this call, e.g, timeout, retries etc.

        Raises:
          :exc:`google.gax.errors.GaxError` if the RPC is aborted.
          :exc:`ValueError` if the parameters are invalid.
        """
        if resource is None:
            resource = monitored_resource_pb2.MonitoredResource()
        if labels is None:
            labels = []
        request = logging_pb2.WriteLogEntriesRequest(
            entries=entries,
            log_name=log_name,
            resource=resource,
            labels=labels,
            partial_success=partial_success)
        self._write_log_entries(request, options)