forked from alsotang/goagent_monitor
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi_handler.py
48 lines (32 loc) · 1.06 KB
/
api_handler.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
43
44
45
46
47
48
# coding: utf-8
import webapp2
from google.appengine.api import urlfetch
from google.appengine.api import memcache
import json
from monitor_config import config as monitor_config
import list_handler
def getApi(cluster_id):
appids = list_handler.get_list(cluster_id)
appid_dict = memcache.get_multi(appids,'',cluster_id)
response_dict = {
"B_available": [],
"C_over_quota": [],
}
for appid, val in appid_dict.iteritems():
if val is True:
response_dict['B_available'].append(appid)
elif val is False:
response_dict['C_over_quota'].append(appid)
response_dict['A_status_msg'] = "今日还剩 %dGB/%dGB 流量" % (len(response_dict['B_available']), len(appids))
return response_dict
def getJson(cluster_id):
response_json = json.dumps(getApi(cluster_id), ensure_ascii=False)
return response_json
class ApiHandler(webapp2.RequestHandler):
def get(self, cluster_id=None):
response_json = getJson(cluster_id)
self.response.write(response_json)
app = webapp2.WSGIApplication([
# (r'/api', ApiHandler),
(r'/api/(.*)', ApiHandler)
], debug=True)