AudienceReportMonitor.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2021/11/30 6:11 下午
  4. # @Site :
  5. # @File : AudienceReportMonitor.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. # @Tel 1501435553
  9. import datetime
  10. import logging
  11. from Apietl.conn.TidbProConn import TidbProConn
  12. from OuterDataCompareInnerData.Utils.SendEmail import SendEmail
  13. class AudienceReportMonitor:
  14. def __init__(self):
  15. self.conn = TidbProConn.get_connection()
  16. self.Audience_list = ['ctop_kuaishou_audience_report_daily_age_material',
  17. 'ctop_kuaishou_audience_report_daily_city_material',
  18. 'ctop_kuaishou_audience_report_daily_client_material',
  19. 'ctop_kuaishou_audience_report_daily_gender_material',
  20. 'ctop_kuaishou_audience_report_daily_province_material']
  21. self.stat_date = (datetime.date.today() + datetime.timedelta(-1)).strftime("%Y-%m-%d")
  22. def monitor(self):
  23. try:
  24. messageList = ''
  25. for table in self.Audience_list:
  26. try:
  27. sql = """select count(1) from `jeecg-boot`.{table} where stat_date='{stat_date}'""".format(
  28. table=table, stat_date=self.stat_date)
  29. print(sql)
  30. rowCount = TidbProConn.quary(self.conn, sql)[0][0]
  31. if rowCount == 0:
  32. message = """{stat_date}日:{table} 数据量为零 请检查
  33. """.format(stat_date=self.stat_date,
  34. table=table)
  35. messageList += message
  36. else:
  37. logging.info("""{stat_date}日:{table} 数据正常""".format(stat_date=self.stat_date, table=table))
  38. except Exception as e:
  39. logging.error(e)
  40. if messageList == '':
  41. logging.info("数据正常")
  42. else:
  43. SendEmail.mail(messageList)
  44. except Exception as e:
  45. logging.error(e)
  46. if __name__ == '__main__':
  47. AudienceReportMonitor().monitor()