Class MetricServiceClient (0.34.0)

MetricServiceClient(
    transport=None,
    channel=None,
    credentials=None,
    client_config=None,
    client_info=None,
    client_options=None,
)

Manages metric descriptors, monitored resource descriptors, and time series data.

Methods

MetricServiceClient

MetricServiceClient(
    transport=None,
    channel=None,
    credentials=None,
    client_config=None,
    client_info=None,
    client_options=None,
)

Constructor.

Parameters
NameDescription
channel grpc.Channel

DEPRECATED. A Channel instance through which to make calls. This argument is mutually exclusive with credentials; providing both will raise an exception.

credentials google.auth.credentials.Credentials

The authorization credentials to attach to requests. These credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment. This argument is mutually exclusive with providing a transport instance to transport; doing so will raise an exception.

client_config dict

DEPRECATED. A dictionary of call options for each method. If not specified, the default configuration is used.

client_info google.api_core.gapic_v1.client_info.ClientInfo

The client info used to send a user-agent string along with API requests. If None, then default info will be used. Generally, you only need to set this if you're developing your own client library.

client_options Union[dict, google.api_core.client_options.ClientOptions]

Client options used to set user options on the client. API Endpoint should be set through client_options.

create_metric_descriptor

create_metric_descriptor(name, metric_descriptor, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)

Creates a new metric descriptor. User-created metric descriptors define custom metrics <https://cloud.google.com/monitoring/custom-metrics>__.

.. rubric:: Example

from google.cloud import monitoring_v3

client = monitoring_v3.MetricServiceClient()

name = client.project_path('[PROJECT]')

TODO: Initialize metric_descriptor:

metric_descriptor = {}

response = client.create_metric_descriptor(name, metric_descriptor)

Parameters
NameDescription
name str

The project on which to execute the request. The format is "projects/{project_id_or_number}".

metric_descriptor Union[dict, MetricDescriptor]

The new custom metric https://cloud.google.com/monitoring/custom-metrics__ descriptor. If a dict is provided, it must be of the same form as the protobuf message MetricDescriptor

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.

create_time_series

create_time_series(name, time_series, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)

Creates or adds data to one or more time series. The response is empty if all time series in the request were written. If any time series could not be written, a corresponding failure message is included in the error response.

.. rubric:: Example

from google.cloud import monitoring_v3

client = monitoring_v3.MetricServiceClient()

name = client.project_path('[PROJECT]')

TODO: Initialize time_series:

time_series = []

client.create_time_series(name, time_series)

Parameters
NameDescription
name str

The project on which to execute the request. The format is "projects/{project_id_or_number}".

time_series list[Union[dict, TimeSeries]]

The new data to be added to a list of time series. Adds at most one data point to each of several time series. The new data point must be more recent than any other point in its time series. Each TimeSeries value must fully specify a unique time series by supplying all label values for the metric and the monitored resource. The maximum number of TimeSeries objects per Create request is 200. If a dict is provided, it must be of the same form as the protobuf message TimeSeries

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.

delete_metric_descriptor

delete_metric_descriptor(name, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)

Deletes a metric descriptor. Only user-created custom metrics <https://cloud.google.com/monitoring/custom-metrics>__ can be deleted.

.. rubric:: Example

from google.cloud import monitoring_v3

client = monitoring_v3.MetricServiceClient()

name = client.metric_descriptor_path('[PROJECT]', '[METRIC_DESCRIPTOR]')

client.delete_metric_descriptor(name)

Parameters
NameDescription
name str

The metric descriptor on which to execute the request. The format is "projects/{project_id_or_number}/metricDescriptors/{metric_id}". An example of {metric_id} is: "custom.googleapis.com/my_test_metric".

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.

from_service_account_file

from_service_account_file(filename, *args, **kwargs)

Creates an instance of this client using the provided credentials file.

Parameter
NameDescription
filename str

The path to the service account private key json file.

Returns
TypeDescription
MetricServiceClientThe constructed client.

from_service_account_json

from_service_account_json(filename, *args, **kwargs)

Creates an instance of this client using the provided credentials file.

Parameter
NameDescription
filename str

The path to the service account private key json file.

Returns
TypeDescription
MetricServiceClientThe constructed client.

get_metric_descriptor

get_metric_descriptor(name, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)

Gets a single metric descriptor. This method does not require a Stackdriver account.

.. rubric:: Example

from google.cloud import monitoring_v3

client = monitoring_v3.MetricServiceClient()

name = client.metric_descriptor_path('[PROJECT]', '[METRIC_DESCRIPTOR]')

response = client.get_metric_descriptor(name)

Parameters
NameDescription
name str

The metric descriptor on which to execute the request. The format is "projects/{project_id_or_number}/metricDescriptors/{metric_id}". An example value of {metric_id} is "compute.googleapis.com/instance/disk/read_bytes_count".

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.

get_monitored_resource_descriptor

get_monitored_resource_descriptor(name, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)

Gets a single monitored resource descriptor. This method does not require a Stackdriver account.

.. rubric:: Example

from google.cloud import monitoring_v3

client = monitoring_v3.MetricServiceClient()

name = client.monitored_resource_descriptor_path('[PROJECT]', '[MONITORED_RESOURCE_DESCRIPTOR]')

response = client.get_monitored_resource_descriptor(name)

Parameters
NameDescription
name str

The monitored resource descriptor to get. The format is "projects/{project_id_or_number}/monitoredResourceDescriptors/{resource_type}". The {resource_type} is a predefined type, such as cloudsql_database.

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.

list_metric_descriptors

list_metric_descriptors(name, filter_=None, page_size=None, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)

Lists metric descriptors that match a filter. This method does not require a Stackdriver account.

.. rubric:: Example

from google.cloud import monitoring_v3

client = monitoring_v3.MetricServiceClient()

name = client.project_path('[PROJECT]')

Iterate over all results

for element in client.list_metric_descriptors(name): ... # process element ... pass

Alternatively:

Iterate over results one page at a time

for page in client.list_metric_descriptors(name).pages: ... for element in page: ... # process element ... pass

Parameters
NameDescription
name str

The project on which to execute the request. The format is "projects/{project_id_or_number}".

filter_ str

If this field is empty, all custom and system-defined metric descriptors are returned. Otherwise, the filter https://cloud.google.com/monitoring/api/v3/filters specifies which metric descriptors are to be returned. For example, the following filter matches all custom metrics https://cloud.google.com/monitoring/custom-metrics: :: metric.type = starts_with("custom.googleapis.com/")

page_size int

The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.

list_monitored_resource_descriptors

list_monitored_resource_descriptors(name, filter_=None, page_size=None, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)

Lists monitored resource descriptors that match a filter. This method does not require a Stackdriver account.

.. rubric:: Example

from google.cloud import monitoring_v3

client = monitoring_v3.MetricServiceClient()

name = client.project_path('[PROJECT]')

Iterate over all results

for element in client.list_monitored_resource_descriptors(name): ... # process element ... pass

Alternatively:

Iterate over results one page at a time

for page in client.list_monitored_resource_descriptors(name).pages: ... for element in page: ... # process element ... pass

Parameters
NameDescription
name str

The project on which to execute the request. The format is "projects/{project_id_or_number}".

filter_ str

An optional filter https://cloud.google.com/monitoring/api/v3/filters_ describing the descriptors to be returned. The filter can reference the descriptor's type and labels. For example, the following filter returns only Google Compute Engine descriptors that have an id label: :: resource.type = starts_with("gce") AND resource.label:id

page_size int

The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.

list_time_series

list_time_series(name, filter_, interval, view, aggregation=None, order_by=None, page_size=None, retry=<_MethodDefault._DEFAULT_VALUE: <object object>>, timeout=<_MethodDefault._DEFAULT_VALUE: <object object>>, metadata=None)

Lists time series that match a filter. This method does not require a Stackdriver account.

.. rubric:: Example

from google.cloud import monitoring_v3 from google.cloud.monitoring_v3 import enums

client = monitoring_v3.MetricServiceClient()

name = client.project_path('[PROJECT]')

TODO: Initialize filter_:

filter_ = ''

TODO: Initialize interval:

interval = {}

TODO: Initialize view:

view = enums.ListTimeSeriesRequest.TimeSeriesView.FULL

Iterate over all results

for element in client.list_time_series(name, filter_, interval, view): ... # process element ... pass

Alternatively:

Iterate over results one page at a time

for page in client.list_time_series(name, filter_, interval, view).pages: ... for element in page: ... # process element ... pass

Parameters
NameDescription
name str

The project on which to execute the request. The format is "projects/{project_id_or_number}".

filter_ str

A monitoring filter https://cloud.google.com/monitoring/api/v3/filters__ that specifies which time series should be returned. The filter must specify a single metric type, and can additionally specify metric labels and other information. For example: :: metric.type = "compute.googleapis.com/instance/cpu/usage_time" AND metric.labels.instance_name = "my-instance-name"

interval Union[dict, TimeInterval]

The time interval for which results should be returned. Only time series that contain data points in the specified interval are included in the response. If a dict is provided, it must be of the same form as the protobuf message TimeInterval

view TimeSeriesView

Specifies which information is returned about the time series.

aggregation Union[dict, Aggregation]

Specifies the alignment of data points in individual time series as well as how to combine the retrieved time series across specified labels. By default (if no aggregation is explicitly specified), the raw time series data is returned. If a dict is provided, it must be of the same form as the protobuf message Aggregation

order_by str

Unsupported: must be left blank. The points in each time series are currently returned in reverse time order (most recent to oldest).

page_size int

The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.

metric_descriptor_path

metric_descriptor_path(project, metric_descriptor)

DEPRECATED. Return a fully-qualified metric_descriptor string.

monitored_resource_descriptor_path

monitored_resource_descriptor_path(project, monitored_resource_descriptor)

DEPRECATED. Return a fully-qualified monitored_resource_descriptor string.

project_path

project_path(project)

DEPRECATED. Return a fully-qualified project string.