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   
 19  from cm_api.endpoints.types import * 
 20   
 21  __docformat__ = "epytext" 
 22   
 23  TIME_SERIES_PATH   = "/timeseries" 
 24  METRIC_SCHEMA_PATH = "/timeseries/schema" 
 25  METRIC_ENTITY_TYPE_PATH = "/timeseries/entityTypes" 
 26  METRIC_ENTITY_ATTR_PATH = "/timeseries/entityTypeAttributes" 
 27   
28 -def query_timeseries(resource_root, query, from_time=None, to_time=None, 29 desired_rollup=None, must_use_desired_rollup=None, by_post=False):
30 """ 31 Query for time series data from the CM time series data store. 32 @param query: Query string. 33 @param from_time: Start of the period to query (optional). 34 @type from_time: datetime.datetime Note the that datetime must either be time 35 zone aware or specified in the server time zone. See the 36 python datetime documentation for more details about python's 37 time zone handling. 38 @param to_time: End of the period to query (default = now). 39 This may be an ISO format string, or a datetime object. 40 @type to_time: datetime.datetime Note the that datetime must either be time 41 zone aware or specified in the server time zone. See the 42 python datetime documentation for more details about python's 43 time zone handling. 44 @param desired_rollup: The aggregate rollup to get data for. This can be 45 RAW, TEN_MINUTELY, HOURLY, SIX_HOURLY, DAILY, or 46 WEEKLY. Note that rollup desired is only a hint unless 47 must_use_desired_rollup is set to true. 48 @param must_use_desired_rollup: Indicates that the monitoring server should 49 return the data at the rollup desired. 50 @param by_post: If true, an HTTP POST request will be made to server. This 51 allows longer query string to be accepted compared to HTTP 52 GET request. 53 @return: List of ApiTimeSeriesResponse 54 """ 55 data = None 56 params = {} 57 request_method = resource_root.get 58 if by_post: 59 request = ApiTimeSeriesRequest(resource_root, 60 query=query) 61 data = request 62 request_method = resource_root.post 63 elif query: 64 params['query'] = query 65 66 if from_time: 67 params['from'] = from_time.isoformat() 68 if to_time: 69 params['to'] = to_time.isoformat() 70 if desired_rollup: 71 params['desiredRollup'] = desired_rollup 72 if must_use_desired_rollup: 73 params['mustUseDesiredRollup'] = must_use_desired_rollup 74 return call(request_method, TIME_SERIES_PATH, 75 ApiTimeSeriesResponse, True, params=params, data=data)
76
77 -def get_metric_schema(resource_root):
78 """ 79 Get the schema for all of the metrics. 80 @return: List of metric schema. 81 """ 82 return call(resource_root.get, METRIC_SCHEMA_PATH, 83 ApiMetricSchema, True)
84
85 -def get_entity_types(resource_root):
86 """ 87 Get the time series entity types that CM monitors. 88 @return: List of time series entity type. 89 """ 90 return call(resource_root.get, METRIC_ENTITY_TYPE_PATH, 91 ApiTimeSeriesEntityType, True)
92
93 -def get_entity_attributes(resource_root):
94 """ 95 Get the time series entity attributes that CM monitors. 96 @return: List of time series entity attribute. 97 """ 98 return call(resource_root.get, METRIC_ENTITY_ATTR_PATH, 99 ApiTimeSeriesEntityAttribute, True)
100
101 -class ApiTimeSeriesCrossEntityMetadata(BaseApiObject):
102 _ATTRIBUTES = { 103 'maxEntityDisplayName' : ROAttr(), 104 'minEntityDisplayName' : ROAttr(), 105 'maxEntityName' : ROAttr(), 106 'minEntityName' : ROAttr(), 107 'numEntities' : ROAttr() 108 }
109
110 -class ApiTimeSeriesAggregateStatistics(BaseApiObject):
111 _ATTRIBUTES = { 112 'sampleTime' : ROAttr(datetime.datetime), 113 'sampleValue' : ROAttr(), 114 'count' : ROAttr(), 115 'min' : ROAttr(), 116 'minTime' : ROAttr(datetime.datetime), 117 'max' : ROAttr(), 118 'maxTime' : ROAttr(datetime.datetime), 119 'mean' : ROAttr(), 120 'stdDev' : ROAttr(), 121 'crossEntityMetadata' : ROAttr(ApiTimeSeriesCrossEntityMetadata) 122 }
123
124 -class ApiTimeSeriesData(BaseApiObject):
125 _ATTRIBUTES = { 126 'timestamp' : ROAttr(datetime.datetime), 127 'value' : ROAttr(), 128 'type' : ROAttr(), 129 'aggregateStatistics' : ROAttr(ApiTimeSeriesAggregateStatistics) 130 }
131
132 -class ApiTimeSeriesMetadata(BaseApiObject):
133 _ATTRIBUTES = { 134 'metricName' : ROAttr(), 135 'entityName' : ROAttr(), 136 'startTime' : ROAttr(datetime.datetime), 137 'endTime' : ROAttr(datetime.datetime), 138 'attributes' : ROAttr(), 139 'unitNumerators' : ROAttr(), 140 'unitDenominators' : ROAttr(), 141 'expression' : ROAttr(), 142 'alias' : ROAttr(), 143 'metricCollectionFrequencyMs': ROAttr(), 144 'rollupUsed' : ROAttr() 145 }
146
147 -class ApiTimeSeries(BaseApiObject):
148 _ATTRIBUTES = { 149 'metadata' : ROAttr(ApiTimeSeriesMetadata), 150 'data' : ROAttr(ApiTimeSeriesData), 151 }
152
153 -class ApiTimeSeriesResponse(BaseApiObject):
154 _ATTRIBUTES = { 155 'timeSeries' : ROAttr(ApiTimeSeries), 156 'warnings' : ROAttr(), 157 'errors' : ROAttr(), 158 'timeSeriesQuery' : ROAttr(), 159 }
160
161 -class ApiMetricSchema(BaseApiObject):
162 _ATTRIBUTES = { 163 'name' : ROAttr(), 164 'displayName' : ROAttr(), 165 'description' : ROAttr(), 166 'isCounter' : ROAttr(), 167 'unitNumerator' : ROAttr(), 168 'unitDenominator' : ROAttr(), 169 'aliases' : ROAttr(), 170 'sources' : ROAttr(), 171 }
172
173 -class ApiTimeSeriesEntityAttribute(BaseApiObject):
174 _ATTRIBUTES = { 175 'name' : ROAttr(), 176 'displayName' : ROAttr(), 177 'description' : ROAttr(), 178 'isValueCaseSensitive' : ROAttr() 179 }
180
181 -class ApiTimeSeriesEntityType(BaseApiObject):
182 _ATTRIBUTES = { 183 'name' : ROAttr(), 184 'category' : ROAttr(), 185 'displayName' : ROAttr(), 186 'description' : ROAttr(), 187 'nameForCrossEntityAggregateMetrics' : ROAttr(), 188 'immutableAttributeNames' : ROAttr(), 189 'mutableAttributeNames' : ROAttr(), 190 'entityNameFormat' : ROAttr(), 191 'entityDisplayNameForamt' : ROAttr(), 192 'parentMetricEntityTypeNames' : ROAttr() 193 }
194