Metric Descriptors#

Metric Descriptors for the Google Stackdriver Monitoring API (V3).

class google.cloud.monitoring.metric.Metric[source]#

Bases: google.cloud.monitoring.metric.Metric

A specific metric identified by specifying values for all labels.

The preferred way to construct a metric object is using the metric() factory method of the Client class.

Parameters:
  • type (str) – The metric type name.
  • labels (dict) – A mapping from label names to values for all labels enumerated in the associated MetricDescriptor.

Create new instance of Metric(type, labels)

class google.cloud.monitoring.metric.MetricDescriptor(client, type_, metric_kind='METRIC_KIND_UNSPECIFIED', value_type='VALUE_TYPE_UNSPECIFIED', labels=(), unit='', description='', display_name='', name=None)[source]#

Bases: object

Specification of a metric type and its schema.

The preferred way to construct a metric descriptor object is using the metric_descriptor() factory method of the Client class.

Parameters:
  • client (google.cloud.monitoring.client.Client) – A client for operating on the metric descriptor.
  • type (str) – The metric type including a DNS name prefix. For example: "compute.googleapis.com/instance/cpu/utilization"
  • metric_kind (str) – The kind of measurement. It must be one of MetricKind.GAUGE, MetricKind.DELTA, or MetricKind.CUMULATIVE. See MetricKind.
  • value_type (str) – The value type of the metric. It must be one of ValueType.BOOL, ValueType.INT64, ValueType.DOUBLE, ValueType.STRING, or ValueType.DISTRIBUTION. See ValueType.
  • labels (list of LabelDescriptor) – A sequence of zero or more label descriptors specifying the labels used to identify a specific instance of this metric.
  • unit (str) – An optional unit in which the metric value is reported.
  • description (str) – An optional detailed description of the metric.
  • display_name (str) – An optional concise name for the metric.
  • name (str) – (Optional) The “resource name” of the metric descriptor. For example: "projects/<project_id>/metricDescriptors/<type>". As retrieved from the service, this will always be specified. You can and should omit it when constructing an instance for the purpose of creating a new metric descriptor.
create()[source]#

Create a new metric descriptor based on this object.

Example:

>>> 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()

The metric kind must not be MetricKind.METRIC_KIND_UNSPECIFIED, and the value type must not be ValueType.VALUE_TYPE_UNSPECIFIED.

The name attribute is ignored in preparing the creation request. All attributes are overwritten by the values received in the response (normally affecting only name).

delete()[source]#

Delete the metric descriptor identified by this object.

Example:

>>> descriptor = client.metric_descriptor(
...     'custom.googleapis.com/my_metric')
>>> descriptor.delete()

Only the client and type attributes are used.

class google.cloud.monitoring.metric.MetricKind[source]#

Bases: object

Choices for the kind of measurement.

METRIC_KIND_UNSPECIFIED = 'METRIC_KIND_UNSPECIFIED'#

Note

An unspecified kind is not allowed in metric descriptors.

class google.cloud.monitoring.metric.ValueType[source]#

Bases: object

Choices for the metric value type.

VALUE_TYPE_UNSPECIFIED = 'VALUE_TYPE_UNSPECIFIED'#

Note

An unspecified type is not allowed in metric descriptors.