def list_metric_descriptors(self, filter_string=None, type_prefix=None): """List all metric descriptors for the project. Examples:: >>> for descriptor in client.list_metric_descriptors(): ... print(descriptor.type) >>> for descriptor in client.list_metric_descriptors( ... type_prefix='custom.'): ... print(descriptor.type) :type filter_string: string or None :param filter_string: An optional filter expression describing the metric descriptors to be returned. See the `filter documentation`_. :type type_prefix: string or None :param type_prefix: An optional prefix constraining the selected metric types. This adds ``metric.type = starts_with("<prefix>")`` to the filter. :rtype: list of :class:`~gcloud.monitoring.metric.MetricDescriptor` :returns: A list of metric descriptor instances. .. _filter documentation: https://cloud.google.com/monitoring/api/v3/filters """ return MetricDescriptor._list(self, filter_string, type_prefix=type_prefix)
def fetch_metric_descriptor(self, metric_type): """Look up a metric descriptor by type. Example:: >>> METRIC = 'compute.googleapis.com/instance/cpu/utilization' >>> print(client.fetch_metric_descriptor(METRIC)) :type metric_type: string :param metric_type: The metric type name. :rtype: :class:`~gcloud.monitoring.metric.MetricDescriptor` :returns: The metric descriptor instance. :raises: :class:`gcloud.exceptions.NotFound` if the metric descriptor is not found. """ return MetricDescriptor._fetch(self, metric_type)
def list_metric_descriptors(self, filter_string=None): """List all metric descriptors for the project. Example:: >>> for descriptor in client.list_metric_descriptors(): ... print(descriptor.type) :type filter_string: string or None :param filter_string: An optional filter expression describing the metric descriptors to be returned. See the `filter documentation`_. :rtype: list of :class:`~gcloud.monitoring.metric.MetricDescriptor` :returns: A list of metric descriptor instances. .. _filter documentation: https://cloud.google.com/monitoring/api/v3/filters """ return MetricDescriptor._list(self, filter_string)
def metric_descriptor(self, type_, metric_kind=MetricKind.METRIC_KIND_UNSPECIFIED, value_type=ValueType.VALUE_TYPE_UNSPECIFIED, labels=(), unit='', description='', display_name=''): """Construct a metric descriptor object. Metric descriptors specify the schema for a particular metric type. This factory method is used most often in conjunction with the metric descriptor :meth:`~gcloud.monitoring.metric.MetricDescriptor.create` method to define custom metrics:: >>> descriptor = client.metric_descriptor( ... 'custom.googleapis.com/my_metric', ... metric_kind=MetricKind.GAUGE, ... value_type=ValueType.DOUBLE, ... description='This is a simple example of a custom metric.') >>> descriptor.create() Here is an example where the custom metric is parameterized by a metric label:: >>> label = LabelDescriptor('response_code', LabelValueType.INT64, ... description='HTTP status code') >>> descriptor = client.metric_descriptor( ... 'custom.googleapis.com/my_app/response_count', ... metric_kind=MetricKind.CUMULATIVE, ... value_type=ValueType.INT64, ... labels=[label], ... description='Cumulative count of HTTP responses.') >>> descriptor.create() :type type_: string :param type_: The metric type including a DNS name prefix. For example: ``"custom.googleapis.com/my_metric"`` :type metric_kind: string :param metric_kind: The kind of measurement. It must be one of :data:`MetricKind.GAUGE`, :data:`MetricKind.DELTA`, or :data:`MetricKind.CUMULATIVE`. See :class:`~gcloud.monitoring.metric.MetricKind`. :type value_type: string :param value_type: The value type of the metric. It must be one of :data:`ValueType.BOOL`, :data:`ValueType.INT64`, :data:`ValueType.DOUBLE`, :data:`ValueType.STRING`, or :data:`ValueType.DISTRIBUTION`. See :class:`ValueType`. :type labels: list of :class:`~gcloud.monitoring.label.LabelDescriptor` :param labels: A sequence of zero or more label descriptors specifying the labels used to identify a specific instance of this metric. :type unit: string :param unit: An optional unit in which the metric value is reported. :type description: string :param description: An optional detailed description of the metric. :type display_name: string :param display_name: An optional concise name for the metric. """ return MetricDescriptor( self, type_, metric_kind=metric_kind, value_type=value_type, labels=labels, unit=unit, description=description, display_name=display_name, )