ApplicationCDCMonitor.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. from Apietl.constant.ConfConstant import ConfConstant
  10. import requests
  11. import os
  12. class ApplicationCDCMonitor:
  13. def __init__(self):
  14. self.cdc_url = ConfConstant.CDC_URL
  15. self.pd_url = ConfConstant.TIDB_HOST
  16. self.cdc_port = 8300
  17. self.pd_port = 2379
  18. self.cdc_job = 'application'
  19. self.cdc_status_url = '/api/v1/status'
  20. self.cdc_health_url = 'GET /api/v1/health'
  21. self.cdc_changefeeds_url = '/api/v1/changefeeds'
  22. def Headler(self):
  23. headers = {'Content-Type': 'application/json'}
  24. repo = requests.get(url='http://{}:{}{}?'.format(self.cdc_url, self.cdc_port, self.cdc_changefeeds_url),
  25. headers=headers)
  26. message = repo.json()
  27. print(message)
  28. for json in message:
  29. task_id = json['id']
  30. state = json['state']
  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/application.toml '
  39. '--changefeed-id=application-task --start-ts {tso}'.format(tso=tso))
  40. if __name__ == '__main__':
  41. ApplicationCDCMonitor().Headler()