3030from gcloud .client import JSONClient
3131from gcloud .monitoring .connection import Connection
3232from gcloud .monitoring .metric import MetricDescriptor
33+ from gcloud .monitoring .metric import MetricKind
34+ from gcloud .monitoring .metric import ValueType
3335from gcloud .monitoring .query import Query
3436from gcloud .monitoring .resource import ResourceDescriptor
3537
@@ -60,7 +62,7 @@ def query(self,
6062 metric_type = Query .DEFAULT_METRIC_TYPE ,
6163 end_time = None ,
6264 days = 0 , hours = 0 , minutes = 0 ):
63- """Construct a query object for listing time series .
65+ """Construct a query object for retrieving metric data .
6466
6567 Example::
6668
@@ -112,6 +114,82 @@ def query(self,
112114 end_time = end_time ,
113115 days = days , hours = hours , minutes = minutes )
114116
117+ def metric_descriptor (self , type_ ,
118+ metric_kind = MetricKind .METRIC_KIND_UNSPECIFIED ,
119+ value_type = ValueType .VALUE_TYPE_UNSPECIFIED ,
120+ labels = (), unit = '' , description = '' , display_name = '' ):
121+ """Construct a metric descriptor object.
122+
123+ Metric descriptors specify the schema for a particular metric type.
124+
125+ This factory method is used most often in conjunction with the metric
126+ descriptor :meth:`~gcloud.monitoring.metric.MetricDescriptor.create`
127+ method to define custom metrics::
128+
129+ >>> descriptor = client.metric_descriptor(
130+ ... 'custom.googleapis.com/my_metric',
131+ ... metric_kind=MetricKind.GAUGE,
132+ ... value_type=ValueType.DOUBLE,
133+ ... description='This is a simple example of a custom metric.')
134+ >>> descriptor.create()
135+
136+ Here is an example where the custom metric is parameterized by a
137+ metric label::
138+
139+ >>> label = LabelDescriptor('response_code', LabelValueType.INT64,
140+ ... description='HTTP status code')
141+ >>> descriptor = client.metric_descriptor(
142+ ... 'custom.googleapis.com/my_app/response_count',
143+ ... metric_kind=MetricKind.CUMULATIVE,
144+ ... value_type=ValueType.INT64,
145+ ... labels=[label],
146+ ... description='Cumulative count of HTTP responses.')
147+ >>> descriptor.create()
148+
149+ :type type_: string
150+ :param type_:
151+ The metric type including a DNS name prefix. For example:
152+ ``"custom.googleapis.com/my_metric"``
153+
154+ :type metric_kind: string
155+ :param metric_kind:
156+ The kind of measurement. It must be one of
157+ :data:`MetricKind.GAUGE`, :data:`MetricKind.DELTA`,
158+ or :data:`MetricKind.CUMULATIVE`.
159+ See :class:`~gcloud.monitoring.metric.MetricKind`.
160+
161+ :type value_type: string
162+ :param value_type:
163+ The value type of the metric. It must be one of
164+ :data:`ValueType.BOOL`, :data:`ValueType.INT64`,
165+ :data:`ValueType.DOUBLE`, :data:`ValueType.STRING`,
166+ or :data:`ValueType.DISTRIBUTION`.
167+ See :class:`ValueType`.
168+
169+ :type labels: list of :class:`~gcloud.monitoring.label.LabelDescriptor`
170+ :param labels:
171+ A sequence of zero or more label descriptors specifying the labels
172+ used to identify a specific instance of this metric.
173+
174+ :type unit: string
175+ :param unit: An optional unit in which the metric value is reported.
176+
177+ :type description: string
178+ :param description: An optional detailed description of the metric.
179+
180+ :type display_name: string
181+ :param display_name: An optional concise name for the metric.
182+ """
183+ return MetricDescriptor (
184+ self , type_ ,
185+ metric_kind = metric_kind ,
186+ value_type = value_type ,
187+ labels = labels ,
188+ unit = unit ,
189+ description = description ,
190+ display_name = display_name ,
191+ )
192+
115193 def fetch_metric_descriptor (self , metric_type ):
116194 """Look up a metric descriptor by type.
117195
@@ -163,7 +241,7 @@ def list_metric_descriptors(self, filter_string=None, type_prefix=None):
163241 type_prefix = type_prefix )
164242
165243 def fetch_resource_descriptor (self , resource_type ):
166- """Look up a resource descriptor by type.
244+ """Look up a monitored resource descriptor by type.
167245
168246 Example::
169247
@@ -181,7 +259,7 @@ def fetch_resource_descriptor(self, resource_type):
181259 return ResourceDescriptor ._fetch (self , resource_type )
182260
183261 def list_resource_descriptors (self , filter_string = None ):
184- """List all resource descriptors for the project.
262+ """List all monitored resource descriptors for the project.
185263
186264 Example::
187265
0 commit comments