@@ -58,18 +58,14 @@ class HawkularMetricsClient(HawkularBaseClient):
5858 """
5959 Internal methods
6060 """
61- @staticmethod
62- def _clean_metric_id (metric_id ):
63- return HawkularBaseClient .quote (metric_id )
64-
6561 def _get_url (self , metric_type = None ):
6662 if metric_type is None :
6763 metric_type = MetricType ._Metrics
6864
6965 return self ._get_base_url () + '{0}' .format (metric_type )
7066
7167 def _get_metrics_single_url (self , metric_type , metric_id ):
72- return self ._get_url (metric_type ) + '/{0}' .format (self . _clean_metric_id (metric_id ))
68+ return self ._get_url (metric_type ) + '/{0}' .format (HawkularBaseClient . quote (metric_id ))
7369
7470 def _get_metrics_raw_url (self , metrics_url ):
7571 return metrics_url + '/data' if self .legacy_api else metrics_url + '/raw'
@@ -113,7 +109,7 @@ def put(self, data):
113109 Send multiple different metric_ids to the server in a single batch. Metrics can be a mixture
114110 of types.
115111
116- data is a dict or a list of dicts created with create_metric(metric_type, metric_id, datapoints)
112+ :param data: A dict or a list of dicts created with create_metric(metric_type, metric_id, datapoints)
117113 """
118114 if not isinstance (data , list ):
119115 data = [data ]
@@ -136,29 +132,57 @@ def push(self, metric_type, metric_id, value, timestamp=None):
136132
137133 This method is an assistant method for the put method by removing the need to
138134 create data structures first.
135+
136+ :param metric_type: MetricType to be matched (required)
137+ :param metric_id: Exact string matching metric id
138+ :param value: Datapoint value (depending on the MetricType)
139+ :param timestamp: Timestamp of the datapoint. If left empty, uses current client time.
139140 """
140141 item = create_metric (metric_type , metric_id , create_datapoint (value , timestamp ))
141142 self .put (item )
142143
143144 def query_metric (self , metric_type , metric_id , ** query_options ):
144145 """
145- Query for metrics from the server. For possible query_options, see the Hawkular-Metrics documentation.
146+ Query for metrics datapoints from the server.
147+
148+ :param metric_type: MetricType to be matched (required)
149+ :param metric_id: Exact string matching metric id
150+ :param query_options: For possible query_options, see the Hawkular-Metrics documentation.
146151 """
147152 return self ._get (
148153 self ._get_metrics_raw_url (
149154 self ._get_metrics_single_url (metric_type , metric_id )),
150155 ** query_options )
151156
152157 def query_metric_stats (self , metric_type , metric_id , ** query_options ):
158+ """
159+ Query for metric aggregates from the server. This is called buckets in the Hawkular-Metrics documentation.
160+
161+ :param metric_type: MetricType to be matched (required)
162+ :param metric_id: Exact string matching metric id
163+ :param query_options: For possible query_options, see the Hawkular-Metrics documentation.
164+ """
153165 return self ._get (
154166 self ._get_metrics_stats_url (
155167 self ._get_metrics_single_url (metric_type , metric_id )),
156168 ** query_options )
169+
170+ def query_metric_definition (self , metric_type , metric_id ):
171+ """
172+ Query definition of a single metric id.
173+
174+ :param metric_type: MetricType to be matched (required)
175+ :param metric_id: Exact string matching metric id
176+ """
177+ return self ._get (self ._get_metrics_single_url (metric_type , metric_id ))
157178
158179 def query_metric_definitions (self , metric_type = None , id_filter = None , ** tags ):
159180 """
160- Query available metric definitions. Available query options are id_filter for id filtering and tags (dict) as tag based query.
161- Tags filtering is required for the id filtering to work.
181+ Query available metric definitions.
182+
183+ :param metric_type: A MetricType to be queried. If left to None, matches all the MetricTypes
184+ :param id_filter: Filter the id with regexp is tag filtering is used, otherwise a list of exact metric ids
185+ :param tags: A dict of tag key/value pairs. Uses Hawkular-Metrics tag query language for syntax
162186 """
163187 if id is not None and tags is None :
164188 raise HawkularMetricsError ('Tags query is required when id filter is used' )
@@ -175,8 +199,10 @@ def query_metric_definitions(self, metric_type=None, id_filter=None, **tags):
175199
176200 def query_tag_values (self , metric_type = None , ** tags ):
177201 """
178- Query for possible tag values. **tags is a dict which has tagname as key and regexp tagvalue as value. See Hawkular-Metrics
179- tag query language for more detailed definition.
202+ Query for possible tag values.
203+
204+ :param metric_type: A MetricType to be queried. If left to None, matches all the MetricTypes
205+ :param tags: A dict of tag key/value pairs. Uses Hawkular-Metrics tag query language for syntax
180206 """
181207 tagql = self ._transform_tags (** tags )
182208
@@ -186,6 +212,10 @@ def create_metric_definition(self, metric_type, metric_id, **tags):
186212 """
187213 Create metric definition with custom definition. **tags should be a set of tags, such as
188214 units, env ..
215+
216+ :param metric_type: MetricType of the new definition
217+ :param metric_id: metric_id is the string index of the created metric
218+ :param tags: Key/Value tag values of the new metric
189219 """
190220 item = { 'id' : metric_id }
191221 if len (tags ) > 0 :
@@ -209,20 +239,31 @@ def create_metric_definition(self, metric_type, metric_id, **tags):
209239
210240 def query_metric_tags (self , metric_type , metric_id ):
211241 """
212- Returns a list of tags in the metric definition of metric_id
242+ Returns a list of tags in the metric definition.
243+
244+ :param metric_type: MetricType to be matched (required)
245+ :param metric_id: Exact string matching metric id
213246 """
214247 definition = self ._get (self ._get_metrics_tags_url (self ._get_metrics_single_url (metric_type , metric_id )))
215248 return definition
216249
217250 def update_metric_tags (self , metric_type , metric_id , ** tags ):
218251 """
219252 Replace the metric_id's tags with given **tags
253+
254+ :param metric_type: MetricType to be matched (required)
255+ :param metric_id: Exact string matching metric id
256+ :param tags: Updated key/value tag values of the metric
220257 """
221258 self ._put (self ._get_metrics_tags_url (self ._get_metrics_single_url (metric_type , metric_id )), tags , parse_json = False )
222259
223260 def delete_metric_tags (self , metric_type , metric_id , ** deleted_tags ):
224261 """
225262 Delete one or more tags from the metric definition.
263+
264+ :param metric_type: MetricType to be matched (required)
265+ :param metric_id: Exact string matching metric id
266+ :param deleted_tags: List of deleted tag names. Values can be set to anything
226267 """
227268 tags = self ._transform_tags (** deleted_tags )
228269 tags_url = self ._get_metrics_tags_url (self ._get_metrics_single_url (metric_type , metric_id )) + '/{0}' .format (tags )
@@ -243,14 +284,15 @@ def create_tenant(self, tenant_id, retentions=None):
243284 """
244285 Create a tenant. Currently nothing can be set (to be fixed after the master
245286 version of Hawkular-Metrics has fixed implementation.
287+
288+ :param retentions: A set of retention settings, see Hawkular-Metrics documentation for more info
246289 """
247290 item = { 'id' : tenant_id }
248291 if retentions is not None :
249292 item ['retentions' ] = retentions
250293
251294 self ._post (self ._get_tenants_url (), json .dumps (item , indent = 2 ))
252295
253-
254296"""
255297Static methods
256298"""
@@ -262,8 +304,11 @@ def time_millis():
262304
263305def create_datapoint (value , timestamp = None , ** tags ):
264306 """
265- Creates a single datapoint dict with a value, timestamp (optional - filled by the method if missing)
266- and tags (optional)
307+ Creates a single datapoint dict with a value, timestamp and tags.
308+
309+ :param value: Value of the datapoint. Type depends on the id's MetricType
310+ :param timestamp: Optional timestamp of the datapoint. Uses client current time if not set. Millisecond accuracy
311+ :param tags: Optional datapoint tags. Not to be confused with metric definition tags
267312 """
268313 if timestamp is None :
269314 timestamp = time_millis ()
@@ -278,7 +323,11 @@ def create_datapoint(value, timestamp=None, **tags):
278323
279324def create_metric (metric_type , metric_id , data ):
280325 """
281- Create Hawkular-Metrics' submittable structure, data is a datapoint or list of datapoints
326+ Create Hawkular-Metrics' submittable structure.
327+
328+ :param metric_type: MetricType to be matched (required)
329+ :param metric_id: Exact string matching metric id
330+ :param data: A datapoint or a list of datapoints created with create_datapoint(value, timestamp, tags)
282331 """
283332 if not isinstance (data , list ):
284333 data = [data ]
0 commit comments