示例#1
0
文件: main.py 项目: ycg/MySQL-DBMS
    def get_mysql_data(self, host_info):
        try:
            # aa = time.time()
            host_id = host_info.host_id
            mysql_data = cache.get_mysql_data_by_host_id(host_id)
            mysql_data.mysql_variables = host_info.mysql_variables
            data_new = self.get_dic_data(host_info, show_global_status_sql)
            cache.set_new_mysql_data(host_id, data_new)

            # set mysql item value
            for item_name in item_names:
                cache.set_item_value(host_id, item_name.lower())

            for item_name in item_names_for_byte:
                cache.set_item_value_for_byte(host_id, item_name.lower())

            for item_name in item_names_for_number:
                cache.set_item_value_for_number(host_id, item_name.lower())

            # get mysql replication
            self.get_mysql_slave_status(host_info)

            # get binlog size total
            total_size = 0
            if (mysql_data.mysql_variables.log_bin == "ON"):
                for row in db_util.fetchall(host_info, "show master logs;"):
                    total_size += int(row["File_size"])
            mysql_data.binlog_size_total = common.convert_for_byte(total_size)

            # mysql data calculate
            mysql_data.uptime = int(data_new["uptime"]) / 60 / 60 / 24
            mysql_data.dml = mysql_data.com_insert + mysql_data.com_update + mysql_data.com_delete
            mysql_data.dirty_page_pct = round(
                float(mysql_data.innodb_buffer_pool_pages_dirty) /
                float(mysql_data.innodb_buffer_pool_pages_total) * 100, 2)
            mysql_data.data_page_pct = round(
                float(mysql_data.innodb_buffer_pool_pages_data) /
                float(mysql_data.innodb_buffer_pool_pages_total) * 100, 2)
            mysql_data.buffer_pool_hit = (
                1 - int(data_new["innodb_buffer_pool_reads"]) /
                (int(data_new["innodb_buffer_pool_read_requests"]) +
                 int(data_new["innodb_buffer_pool_reads"]))) * 100
            if (mysql_data.binlog_cache_use > 0):
                mysql_data.binlog_cache_hit = (
                    1 - mysql_data.binlog_cache_disk_use /
                    mysql_data.binlog_cache_use) * 100
            else:
                mysql_data.binlog_cache_hit = 0

            cache.set_old_mysql_data(host_id, data_new)
            # bb = time.time()
            # print ("{0}-{1}".format(host_id, (bb - aa)))
        except Exception as e:
            traceback.print_exc()
示例#2
0
文件: main.py 项目: ycg/MySQL-DBMS
 def check_master_and_slave_relation(self):
     # 有的mysql既是主库也是从库,这个要理清逻辑
     uuid_key = "Slave_UUID"
     for host_info in cache.get_all_host_infos():
         result = db_util.fetchall(host_info, "show slave hosts;")
示例#3
0
文件: main.py 项目: ycg/MySQL-DBMS
 def get_dic_data(self, host_info, sql):
     result = {}
     for row in db_util.fetchall(host_info, sql):
         result[row.get("Variable_name").lower()] = row.get("Value")
     return result
示例#4
0
文件: main.py 项目: ycg/MySQL-DBMS
 def get_mysql_variables_info(self, host_info):
     info = entity.Entity()
     for row in db_util.fetchall(host_info, show_global_variables_sql):
         setattr(info, row.get("Variable_name").lower(), row.get("Value"))
     return info
示例#5
0
def get_mysql_variables(host_info):
    host_info.mysql_variables = entity.Entity()
    for row in db_util.fetchall(host_info, main.show_global_variables_sql):
        setattr(host_info.mysql_variables,
                row.get("Variable_name").lower(), row.get("Value"))