adjust-dashboard-for-channel.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/usr/bin/env python3
  2. #
  3. # Adjusts the testnet monitor dashboard for the specified release channel
  4. #
  5. import sys
  6. import json
  7. if len(sys.argv) != 3:
  8. print('Error: Dashboard or Channel not specified')
  9. sys.exit(1)
  10. dashboard_json = sys.argv[1]
  11. channel = sys.argv[2]
  12. if channel not in ['edge', 'beta', 'stable', 'local']:
  13. print('Error: Unknown channel:', channel)
  14. sys.exit(2)
  15. with open(dashboard_json, 'r') as read_file:
  16. data = json.load(read_file)
  17. if channel == 'local':
  18. data['title'] = 'Local Cluster Monitor'
  19. data['uid'] = 'local'
  20. data['links'] = []
  21. data['templating']['list'] = [{'current': {'text': '$datasource',
  22. 'value': '$datasource'},
  23. 'hide': 1,
  24. 'label': 'Data Source',
  25. 'name': 'datasource',
  26. 'options': [],
  27. 'query': 'influxdb',
  28. 'refresh': 1,
  29. 'regex': '',
  30. 'type': 'datasource'},
  31. {'allValue': None,
  32. 'current': {'text': 'testnet',
  33. 'value': 'testnet'},
  34. 'hide': 1,
  35. 'includeAll': False,
  36. 'label': 'Testnet',
  37. 'multi': False,
  38. 'name': 'testnet',
  39. 'options': [{'selected': True,
  40. 'text': 'testnet',
  41. 'value': 'testnet'}],
  42. 'query': 'testnet',
  43. 'type': 'custom'},
  44. {'allValue': ".*",
  45. 'datasource': '$datasource',
  46. 'hide': 0,
  47. 'includeAll': True,
  48. 'label': 'HostID',
  49. 'multi': False,
  50. 'name': 'hostid',
  51. 'options': [],
  52. 'query': 'SELECT DISTINCT(\"id\") FROM \"$testnet\".\"autogen\".\"validator-new\" ',
  53. 'refresh': 2,
  54. 'regex': '',
  55. 'sort': 1,
  56. 'tagValuesQuery': '',
  57. 'tags': [],
  58. 'tagsQuery': '',
  59. 'type': 'query',
  60. 'useTags': False}]
  61. elif channel == 'stable':
  62. # Stable dashboard only allows the user to select between public clusters
  63. data['title'] = 'Cluster Telemetry'
  64. data['uid'] = 'monitor'
  65. data['templating']['list'] = [{'current': {'text': '$datasource',
  66. 'value': '$datasource'},
  67. 'hide': 1,
  68. 'label': 'Data Source',
  69. 'name': 'datasource',
  70. 'options': [],
  71. 'query': 'influxdb',
  72. 'refresh': 1,
  73. 'regex': '',
  74. 'type': 'datasource'},
  75. {'allValue': None,
  76. 'current': {'text': 'Mainnet Beta',
  77. 'value': 'mainnet-beta'},
  78. 'hide': 1,
  79. 'includeAll': False,
  80. 'label': 'Testnet',
  81. 'multi': False,
  82. 'name': 'testnet',
  83. 'options': [{'selected': True,
  84. 'text': 'Devnet',
  85. 'value': 'devnet'},
  86. {'selected': False,
  87. 'text': 'Mainnet Beta',
  88. 'value': 'mainnet-beta'},
  89. {'selected': False,
  90. 'text': 'Testnet',
  91. 'value': 'tds'}],
  92. 'query': 'devnet,mainnet-beta,tds',
  93. 'type': 'custom'},
  94. {'allValue': ".*",
  95. 'datasource': '$datasource',
  96. 'hide': 0,
  97. 'includeAll': True,
  98. 'label': 'HostID',
  99. 'multi': False,
  100. 'name': 'hostid',
  101. 'options': [],
  102. 'query': 'SELECT DISTINCT(\"id\") FROM \"$testnet\".\"autogen\".\"validator-new\" ',
  103. 'refresh': 2,
  104. 'regex': '',
  105. 'sort': 1,
  106. 'tagValuesQuery': '',
  107. 'tags': [],
  108. 'tagsQuery': '',
  109. 'type': 'query',
  110. 'useTags': False}]
  111. else:
  112. # Non-stable dashboard includes all the dev clusters
  113. data['title'] = 'Cluster Telemetry ({})'.format(channel)
  114. data['uid'] = 'monitor-' + channel
  115. data['templating']['list'] = [{'current': {'text': '$datasource',
  116. 'value': '$datasource'},
  117. 'hide': 1,
  118. 'label': 'Data Source',
  119. 'name': 'datasource',
  120. 'options': [],
  121. 'query': 'influxdb',
  122. 'refresh': 1,
  123. 'regex': '',
  124. 'type': 'datasource'},
  125. {'allValue': ".*",
  126. 'current': {'text': 'Developer Testnet',
  127. 'value': 'devnet'},
  128. 'datasource': '$datasource',
  129. 'hide': 1,
  130. 'includeAll': False,
  131. 'label': 'Testnet',
  132. 'multi': False,
  133. 'name': 'testnet',
  134. 'options': [],
  135. 'query': 'show databases',
  136. 'refresh': 1,
  137. 'regex': '(devnet|tds|mainnet-beta|testnet.*)',
  138. 'sort': 1,
  139. 'tagValuesQuery': '',
  140. 'tags': [],
  141. 'tagsQuery': '',
  142. 'type': 'query',
  143. 'useTags': False},
  144. {'allValue': ".*",
  145. 'datasource': '$datasource',
  146. 'hide': 0,
  147. 'includeAll': True,
  148. 'label': 'HostID',
  149. 'multi': False,
  150. 'name': 'hostid',
  151. 'options': [],
  152. 'query': 'SELECT DISTINCT(\"id\") FROM \"$testnet\".\"autogen\".\"validator-new\" ',
  153. 'refresh': 2,
  154. 'regex': '',
  155. 'sort': 1,
  156. 'tagValuesQuery': '',
  157. 'tags': [],
  158. 'tagsQuery': '',
  159. 'type': 'query',
  160. 'useTags': False}]
  161. with open(dashboard_json, 'w') as write_file:
  162. json.dump(data, write_file, indent=2)