ApplicationCDCMonitor.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2021/10/20 3:39 下午
  4. # @Site :
  5. # @File : ApplicationCDCMonitor.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. # @Tel 1501435553
  9. import logging
  10. from Apietl.constant.ConfConstant import ConfConstant
  11. import requests
  12. import os
  13. class ApplicationCDCMonitor:
  14. def __init__(self):
  15. self.cdc_url = ConfConstant.CDC_URL
  16. self.pd_url = ConfConstant.TIDB_HOST
  17. self.cdc_port = 8300
  18. self.pd_port = 2379
  19. self.cdc_job = 'application'
  20. self.cdc_status_url = '/api/v1/status'
  21. self.cdc_health_url = 'GET /api/v1/health'
  22. self.cdc_changefeeds_url = '/api/v1/changefeeds'
  23. def Headler(self):
  24. headers = {'Content-Type': 'application/json'}
  25. repo = requests.get(url='http://{}:{}{}?'.format(self.cdc_url, self.cdc_port, self.cdc_changefeeds_url),
  26. headers=headers)
  27. message = repo.json()
  28. print(message)
  29. for json in message:
  30. task_id = json['id']
  31. tso = json['checkpoint_tso']
  32. error = json['error']
  33. if error is not None:
  34. requests.delete(url='http://{}:{}{}/{}'.format(self.cdc_url, self.cdc_port,
  35. self.cdc_changefeeds_url, task_id))
  36. os.system(
  37. 'cd /data/tidb-deploy/cdc-8300/bin; ./cdc cli changefeed create --pd=http://192.168.0.184:2379 '
  38. '--sink-uri="mysql://data:hcst@2021@139.186.27.96:3390" --config ../conf/{task_id}.toml '
  39. '--changefeed-id={task_id} --start-ts {tso}'.format(tso=tso, task_id=task_id))
  40. backResult = requests.get(
  41. url='http://{}:{}{}/{}'.format(self.cdc_url, self.cdc_port, self.cdc_changefeeds_url, task_id),
  42. headers=headers)
  43. print(backResult, '--------1111-------')
  44. # if backResult is None:
  45. # os.system(
  46. # 'cd /data/tidb-deploy/cdc-8300/bin; ./cdc cli changefeed create --pd=http://192.168.0.184:2379 '
  47. # '--sink-uri="mysql://data:hcst@2021@139.186.27.96:3390" --config ../conf/{task_id}.toml '
  48. # '--changefeed-id={task_id} '.format(task_id=task_id))
  49. # else:
  50. # result = backResult.json()
  51. # print(result)
  52. # if result['error'] is not None:
  53. # requests.delete(url='http://{}:{}{}/{}'.format(self.cdc_url, self.cdc_port,
  54. # self.cdc_changefeeds_url, task_id))
  55. # os.system(
  56. # 'cd /data/tidb-deploy/cdc-8300/bin; ./cdc cli changefeed create '
  57. # '--pd=http://192.168.0.184:2379 '
  58. # '--sink-uri="mysql://data:hcst@2021@139.186.27.96:3390" --config ../conf/{task_id}.toml '
  59. # '--changefeed-id={task_id} '.format(task_id=task_id))
  60. # else:
  61. # logging.info('新创建没有问题')
  62. else:
  63. logging.info("无异常")
  64. if __name__ == '__main__':
  65. ApplicationCDCMonitor().Headler()