-
Notifications
You must be signed in to change notification settings - Fork 0
/
appengine_stats.py
42 lines (35 loc) · 1.49 KB
/
appengine_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import absolute_import
import datetime
import time
import request_handler
import user_util
from google.appengine.api import memcache
class MemcacheStatus(request_handler.RequestHandler):
"""Handle requests to show information about the current state of memcache.
Gives raw data, suitable for plotting.
This is open-access so it's easy to write a script to download this
data and store it. Nothing here is sensitive.
TODO(csilvers): save the data and show a pretty graphy.
"""
@user_util.open_access
def get(self):
now = datetime.datetime.now()
now_time_t = int(time.mktime(now.timetuple()))
memcache_stats = memcache.get_stats()
if self.request.get('output') in ('text', 'txt'):
self.response.out.write(now_time_t)
self.response.out.write(' h:%(hits)s'
' m:%(misses)s'
' bh:%(byte_hits)s'
' i:%(items)s'
' b:%(bytes)s'
' oia:%(oldest_item_age)s'
'\n' % memcache_stats)
self.response.headers['Content-Type'] = "text/text"
else:
template_values = {
'now': now.ctime(),
'now_time_t': now_time_t,
'memcache_stats': memcache_stats,
}
self.render_jinja2_template("memcache_stats.html", template_values)