Commit df7a160f authored by 吴升宇's avatar 吴升宇

init

parents
/venv
.idea
\ No newline at end of file
psycopg2==2.8.6
pymysql
DingtalkChatbot==1.3.0
\ No newline at end of file
# coding:utf-8
import psycopg2
import pymysql
from dingtalkchatbot.chatbot import DingtalkChatbot
DATABASES = {
'slave': { # mysql
'ENGINE': 'django.db.backends.mysql',
'NAME': 'zhengxing',
'USER': 'zhengxing',
'PASSWORD': 'ZX0*n4vgtdN%t1VE',
'HOST': '172.16.30.141',
'PORT': '3306',
'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;",
"charset": "utf8mb4",
},
},
}
def main():
slave = DATABASES["slave"]
my_db = pymysql.connect(slave["HOST"], slave["USER"], slave["PASSWORD"], slave["NAME"])
pg_db = psycopg2.connect(host="172.16.50.153", user="brain_worker", password="zbVas87dtLhY", database="brain")
my_cursor = my_db.cursor()
pg_cursor = pg_db.cursor()
zhengxing_table_list = ["api_city", "api_province", "auth_user", "api_userextra", "api_userblacklist",
"api_userextratocollege",
"api_doctor", "api_person", "social_userfollow", "api_userinnerinfo", "api_hospital",
"statistic_device",
"statistic_device_user", "api_bdtransfer", "hera_bdtransfer_auto_assignor", "api_userextra",
"api_userextratocollege"]
msg = "数据同步监控\n"
for table in zhengxing_table_list:
sql = "select count(*) from %s" % table
pg_sql = "select count(*) from zhengxing.%s" % table
try:
my_cursor.execute(sql)
my_num = my_cursor.fetchone()[0]
except:
my_num = 0
try:
pg_cursor.execute(pg_sql)
pg_num = pg_cursor.fetchone()[0]
except:
pg_num = 0
print(table, my_num, pg_num)
if my_num > pg_num:
msg += "表zhengxing.%s延迟的数据量为%s条记录, mysql: %s, psql: %s".format(table, my_num - pg_num, my_num, pg_num)
webhook = 'https://oapi.dingtalk.com/robot/send?access_token={}'.format(
"1475fb9e6beff63126fef5464a378b6b77fa8655933a407d8159a2a2b1b8c869")
xiaoding = DingtalkChatbot(webhook)
# at_mobiles = ["17794411132", "15624986543"]
at_mobiles = []
xiaoding.send_text(msg=msg, at_mobiles=at_mobiles)
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment