当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
5 Star 28 Fork 739

lyonzhi / Lepus
关闭

forked from LepusGroup / lepus 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
check_mysql_bigtable.py 2.92 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env python
# coding:utf-8
import os
import sys
import string
import time
import datetime
import pymysql
import include.functions as func
from multiprocessing import Process
def check_mysql_bigtable(host, port, username, password, server_id, tags, bigtable_size):
conn = pymysql.connect(host=host, user=username, passwd=password, port=int(
port), connect_timeout=2, charset='utf8')
sql = """
SELECT table_schema as 'DB',table_name as 'TABLE',
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 ), 2), '') 'TOTAL' ,
table_comment as COMMENT
FROM information_schema.TABLES where table_schema
not in ('information_schema', 'performance_schema', 'mysql', 'sys', 'lepus')
"""
try:
with conn.cursor() as cursor:
cursor.execute(sql)
rows = cursor.fetchall()
for row in rows:
datalist = []
for r in row:
datalist.append(r)
result = datalist
if result:
table_size = float(result[2])
if table_size >= int(bigtable_size):
sql = "insert into lepus.mysql_bigtable(server_id,host,port,tags,db_name,table_name,table_size,table_comment) values(%s,%s,%s,%s,%s,%s,%s,%s);"
param = (server_id, host, port, tags,
result[0], result[1], result[2], result[3])
func.mysql_exec(sql, param)
except Exception as e:
print(e)
finally:
conn.close()
def main():
func.mysql_exec(
"insert into mysql_bigtable_history SELECT *,LEFT(REPLACE(REPLACE(REPLACE(create_time,'-',''),' ',''),':',''),8) from mysql_bigtable", '')
func.mysql_exec('delete from mysql_bigtable;', '')
# get mysql servers list
servers = func.mysql_query(
'select id,host,port,username,password,tags,bigtable_size from db_servers_mysql where is_delete=0 and monitor=1 and bigtable_monitor=1;')
if servers:
print("%s: check mysql bigtable controller started." %
(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()),))
plist = []
for row in servers:
server_id = row[0]
host = row[1]
port = row[2]
username = row[3]
password = row[4]
tags = row[5]
bigtable_size = row[6]
p = Process(target=check_mysql_bigtable, args=(
host, port, username, password, server_id, tags, bigtable_size))
plist.append(p)
for p in plist:
p.start()
time.sleep(15)
for p in plist:
p.terminate()
for p in plist:
p.join()
print("%s: check mysql bigtable controller finished." %
(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()),))
if __name__ == '__main__':
main()
Python
1
https://gitee.com/zhiyoucai/Lepus.git
git@gitee.com:zhiyoucai/Lepus.git
zhiyoucai
Lepus
Lepus
master

搜索帮助