Skip to content

Commit 3345110

Browse files
author
Jon Wayne Parrott
committed
Adding appstats sample (#293)
Change-Id: Ia0a54ea44390a77b2ea786c95e033d9f6f8ff51d
1 parent ba4655c commit 3345110

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

appengine/appstats/app.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
runtime: python27
2+
api_version: 1
3+
threadsafe: yes
4+
5+
builtins:
6+
- appstats: on
7+
8+
handlers:
9+
- url: .*
10+
script: main.app
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
# The app engine runtime will call this function during instance startup.
17+
def webapp_add_wsgi_middleware(app):
18+
from google.appengine.ext.appstats import recording
19+
app = recording.appstats_wsgi_middleware(app)
20+
return app

appengine/appstats/main.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""
16+
Sample Google App Engine application that demonstrates using appstats.
17+
18+
For more information about App Engine, see README.md under /appengine.
19+
"""
20+
21+
# [START all]
22+
from google.appengine.api import memcache
23+
import webapp2
24+
25+
26+
class MainPage(webapp2.RequestHandler):
27+
def get(self):
28+
# Perform some RPCs so that appstats can capture them.
29+
memcache.set('example_key', 50)
30+
value = memcache.get('example_key')
31+
self.response.write('Value is: {}'.format(value))
32+
33+
app = webapp2.WSGIApplication([
34+
('/', MainPage)
35+
], debug=True)
36+
# [END all]

appengine/appstats/main_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import main
16+
import webtest
17+
18+
19+
def test_app(testbed):
20+
app = webtest.TestApp(main.app)
21+
app.get('/')

0 commit comments

Comments
 (0)