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   
26 -def query_timeseries(resource_root, query, from_time=None, to_time=None, 27 desired_rollup=None, must_use_desired_rollup=None):
28 """ 29 Query for time series data from the CM time series data store. 30 @param query: Query string. 31 @param from_time: Start of the period to query (optional). 32 @type from_time: datetime.datetime Note the that datetime must either be time 33 zone aware or specified in the server time zone. See the 34 python datetime documentation for more details about python's 35 time zone handling. 36 @param to_time: End of the period to query (default = now). 37 This may be an ISO format string, or a datetime object. 38 @type to_time: datetime.datetime Note the that datetime must either be time 39 zone aware or specified in the server time zone. See the 40 python datetime documentation for more details about python's 41 time zone handling. 42 @param desired_rollup: The aggregate rollup to get data for. This can be 43 RAW, TEN_MINUTELY, HOURLY, SIX_HOURLY, DAILY, or 44 WEEKLY. Note that rollup desired is only a hint unless 45 must_use_desired_rollup is set to true. 46 @param must_use_desired_rollup: Indicates that the monitoring server should 47 return the data at the rollup desired. 48 @return: List of ApiTimeSeriesResponse 49 """ 50 params = {} 51 if query: 52 params['query'] = query 53 if from_time: 54 params['from'] = from_time.isoformat() 55 if to_time: 56 params['to'] = to_time.isoformat() 57 if desired_rollup: 58 params['desiredRollup'] = desired_rollup 59 if must_use_desired_rollup: 60 params['mustUseDesiredRollup'] = must_use_desired_rollup 61 return call(resource_root.get, TIME_SERIES_PATH, 62 ApiTimeSeriesResponse, True, params=params)
63
64 -def get_metric_schema(resource_root):
65 """ 66 Get the schema for all of the metrics. 67 @return: List of metric schema. 68 """ 69 return call(resource_root.get, METRIC_SCHEMA_PATH, 70 ApiMetricSchema, True)
71
72 -class ApiTimeSeriesCrossEntityMetadata(BaseApiObject):
73 _ATTRIBUTES = { 74 'maxEntityDisplayName' : ROAttr(), 75 'minEntityDisplayName' : ROAttr(), 76 'numEntities' : ROAttr() 77 }
78
79 -class ApiTimeSeriesAggregateStatistics(BaseApiObject):
80 _ATTRIBUTES = { 81 'sampleTime' : ROAttr(datetime.datetime), 82 'sampleValue' : ROAttr(), 83 'count' : ROAttr(), 84 'min' : ROAttr(), 85 'minTime' : ROAttr(datetime.datetime), 86 'max' : ROAttr(), 87 'maxTime' : ROAttr(datetime.datetime), 88 'mean' : ROAttr(), 89 'stdDev' : ROAttr(), 90 'crossEntityMetadata' : ROAttr(ApiTimeSeriesCrossEntityMetadata) 91 }
92
93 -class ApiTimeSeriesData(BaseApiObject):
94 _ATTRIBUTES = { 95 'timestamp' : ROAttr(datetime.datetime), 96 'value' : ROAttr(), 97 'type' : ROAttr(), 98 'aggregateStatistics' : ROAttr(ApiTimeSeriesAggregateStatistics) 99 }
100
101 -class ApiTimeSeriesMetadata(BaseApiObject):
102 _ATTRIBUTES = { 103 'metricName' : ROAttr(), 104 'entityName' : ROAttr(), 105 'startTime' : ROAttr(datetime.datetime), 106 'endTime' : ROAttr(datetime.datetime), 107 'attributes' : ROAttr(), 108 'unitNumerators' : ROAttr(), 109 'unitDenominators' : ROAttr(), 110 'expression' : ROAttr(), 111 'alias' : ROAttr(), 112 'metricCollectionFrequencyMs': ROAttr(), 113 'rollupUsed' : ROAttr() 114 }
115
116 -class ApiTimeSeries(BaseApiObject):
117 _ATTRIBUTES = { 118 'metadata' : ROAttr(ApiTimeSeriesMetadata), 119 'data' : ROAttr(ApiTimeSeriesData), 120 }
121
122 -class ApiTimeSeriesResponse(BaseApiObject):
123 _ATTRIBUTES = { 124 'timeSeries' : ROAttr(ApiTimeSeries), 125 'warnings' : ROAttr(), 126 'errors' : ROAttr(), 127 'timeSeriesQuery' : ROAttr(), 128 }
129
130 -class ApiMetricSchema(BaseApiObject):
131 _ATTRIBUTES = { 132 'name' : ROAttr(), 133 'isCounter' : ROAttr(), 134 'unitNumerator' : ROAttr(), 135 'unitDenominator' : ROAttr(), 136 'aliases' : ROAttr(), 137 'sources' : ROAttr(), 138 }
139