def post(self, app_id): """ Saves profiling information about a Google App Engine application to the Datastore, for viewing by the GET method. Args: app_id: A str that uniquely identifies the Google App Engine application we are storing data for. """ encoded_data = self.request.body data = json.loads(encoded_data) the_time = int(data['timestamp']) reversed_time = (2**34 - the_time) * 1000000 request_info = RequestInfo( id = app_id + str(reversed_time), # puts entities time descending. app_id = app_id, timestamp = datetime.datetime.fromtimestamp(data['timestamp']), num_of_requests = data['request_rate']) request_info.put()
def post(self, app_id): """ Saves profiling information about a Google App Engine application to the Datastore, for viewing by the GET method. Args: app_id: A str that uniquely identifies the Google App Engine application we are storing data for. """ encoded_data = self.request.body data = json.loads(encoded_data) the_time = int(data['timestamp']) reversed_time = (2**34 - the_time) * 1000000 request_info = RequestInfo( id=app_id + str(reversed_time), # puts entities time descending. app_id=app_id, timestamp=datetime.datetime.fromtimestamp(data['timestamp']), num_of_requests=data['request_rate']) request_info.put()
def fetch_request_info(app_id): """ Fetches request per second information from the datastore for a given application. Args: app_id: A str, the application identifier. Returns: A list of dictionaries filled with timestamps and number of requests per second. """ query = RequestInfo.query(RequestInfo.app_id == app_id) requests = query.fetch(MAX_REQUESTS_DATA_POINTS) request_info = [] for request in requests: request_info.append( {"timestamp": int(request.timestamp.strftime("%s")), "num_of_requests": request.num_of_requests} ) return request_info
def fetch_request_info(app_id): """ Fetches request per second information from the datastore for a given application. Args: app_id: A str, the application identifier. Returns: A list of dictionaries filled with timestamps and number of requests per second. """ query = RequestInfo.query(RequestInfo.app_id == app_id) request_info = [] for request in query.iter(): request_info.append({ 'timestamp': int(request.timestamp.strftime('%s')), 'num_of_requests': request.num_of_requests, 'avg_request_rate': request.avg_request_rate }) return request_info