Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

small change

  • Loading branch information...
commit a9c601dfbb883ca9c844fa70c3a591af2787005b 1 parent 1e46d45
Peng Yuwei authored April 13, 2012
48  kanyun/server/api_server.py
@@ -33,7 +33,7 @@
33 33
 
34 34
 protocol:
35 35
     http://wiki.sinaapp.com/doku.php?id=monitoring
36  
-[u'S', u'instance-00000001@pyw.novalocal', u'cpu', u'total', 0, 5, 1332897600, 0]
  36
+[u'S', u'instance-000001@pyw.novalocal', u'cpu', u'total', 0, 5, 1332897600, 0]
37 37
 """
38 38
 
39 39
 logger = logging.getLogger()
@@ -133,11 +133,11 @@ def api_getdata(row_id, cf_str, scf_str, time_from=0, time_to=0):
133 133
     param type: UnicodeType and IntType
134 134
     return: recordset, count, bool(count > limit?)
135 135
     """
136  
-    if not isinstanceof(row_id, unicode)
137  
-        or not isinstanceof(cf_str, unicode)
138  
-        or not isinstanceof(scf_str, unicode)
139  
-        or not isinstanceof(time_from, int)
140  
-        or not isinstanceof(time_to, int):
  136
+    if not isinstance(row_id, unicode) \
  137
+        or not isinstance(cf_str, unicode) \
  138
+        or not isinstance(scf_str, unicode) \
  139
+        or not isinstance(time_from, int) \
  140
+        or not isinstance(time_to, int):
141 141
         return None, 0, True
142 142
         
143 143
     db = get_db()
@@ -156,9 +156,9 @@ def analyize_data(rs, period, statistic):
156 156
     """[private func]analyize the data
157 157
     period: minutes
158 158
     """
159  
-    if rs is None 
160  
-        or not isinstanceof(period, int)
161  
-        or not isinstanceof(statistic, int):
  159
+    if rs is None \
  160
+        or not isinstance(period, int) \
  161
+        or not isinstance(statistic, int):
162 162
         return None
163 163
     t = 0
164 164
     key_time = 0
@@ -200,7 +200,7 @@ def analyize_data(rs, period, statistic):
200 200
 
201 201
 ############################# public API interface ############################
202 202
 def api_get_instances_list(cf_str):
203  
-    if not isinstanceof(cf_str) is types.UnicodeType:
  203
+    if not isinstance(cf_str, unicode):
204 204
         print 'param types error'
205 205
         return None
206 206
     ret = list()
@@ -218,8 +218,8 @@ def api_get_instances_list(cf_str):
218 218
     
219 219
     
220 220
 def api_get_by_instance_id(row_id, cf_str):
221  
-    if not isinstanceof(row_id, unicode)
222  
-        or not isinstanceof(cf_str) is types.UnicodeType:
  221
+    if not isinstance(row_id, unicode) \
  222
+        or not isinstance(cf_str, unicode):
223 223
         print 'param types error'
224 224
         return None, 0, True
225 225
     db = get_db()
@@ -234,10 +234,10 @@ def api_getbykey(row_id, cf_str, scf_str, limit=20000):
234 234
     example:cf=u'vmnetwork',scf=u'10.0.0.1',key=u'instance-0000002'
235 235
     return: recordset, count, bool(count > limit?)
236 236
     """
237  
-    if not isinstanceof(row_id, unicode)
238  
-        or not isinstanceof(cf_str, unicode)
239  
-        or not isinstanceof(scf_str, unicode)
240  
-        or not isinstanceof(limit, int):
  237
+    if not isinstance(row_id, unicode) \
  238
+        or not isinstance(cf_str, unicode) \
  239
+        or not isinstance(scf_str, unicode) \
  240
+        or not isinstance(limit, int):
241 241
         print 'param types error'
242 242
         return None, 0, True
243 243
     db = get_db()
@@ -252,13 +252,13 @@ def api_statistic(row_id, cf_str, scf_str,
252 252
     """statistic is STATISTIC enum
253 253
     period default=5 minutes
254 254
     time_to default=0(now)"""
255  
-    if (not isinstanceof(row_id, unicode)
256  
-        or not isinstanceof(cf_str, unicode)
257  
-        or not isinstanceof(scf_str, unicode)
258  
-        or not isinstanceof(statistic, int)
259  
-        or not isinstanceof(period, int)
260  
-        or not isinstanceof(time_from, int)
261  
-        or not isinstanceof(time_to, int)):
  255
+    if (not isinstance(row_id, unicode) \
  256
+        or not isinstance(cf_str, unicode) \
  257
+        or not isinstance(scf_str, unicode) \
  258
+        or not isinstance(statistic, int) \
  259
+        or not isinstance(period, int) \
  260
+        or not isinstance(time_from, int) \
  261
+        or not isinstance(time_to, int)):
262 262
         print 'param types error'
263 263
         return None, 0, True
264 264
         
@@ -280,5 +280,5 @@ def api_statistic(row_id, cf_str, scf_str,
280 280
         ret_len = 0
281 281
     return ret, ret_len, all_data
282 282
 
283  
-########################## end public API interface #############################
  283
+######################### end public API interface ############################
284 284
 
7  kanyun/server/data_server.py
@@ -45,7 +45,8 @@
45 45
 class LivingStatus():
46 46
 
47 47
     def __init__(self, worker_id = '1'):
48  
-        self.min = 2 # 2min
  48
+        self.dietv = 2 * 60  # default die threshold value: 2min
  49
+        self.alert_interval = 60 # one alert every 60 seconds
49 50
         self.update()
50 51
         self.alerted = False
51 52
         self.worker_id = worker_id
@@ -56,7 +57,7 @@ def update(self):
56 57
         self.alerted = False
57 58
         
58 59
     def is_die(self):
59  
-        return time.time() - self.update_time > self.min * 60 
  60
+        return time.time() - self.update_time > self.dietv
60 61
         
61 62
     def on_die(self):
62 63
         ret = 0
@@ -65,7 +66,7 @@ def on_die(self):
65 66
             ret += 1
66 67
             
67 68
         # each minutes less than once
68  
-        if time.time() - self.previous_alert_time > 60: 
  69
+        if time.time() - self.previous_alert_time > self.alert_interval: 
69 70
             self.alert()
70 71
             ret += 1
71 72
             
2  kanyun/server/plugin_agent_srv.py
@@ -42,7 +42,7 @@ def get_cf_str(cf_str):
42 42
     """
43 43
     [('cpu', 'total', (utc_time, cpu_usage)), 
44 44
     ('mem', 'total', (utc_time, max, free)), 
45  
-    ('nic', 'vnet8', (utc_time, incoming, outgoing(内网))), 
  45
+    ('nic', 'vnet8', (utc_time, incoming, outgoing())), 
46 46
     ('blk', 'vda', (utc_time, read, write)), 
47 47
     ('blk', 'vdb', (utc_time, read, write))],
48 48
     """
4  tests/test_api_server.py
@@ -97,9 +97,9 @@ def testParamTypeCheck(self):
97 97
         statistic = None
98 98
         rs1, count, _ = api_server.api_statistic(None, None, None, None, period=5, time_from=0, time_to=0)
99 99
         rs2, count, _ = api_server.api_getbykey(None, cf_str, scf_str, limit=20000)
100  
-        rs3, count, _ = api_server.api_getbyInstanceID(row_id, cf_str)
  100
+        rs3, count, _ = api_server.api_get_by_instance_id(row_id, cf_str)
101 101
         rs4, count, _ = api_server.api_getdata(row_id, cf_str, scf_str, time_from=0, time_to=0)
102  
-        rs5 = api_server.api_getInstancesList(None)
  102
+        rs5 = api_server.api_get_instances_list(None)
103 103
         rs6 = api_server.analyize_data(None, period, statistic)
104 104
         assert(rs1 is None)
105 105
         assert(rs2 is None)
2  tests/test_call_plugin_agent.py
@@ -18,7 +18,7 @@
18 18
 
19 19
 import time
20 20
 
21  
-import plugin_agent
  21
+import kanyun.worker.plugin_agent as plugin_agent
22 22
 
23 23
 """
24 24
 CPU Calculation
1  tests/test_cassadb.py
@@ -61,6 +61,7 @@ def ObjectTest(self):
61 61
         column_count = 0
62 62
 
63 63
     def GetTest(self):
  64
+        import pycassa
64 65
         cf_str = "cpu"
65 66
         key = "instance-00000001@pyw.novalocal"
66 67
         super_column = 'total'
2  tests/test_client.py
@@ -17,7 +17,7 @@
17 17
 #    under the License.
18 18
 
19 19
 import time
20  
-from kanyun.server.api_client import ApiClient
  20
+from kanyun.client.api_client import ApiClient
21 21
 
22 22
 
23 23
 if __name__ == '__main__':
8  tests/test_data_server.py
@@ -41,6 +41,7 @@ def testLivingStatusFunc(self):
41 41
         print 'living'
42 42
         ls.update()
43 43
         self.assertTrue(not ls.is_die())
  44
+        ls.dietv = 5
44 45
         while not ls.is_die():
45 46
             now = time.localtime()
46 47
             sys.stdout.write("\r%02d:%02d:%02d waitting for die" % 
@@ -48,12 +49,13 @@ def testLivingStatusFunc(self):
48 49
             sys.stdout.flush()
49 50
             time.sleep(1)
50 51
         print
51  
-        print 'first event:'
52 52
         ret = ls.on_die()
  53
+        print 'first event:', ret
53 54
         self.assertTrue(ret == 2)
54  
-        print 'next event:'
  55
+        
55 56
         ret = ls.on_die()
56  
-        self.assertTrue(ret == 1)
  57
+        print 'next event:', ret
  58
+        self.assertTrue(ret == 0)
57 59
         print "LivingStatus test \t[\033[1;33mOK\033[0m]"
58 60
     
59 61
     

0 notes on commit a9c601d

Please sign in to comment.
Something went wrong with that request. Please try again.