@@ -55,14 +55,6 @@ def data_received(self, chunk):
55
55
pass
56
56
57
57
58
- class IndexHandler (BaseHandler ):
59
- @gen .coroutine
60
- def get (self ):
61
- with open ("index.html" ) as f :
62
- html = f .read ()
63
- self .write (html )
64
-
65
-
66
58
class AntiCrawler :
67
59
68
60
def __init__ (self , instance ):
@@ -126,8 +118,23 @@ def get_real_ip(self):
126
118
return x_real or remote_ip
127
119
128
120
121
+ class IndexHandler (BaseHandler ):
122
+ executor = ThreadPoolExecutor (100 )
123
+
124
+ @run_on_executor ()
125
+ def send_index (self ):
126
+ with open ("index.html" ) as f :
127
+ html = f .read ()
128
+ return html
129
+
130
+ @gen .coroutine
131
+ def get (self ):
132
+ resp = yield self .send_index ()
133
+ self .write (resp )
134
+
135
+
129
136
class ResourceHandler (BaseHandler ):
130
- executor = ThreadPoolExecutor (50 )
137
+ executor = ThreadPoolExecutor (100 )
131
138
132
139
@run_on_executor ()
133
140
def get_resource_data (self ):
@@ -193,7 +200,7 @@ def get(self):
193
200
194
201
195
202
class TopHandler (BaseHandler ):
196
- executor = ThreadPoolExecutor (50 )
203
+ executor = ThreadPoolExecutor (100 )
197
204
198
205
@run_on_executor ()
199
206
def get_top_resource (self ):
@@ -219,7 +226,7 @@ def get(self):
219
226
220
227
221
228
class NameHandler (BaseHandler ):
222
- executor = ThreadPoolExecutor (50 )
229
+ executor = ThreadPoolExecutor (100 )
223
230
224
231
@staticmethod
225
232
def json_encode (value ):
@@ -272,7 +279,7 @@ def get(self):
272
279
273
280
274
281
class MetricsHandler (BaseHandler ):
275
- executor = ThreadPoolExecutor (50 )
282
+ executor = ThreadPoolExecutor (100 )
276
283
277
284
@classmethod
278
285
def add (cls , type_name ):
@@ -304,6 +311,29 @@ def post(self):
304
311
self .write (resp )
305
312
306
313
314
+ class BlacklistHandler (BaseHandler ):
315
+ executor = ThreadPoolExecutor (100 )
316
+
317
+ @run_on_executor ()
318
+ def get_black_list (self ):
319
+ r = Redis ().r
320
+
321
+ keys = r .keys ("*" )
322
+ result = {}
323
+
324
+ for key in keys :
325
+ count = r .get (key )
326
+ ttl = r .ttl (key )
327
+ result ["key" ] = dict (count = count , ttl = ttl )
328
+
329
+ return result
330
+
331
+ @gen .coroutine
332
+ def get (self ):
333
+ resp = yield self .get_black_list ()
334
+ self .write (resp )
335
+
336
+
307
337
class RunServer :
308
338
root_path = os .path .dirname (__file__ )
309
339
static_path = os .path .join (root_path , '' )
@@ -312,6 +342,7 @@ class RunServer:
312
342
(r'/api/top' , TopHandler ),
313
343
(r'/api/name' , NameHandler ),
314
344
(r'/api/metrics' , MetricsHandler ),
345
+ (r'/api/blacklist' , BlacklistHandler ),
315
346
(r'/' , IndexHandler ),
316
347
(r'/(.*\.html|.*\.js|.*\.css|.*\.png|.*\.jpg|.*\.ico|.*\.gif|.*\.woff2)' , web .StaticFileHandler ,
317
348
{'path' : static_path }),
0 commit comments