Authored by BuddyJack

Fix

1 import collectd 1 import collectd
2 import MySQLdb 2 import MySQLdb
3 import copy 3 import copy
  4 +import re
4 5
5 Cobar_config = { 6 Cobar_config = {
6 'host': '127.0.0.1', 7 'host': '127.0.0.1',
@@ -70,10 +71,12 @@ class CobarSchemaStates(object): @@ -70,10 +71,12 @@ class CobarSchemaStates(object):
70 sch_net_in = 0 71 sch_net_in = 0
71 sch_net_out = 0 72 sch_net_out = 0
72 sch_cobar_10 = 0 73 sch_cobar_10 = 0
  74 + sch_cobar_50 = 0
73 sch_cobar_200 = 0 75 sch_cobar_200 = 0
74 sch_cobar_1000 = 0 76 sch_cobar_1000 = 0
75 sch_cobar_2000 = 0 77 sch_cobar_2000 = 0
76 sch_node_10 = 0 78 sch_node_10 = 0
  79 + sch_node_50 = 0
77 sch_node_200 = 0 80 sch_node_200 = 0
78 sch_node_1000 = 0 81 sch_node_1000 = 0
79 sch_node_2000 = 0 82 sch_node_2000 = 0
@@ -84,14 +87,15 @@ g_schema_states = dict() @@ -84,14 +87,15 @@ g_schema_states = dict()
84 87
85 class CobarTableStates(object): 88 class CobarTableStates(object):
86 table = '' 89 table = ''
87 - tb_max_concurrent = 0  
88 tb_rcount = 0 90 tb_rcount = 0
89 tb_wcount = 0 91 tb_wcount = 0
90 tb_cobar_10 = 0 92 tb_cobar_10 = 0
  93 + tb_cobar_50 = 0
91 tb_cobar_200 = 0 94 tb_cobar_200 = 0
92 tb_cobar_1000 = 0 95 tb_cobar_1000 = 0
93 tb_cobar_2000 = 0 96 tb_cobar_2000 = 0
94 tb_node_10 = 0 97 tb_node_10 = 0
  98 + tb_node_50 = 0
95 tb_node_200 = 0 99 tb_node_200 = 0
96 tb_node_1000 = 0 100 tb_node_1000 = 0
97 tb_node_2000 = 0 101 tb_node_2000 = 0
@@ -143,18 +147,27 @@ def get_cobar_tb_states(con): @@ -143,18 +147,27 @@ def get_cobar_tb_states(con):
143 global g_table_states 147 global g_table_states
144 for row in res.fetchall(): 148 for row in res.fetchall():
145 tmp_tb_states = CobarTableStates() 149 tmp_tb_states = CobarTableStates()
146 - tmp_tb_states.table = row['table']  
147 - tmp_tb_states.tb_max_concurrent = row['maxConcurrent']  
148 - tmp_tb_states.tb_rcount = row['rCount']  
149 - tmp_tb_states.tb_wcount = row['wCount']  
150 - tmp_tb_states.tb_cobar_10 = row['alltime_10']  
151 - tmp_tb_states.tb_cobar_200 = row['alltime_200']  
152 - tmp_tb_states.tb_cobar_1000 = row['alltime_1000']  
153 - tmp_tb_states.tb_cobar_2000 = row['alltime_2000']  
154 - tmp_tb_states.tb_node_10 = row['nodetime_10']  
155 - tmp_tb_states.tb_node_200 = row['nodetime_200']  
156 - tmp_tb_states.tb_node_1000 = row['nodetime_1000']  
157 - tmp_tb_states.tb_node_2000 = row['nodetime_2000'] 150 + tmp_tb_states.table = row['TABLE'].lower()
  151 + tmp_tb_states.tb_rcount = int(row['R'])
  152 + tmp_tb_states.tb_wcount = int(row['W'])
  153 + tmp_ttl_tb = row['ALL_TTL_COUNT']
  154 + tmp_ttl_tb = tmp_ttl_tb.lstrip('[')
  155 + tmp_ttl_tb = tmp_ttl_tb.rstrip(']')
  156 + ttl_tb = re.split(r'[;,\s]\s*', tmp_ttl_tb)
  157 + tmp_tb_states.tb_cobar_10 = int(ttl_tb[0])
  158 + tmp_tb_states.tb_cobar_50 = int(ttl_tb[1])
  159 + tmp_tb_states.tb_cobar_200 = int(ttl_tb[2])
  160 + tmp_tb_states.tb_cobar_1000 = int(ttl_tb[3])
  161 + tmp_tb_states.tb_cobar_2000 = int(ttl_tb[4])
  162 + tmp_ttl_tb = row['NODE_TTL_COUNT']
  163 + tmp_ttl_tb = tmp_ttl_tb.lstrip('[')
  164 + tmp_ttl_tb = tmp_ttl_tb.rstrip(']')
  165 + ttl_tb = re.split(r'[;,\s]\s*', tmp_ttl_tb)
  166 + tmp_tb_states.tb_node_10 = int(ttl_tb[0])
  167 + tmp_tb_states.tb_node_50 = int(ttl_tb[1])
  168 + tmp_tb_states.tb_node_200 = int(ttl_tb[2])
  169 + tmp_tb_states.tb_node_1000 = int(ttl_tb[3])
  170 + tmp_tb_states.tb_node_2000 = int(ttl_tb[4])
158 old_states = g_table_states.get(tmp_tb_states.table) 171 old_states = g_table_states.get(tmp_tb_states.table)
159 if old_states is None: 172 if old_states is None:
160 g_table_states[tmp_tb_states.table] = tmp_tb_states 173 g_table_states[tmp_tb_states.table] = tmp_tb_states
@@ -162,14 +175,15 @@ def get_cobar_tb_states(con): @@ -162,14 +175,15 @@ def get_cobar_tb_states(con):
162 else: 175 else:
163 tb_states = CobarTableStates() 176 tb_states = CobarTableStates()
164 tb_states.table = tmp_tb_states.table 177 tb_states.table = tmp_tb_states.table
165 - tb_states.tb_max_concurrent = tmp_tb_states.tb_max_concurrent  
166 tb_states.tb_rcount = tmp_tb_states.tb_rcount - old_states.tb_rcount 178 tb_states.tb_rcount = tmp_tb_states.tb_rcount - old_states.tb_rcount
167 tb_states.tb_wcount = tmp_tb_states.tb_wcount - old_states.tb_wcount 179 tb_states.tb_wcount = tmp_tb_states.tb_wcount - old_states.tb_wcount
168 tb_states.tb_cobar_10 = tmp_tb_states.tb_cobar_10 - old_states.tb_cobar_10 180 tb_states.tb_cobar_10 = tmp_tb_states.tb_cobar_10 - old_states.tb_cobar_10
  181 + tb_states.tb_cobar_50 = tmp_tb_states.tb_cobar_50 - old_states.tb_cobar_50
169 tb_states.tb_cobar_200 = tmp_tb_states.tb_cobar_200 - old_states.tb_cobar_200 182 tb_states.tb_cobar_200 = tmp_tb_states.tb_cobar_200 - old_states.tb_cobar_200
170 tb_states.tb_cobar_1000 = tmp_tb_states.tb_cobar_1000 - old_states.tb_cobar_1000 183 tb_states.tb_cobar_1000 = tmp_tb_states.tb_cobar_1000 - old_states.tb_cobar_1000
171 tb_states.tb_cobar_2000 = tmp_tb_states.tb_cobar_2000 - old_states.tb_cobar_2000 184 tb_states.tb_cobar_2000 = tmp_tb_states.tb_cobar_2000 - old_states.tb_cobar_2000
172 tb_states.tb_node_10 = tmp_tb_states.tb_node_10 - old_states.tb_node_10 185 tb_states.tb_node_10 = tmp_tb_states.tb_node_10 - old_states.tb_node_10
  186 + tb_states.tb_node_50 = tmp_tb_states.tb_node_50 - old_states.tb_node_50
173 tb_states.tb_node_200 = tmp_tb_states.tb_node_200 - old_states.tb_node_200 187 tb_states.tb_node_200 = tmp_tb_states.tb_node_200 - old_states.tb_node_200
174 tb_states.tb_node_1000 = tmp_tb_states.tb_node_1000 - old_states.tb_node_1000 188 tb_states.tb_node_1000 = tmp_tb_states.tb_node_1000 - old_states.tb_node_1000
175 tb_states.tb_node_2000 = tmp_tb_states.tb_node_2000 - old_states.tb_node_2000 189 tb_states.tb_node_2000 = tmp_tb_states.tb_node_2000 - old_states.tb_node_2000
@@ -182,23 +196,33 @@ def get_cobar_schema_states(con): @@ -182,23 +196,33 @@ def get_cobar_schema_states(con):
182 global g_schema_states 196 global g_schema_states
183 for row in res.fetchall(): 197 for row in res.fetchall():
184 tmp_schema_states = CobarSchemaStates() 198 tmp_schema_states = CobarSchemaStates()
185 - tmp_schema_states.schema = row['schema']  
186 - tmp_schema_states.sch_max_concurrent = row['maxConcurrent']  
187 - tmp_schema_states.sch_net_in = row['netInBytes']  
188 - tmp_schema_states.sch_net_out = row['netOutBytes']  
189 - tmp_schema_states.sch_rcount = row['rCount']  
190 - tmp_schema_states.sch_wcount = row['wCount']  
191 - tmp_schema_states.sch_cobar_10 = row['alltime_10']  
192 - tmp_schema_states.sch_cobar_200 = row['alltime_200']  
193 - tmp_schema_states.sch_cobar_1000 = row['alltime_1000']  
194 - tmp_schema_states.sch_cobar_2000 = row['alltime_2000']  
195 - tmp_schema_states.sch_node_10 = row['nodetime_10']  
196 - tmp_schema_states.sch_node_200 = row['nodetime_200']  
197 - tmp_schema_states.sch_node_1000 = row['nodetime_1000']  
198 - tmp_schema_states.sch_node_2000 = row['nodetime_2000']  
199 - old_states = g_table_states.get(tmp_schema_states.table) 199 + tmp_schema_states.schema = row['SCHEMA'].lower()
  200 + tmp_schema_states.sch_max_concurrent = int(row['MAX'])
  201 + tmp_schema_states.sch_net_in = int(row['NET_IN'])
  202 + tmp_schema_states.sch_net_out = int(row['NET_OUT'])
  203 + tmp_schema_states.sch_rcount = int(row['R'])
  204 + tmp_schema_states.sch_wcount = int(row['W'])
  205 + tmp_ttl_sch = row['ALL_TTL_COUNT']
  206 + tmp_ttl_sch = tmp_ttl_sch.lstrip('[')
  207 + tmp_ttl_sch = tmp_ttl_sch.rstrip(']')
  208 + ttl_sch = re.split(r'[;,\s]\s*', tmp_ttl_sch)
  209 + tmp_schema_states.sch_cobar_10 = int(ttl_sch[0])
  210 + tmp_schema_states.sch_cobar_50 = int(ttl_sch[1])
  211 + tmp_schema_states.sch_cobar_200 = int(ttl_sch[2])
  212 + tmp_schema_states.sch_cobar_1000 = int(ttl_sch[3])
  213 + tmp_schema_states.sch_cobar_2000 = int(ttl_sch[4])
  214 + tmp_ttl_sch = row['NODE_TTL_COUNT']
  215 + tmp_ttl_sch = tmp_ttl_sch.lstrip('[')
  216 + tmp_ttl_sch = tmp_ttl_sch.rstrip(']')
  217 + ttl_sch = re.split(r'[;,\s]\s*', tmp_ttl_sch)
  218 + tmp_schema_states.sch_node_10 = int(ttl_sch[0])
  219 + tmp_schema_states.sch_node_50 = int(ttl_sch[1])
  220 + tmp_schema_states.sch_node_200 = int(ttl_sch[2])
  221 + tmp_schema_states.sch_node_1000 = int(ttl_sch[3])
  222 + tmp_schema_states.sch_node_2000 = int(ttl_sch[4])
  223 + old_states = g_schema_states.get(tmp_schema_states.schema)
200 if old_states is None: 224 if old_states is None:
201 - g_table_states[tmp_schema_states.schema] = tmp_schema_states 225 + g_schema_states[tmp_schema_states.schema] = tmp_schema_states
202 # dispatch_states(tmp_schema_states.schema, tmp_schema_states) 226 # dispatch_states(tmp_schema_states.schema, tmp_schema_states)
203 else: 227 else:
204 sch_states = CobarSchemaStates() 228 sch_states = CobarSchemaStates()
@@ -209,10 +233,12 @@ def get_cobar_schema_states(con): @@ -209,10 +233,12 @@ def get_cobar_schema_states(con):
209 sch_states.sch_wcount = tmp_schema_states.sch_wcount - old_states.sch_wcount 233 sch_states.sch_wcount = tmp_schema_states.sch_wcount - old_states.sch_wcount
210 sch_states.sch_rcount = tmp_schema_states.sch_rcount - old_states.sch_rcount 234 sch_states.sch_rcount = tmp_schema_states.sch_rcount - old_states.sch_rcount
211 sch_states.sch_cobar_10 = tmp_schema_states.sch_cobar_10 - old_states.sch_cobar_10 235 sch_states.sch_cobar_10 = tmp_schema_states.sch_cobar_10 - old_states.sch_cobar_10
  236 + sch_states.sch_cobar_50 = tmp_schema_states.sch_cobar_50 - old_states.sch_cobar_50
212 sch_states.sch_cobar_200 = tmp_schema_states.sch_cobar_200 - old_states.sch_cobar_200 237 sch_states.sch_cobar_200 = tmp_schema_states.sch_cobar_200 - old_states.sch_cobar_200
213 sch_states.sch_cobar_1000 = tmp_schema_states.sch_cobar_1000 - old_states.sch_cobar_1000 238 sch_states.sch_cobar_1000 = tmp_schema_states.sch_cobar_1000 - old_states.sch_cobar_1000
214 sch_states.sch_cobar_2000 = tmp_schema_states.sch_cobar_2000 - old_states.sch_cobar_2000 239 sch_states.sch_cobar_2000 = tmp_schema_states.sch_cobar_2000 - old_states.sch_cobar_2000
215 sch_states.sch_node_10 = tmp_schema_states.sch_node_10 - old_states.sch_node_10 240 sch_states.sch_node_10 = tmp_schema_states.sch_node_10 - old_states.sch_node_10
  241 + sch_states.sch_node_50 = tmp_schema_states.sch_node_50 - old_states.sch_node_50
216 sch_states.sch_node_200 = tmp_schema_states.sch_node_200 - old_states.sch_node_200 242 sch_states.sch_node_200 = tmp_schema_states.sch_node_200 - old_states.sch_node_200
217 sch_states.sch_node_1000 = tmp_schema_states.sch_node_1000 - old_states.sch_node_1000 243 sch_states.sch_node_1000 = tmp_schema_states.sch_node_1000 - old_states.sch_node_1000
218 sch_states.sch_node_2000 = tmp_schema_states.sch_node_2000 - old_states.sch_node_2000 244 sch_states.sch_node_2000 = tmp_schema_states.sch_node_2000 - old_states.sch_node_2000
@@ -255,13 +281,14 @@ def dispatch_nstates(type, states): @@ -255,13 +281,14 @@ def dispatch_nstates(type, states):
255 pass 281 pass
256 if not states: 282 if not states:
257 return 283 return
258 - data_dic = vars(states).iteritems()  
259 - if type == 'shcema':  
260 - prefix = data_dic['schema'] 284 + prefix = ''
  285 + if type == 'schema':
  286 + prefix = states.schema
261 else: 287 else:
262 - prefix = data_dic['table'] 288 + prefix = states.table
  289 + data_dic = vars(states).iteritems()
263 for key, value in data_dic: 290 for key, value in data_dic:
264 - if str(key) == 'shcema' or str(key) == 'table': 291 + if str(key) == 'schema' or str(key) == 'table':
265 continue 292 continue
266 dispatch_value(key, value, type, prefix) 293 dispatch_value(key, value, type, prefix)
267 294