Package cm_api :: Package endpoints :: Module timeseries
[hide private]
[frames] | no frames]

Source Code for Module cm_api.endpoints.timeseries

  1  # Licensed to Cloudera, Inc. under one 
  2  # or more contributor license agreements.  See the NOTICE file 
  3  # distributed with this work for additional information 
  4  # regarding copyright ownership.  Cloudera, Inc. licenses this file 
  5  # to you under the Apache License, Version 2.0 (the 
  6  # "License"); you may not use this file except in compliance 
  7  # with the License.  You may obtain a copy of the License at 
  8  # 
  9  #     http://www.apache.org/licenses/LICENSE-2.0 
 10  # 
 11  # Unless required by applicable law or agreed to in writing, software 
 12  # distributed under the License is distributed on an "AS IS" BASIS, 
 13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 14  # See the License for the specific language governing permissions and 
 15  # limitations under the License. 
 16   
 17  import datetime 
 18  try: 
 19    import json 
 20  except ImportError: 
 21    import simplejson as json 
 22  import logging 
 23   
 24  from cm_api.endpoints.types import * 
 25   
 26  __docformat__ = "epytext" 
 27   
 28  TIME_SERIES_PATH   = "/timeseries" 
 29  METRIC_SCHEMA_PATH = "/timeseries/schema" 
 30   
 31  LOG = logging.getLogger(__name__) 
 32   
33 -def query_timeseries(resource_root, query, from_time=None, to_time=None):
34 """ 35 Query for time series data from the CM time series data store. 36 @param query: Query string. 37 @param from_time: Start of the period to query (optional). 38 This may be an ISO format string, or a datetime object. 39 @param to_time: End of the period to query (default = now). 40 This may be an ISO format string, or a datetime object. 41 @return List of ApiTimeSeriesResponse 42 """ 43 params = {} 44 if query: 45 params['query'] = query 46 if from_time: 47 if isinstance(from_time, datetime.datetime): 48 from_time = from_time.isoformat() 49 params['from'] = from_time 50 if to_time: 51 if isinstance(to_time, datetime.datetime): 52 to_time = to_time.isoformat() 53 params['to'] = to_time 54 55 resp = resource_root.get(TIME_SERIES_PATH, params=params) 56 return ApiList.from_json_dict(ApiTimeSeriesResponse, resp, resource_root)
57
58 -def get_metric_schema(resource_root):
59 """ 60 Get the schema for all of the metrics. 61 @return List of metric schema. 62 """ 63 resp = resource_root.get(METRIC_SCHEMA_PATH) 64 return ApiList.from_json_dict(ApiMetricSchema, resp, resource_root)
65 66
67 -class ApiTimeSeriesData(BaseApiObject):
68 _ATTRIBUTES = { 69 'timestamp' : ROAttr(datetime.datetime), 70 'value' : ROAttr(), 71 'type' : ROAttr(), 72 }
73
74 -class ApiTimeSeriesMetadata(BaseApiObject):
75 _ATTRIBUTES = { 76 'metricName' : ROAttr(), 77 'entityName' : ROAttr(), 78 'startTime' : ROAttr(datetime.datetime), 79 'endTime' : ROAttr(datetime.datetime), 80 'attributes' : ROAttr(), 81 'unitNumerators' : ROAttr(), 82 'unitDenominators' : ROAttr(), 83 }
84
85 -class ApiTimeSeries(BaseApiObject):
86 _ATTRIBUTES = { 87 'metadata' : ROAttr(ApiTimeSeriesMetadata), 88 'data' : ROAttr(ApiTimeSeriesData), 89 }
90
91 -class ApiTimeSeriesResponse(BaseApiObject):
92 _ATTRIBUTES = { 93 'timeSeries' : ROAttr(ApiTimeSeries), 94 'warnings' : ROAttr(), 95 'errors' : ROAttr(), 96 'timeSeriesQuery' : ROAttr(), 97 }
98
99 -class ApiMetricSchema(BaseApiObject):
100 _ATTRIBUTES = { 101 'name' : ROAttr(), 102 'isCounter' : ROAttr(), 103 'unitNumerator' : ROAttr(), 104 'unitDenominator' : ROAttr(), 105 'aliases' : ROAttr(), 106 'sources' : ROAttr(), 107 }
108