Authored by BuddyJack

Fix

import collectd
import MySQLdb
import copy
import re
Cobar_config = {
'host': '127.0.0.1',
... ... @@ -70,10 +71,12 @@ class CobarSchemaStates(object):
sch_net_in = 0
sch_net_out = 0
sch_cobar_10 = 0
sch_cobar_50 = 0
sch_cobar_200 = 0
sch_cobar_1000 = 0
sch_cobar_2000 = 0
sch_node_10 = 0
sch_node_50 = 0
sch_node_200 = 0
sch_node_1000 = 0
sch_node_2000 = 0
... ... @@ -84,14 +87,15 @@ g_schema_states = dict()
class CobarTableStates(object):
table = ''
tb_max_concurrent = 0
tb_rcount = 0
tb_wcount = 0
tb_cobar_10 = 0
tb_cobar_50 = 0
tb_cobar_200 = 0
tb_cobar_1000 = 0
tb_cobar_2000 = 0
tb_node_10 = 0
tb_node_50 = 0
tb_node_200 = 0
tb_node_1000 = 0
tb_node_2000 = 0
... ... @@ -143,18 +147,27 @@ def get_cobar_tb_states(con):
global g_table_states
for row in res.fetchall():
tmp_tb_states = CobarTableStates()
tmp_tb_states.table = row['table']
tmp_tb_states.tb_max_concurrent = row['maxConcurrent']
tmp_tb_states.tb_rcount = row['rCount']
tmp_tb_states.tb_wcount = row['wCount']
tmp_tb_states.tb_cobar_10 = row['alltime_10']
tmp_tb_states.tb_cobar_200 = row['alltime_200']
tmp_tb_states.tb_cobar_1000 = row['alltime_1000']
tmp_tb_states.tb_cobar_2000 = row['alltime_2000']
tmp_tb_states.tb_node_10 = row['nodetime_10']
tmp_tb_states.tb_node_200 = row['nodetime_200']
tmp_tb_states.tb_node_1000 = row['nodetime_1000']
tmp_tb_states.tb_node_2000 = row['nodetime_2000']
tmp_tb_states.table = row['TABLE'].lower()
tmp_tb_states.tb_rcount = int(row['R'])
tmp_tb_states.tb_wcount = int(row['W'])
tmp_ttl_tb = row['ALL_TTL_COUNT']
tmp_ttl_tb = tmp_ttl_tb.lstrip('[')
tmp_ttl_tb = tmp_ttl_tb.rstrip(']')
ttl_tb = re.split(r'[;,\s]\s*', tmp_ttl_tb)
tmp_tb_states.tb_cobar_10 = int(ttl_tb[0])
tmp_tb_states.tb_cobar_50 = int(ttl_tb[1])
tmp_tb_states.tb_cobar_200 = int(ttl_tb[2])
tmp_tb_states.tb_cobar_1000 = int(ttl_tb[3])
tmp_tb_states.tb_cobar_2000 = int(ttl_tb[4])
tmp_ttl_tb = row['NODE_TTL_COUNT']
tmp_ttl_tb = tmp_ttl_tb.lstrip('[')
tmp_ttl_tb = tmp_ttl_tb.rstrip(']')
ttl_tb = re.split(r'[;,\s]\s*', tmp_ttl_tb)
tmp_tb_states.tb_node_10 = int(ttl_tb[0])
tmp_tb_states.tb_node_50 = int(ttl_tb[1])
tmp_tb_states.tb_node_200 = int(ttl_tb[2])
tmp_tb_states.tb_node_1000 = int(ttl_tb[3])
tmp_tb_states.tb_node_2000 = int(ttl_tb[4])
old_states = g_table_states.get(tmp_tb_states.table)
if old_states is None:
g_table_states[tmp_tb_states.table] = tmp_tb_states
... ... @@ -162,14 +175,15 @@ def get_cobar_tb_states(con):
else:
tb_states = CobarTableStates()
tb_states.table = tmp_tb_states.table
tb_states.tb_max_concurrent = tmp_tb_states.tb_max_concurrent
tb_states.tb_rcount = tmp_tb_states.tb_rcount - old_states.tb_rcount
tb_states.tb_wcount = tmp_tb_states.tb_wcount - old_states.tb_wcount
tb_states.tb_cobar_10 = tmp_tb_states.tb_cobar_10 - old_states.tb_cobar_10
tb_states.tb_cobar_50 = tmp_tb_states.tb_cobar_50 - old_states.tb_cobar_50
tb_states.tb_cobar_200 = tmp_tb_states.tb_cobar_200 - old_states.tb_cobar_200
tb_states.tb_cobar_1000 = tmp_tb_states.tb_cobar_1000 - old_states.tb_cobar_1000
tb_states.tb_cobar_2000 = tmp_tb_states.tb_cobar_2000 - old_states.tb_cobar_2000
tb_states.tb_node_10 = tmp_tb_states.tb_node_10 - old_states.tb_node_10
tb_states.tb_node_50 = tmp_tb_states.tb_node_50 - old_states.tb_node_50
tb_states.tb_node_200 = tmp_tb_states.tb_node_200 - old_states.tb_node_200
tb_states.tb_node_1000 = tmp_tb_states.tb_node_1000 - old_states.tb_node_1000
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):
global g_schema_states
for row in res.fetchall():
tmp_schema_states = CobarSchemaStates()
tmp_schema_states.schema = row['schema']
tmp_schema_states.sch_max_concurrent = row['maxConcurrent']
tmp_schema_states.sch_net_in = row['netInBytes']
tmp_schema_states.sch_net_out = row['netOutBytes']
tmp_schema_states.sch_rcount = row['rCount']
tmp_schema_states.sch_wcount = row['wCount']
tmp_schema_states.sch_cobar_10 = row['alltime_10']
tmp_schema_states.sch_cobar_200 = row['alltime_200']
tmp_schema_states.sch_cobar_1000 = row['alltime_1000']
tmp_schema_states.sch_cobar_2000 = row['alltime_2000']
tmp_schema_states.sch_node_10 = row['nodetime_10']
tmp_schema_states.sch_node_200 = row['nodetime_200']
tmp_schema_states.sch_node_1000 = row['nodetime_1000']
tmp_schema_states.sch_node_2000 = row['nodetime_2000']
old_states = g_table_states.get(tmp_schema_states.table)
tmp_schema_states.schema = row['SCHEMA'].lower()
tmp_schema_states.sch_max_concurrent = int(row['MAX'])
tmp_schema_states.sch_net_in = int(row['NET_IN'])
tmp_schema_states.sch_net_out = int(row['NET_OUT'])
tmp_schema_states.sch_rcount = int(row['R'])
tmp_schema_states.sch_wcount = int(row['W'])
tmp_ttl_sch = row['ALL_TTL_COUNT']
tmp_ttl_sch = tmp_ttl_sch.lstrip('[')
tmp_ttl_sch = tmp_ttl_sch.rstrip(']')
ttl_sch = re.split(r'[;,\s]\s*', tmp_ttl_sch)
tmp_schema_states.sch_cobar_10 = int(ttl_sch[0])
tmp_schema_states.sch_cobar_50 = int(ttl_sch[1])
tmp_schema_states.sch_cobar_200 = int(ttl_sch[2])
tmp_schema_states.sch_cobar_1000 = int(ttl_sch[3])
tmp_schema_states.sch_cobar_2000 = int(ttl_sch[4])
tmp_ttl_sch = row['NODE_TTL_COUNT']
tmp_ttl_sch = tmp_ttl_sch.lstrip('[')
tmp_ttl_sch = tmp_ttl_sch.rstrip(']')
ttl_sch = re.split(r'[;,\s]\s*', tmp_ttl_sch)
tmp_schema_states.sch_node_10 = int(ttl_sch[0])
tmp_schema_states.sch_node_50 = int(ttl_sch[1])
tmp_schema_states.sch_node_200 = int(ttl_sch[2])
tmp_schema_states.sch_node_1000 = int(ttl_sch[3])
tmp_schema_states.sch_node_2000 = int(ttl_sch[4])
old_states = g_schema_states.get(tmp_schema_states.schema)
if old_states is None:
g_table_states[tmp_schema_states.schema] = tmp_schema_states
g_schema_states[tmp_schema_states.schema] = tmp_schema_states
# dispatch_states(tmp_schema_states.schema, tmp_schema_states)
else:
sch_states = CobarSchemaStates()
... ... @@ -209,10 +233,12 @@ def get_cobar_schema_states(con):
sch_states.sch_wcount = tmp_schema_states.sch_wcount - old_states.sch_wcount
sch_states.sch_rcount = tmp_schema_states.sch_rcount - old_states.sch_rcount
sch_states.sch_cobar_10 = tmp_schema_states.sch_cobar_10 - old_states.sch_cobar_10
sch_states.sch_cobar_50 = tmp_schema_states.sch_cobar_50 - old_states.sch_cobar_50
sch_states.sch_cobar_200 = tmp_schema_states.sch_cobar_200 - old_states.sch_cobar_200
sch_states.sch_cobar_1000 = tmp_schema_states.sch_cobar_1000 - old_states.sch_cobar_1000
sch_states.sch_cobar_2000 = tmp_schema_states.sch_cobar_2000 - old_states.sch_cobar_2000
sch_states.sch_node_10 = tmp_schema_states.sch_node_10 - old_states.sch_node_10
sch_states.sch_node_50 = tmp_schema_states.sch_node_50 - old_states.sch_node_50
sch_states.sch_node_200 = tmp_schema_states.sch_node_200 - old_states.sch_node_200
sch_states.sch_node_1000 = tmp_schema_states.sch_node_1000 - old_states.sch_node_1000
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):
pass
if not states:
return
data_dic = vars(states).iteritems()
if type == 'shcema':
prefix = data_dic['schema']
prefix = ''
if type == 'schema':
prefix = states.schema
else:
prefix = data_dic['table']
prefix = states.table
data_dic = vars(states).iteritems()
for key, value in data_dic:
if str(key) == 'shcema' or str(key) == 'table':
if str(key) == 'schema' or str(key) == 'table':
continue
dispatch_value(key, value, type, prefix)
... ...