Monitor.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div>
  3. <div v-if="hadMonitor">
  4. <dashboard-cards ref="dashboardCards" useLocalPanels :extraParams="extraParams" :localPanels="localPanels" />
  5. </div>
  6. <template v-else>
  7. <a-alert
  8. :message="$t('db.text_183')"
  9. class="mb-2"
  10. type="warning" />
  11. </template>
  12. </div>
  13. </template>
  14. <script>
  15. import _ from 'lodash'
  16. import * as R from 'ramda'
  17. import { RDS_MONITOR_ALL_OPTS } from '@DB/constants'
  18. import DashboardCards from '@Monitor/components/MonitorCard/DashboardCards'
  19. import WindowsMixin from '@/mixins/windows'
  20. import { HYPERVISORS_MAP } from '@/constants'
  21. export default {
  22. name: 'RDSnitorSidepage',
  23. components: {
  24. DashboardCards,
  25. },
  26. mixins: [WindowsMixin],
  27. props: {
  28. data: { // listItemData
  29. type: Object,
  30. required: true,
  31. },
  32. },
  33. data () {
  34. return {
  35. }
  36. },
  37. computed: {
  38. brand () {
  39. if (this.data.brand) {
  40. return this.data.brand.toLowerCase()
  41. }
  42. return ''
  43. },
  44. engine () {
  45. if (this.data.engine) {
  46. return this.data.engine.toLowerCase()
  47. }
  48. return ''
  49. },
  50. hadMonitor () {
  51. const brand = this.data.brand.toLowerCase()
  52. const surportBrand = [HYPERVISORS_MAP.aliyun.key, HYPERVISORS_MAP.apsara.key, HYPERVISORS_MAP.huawei.key, HYPERVISORS_MAP.hcso.key, HYPERVISORS_MAP.hcs.key, HYPERVISORS_MAP.qcloud.key, HYPERVISORS_MAP.jdcloud.key, HYPERVISORS_MAP.azure.key, HYPERVISORS_MAP.aws.key, HYPERVISORS_MAP.remotefile.key, HYPERVISORS_MAP.h3c.key]
  53. return surportBrand.includes(brand)
  54. },
  55. monitorConstants () {
  56. const brand = this.brand
  57. return RDS_MONITOR_ALL_OPTS.filter(item => {
  58. return item.supportBrands.includes(brand)
  59. })
  60. },
  61. dbId () {
  62. return this.data.id
  63. },
  64. localPanels () {
  65. return this.monitorConstants.map(item => {
  66. return {
  67. panel_name: `${item.label}${item.metric ? `(${item.metric})` : `(${item.fromItem}.${item.seleteItem})`}`,
  68. constants: item,
  69. queryData: this.genQueryData(item),
  70. }
  71. })
  72. },
  73. },
  74. created () {
  75. this.fetchData()
  76. this.fetchDataDebounce = _.debounce(this.fetchData, 500)
  77. this.baywatch(['time', 'timeGroup', 'data.id', 'customTime', 'groupFunc'], this.fetchDataDebounce)
  78. },
  79. methods: {
  80. genQueryData (val) {
  81. const opt = val
  82. let select = []
  83. if (val.as) {
  84. const asItems = val.as.split(',')
  85. select = val.seleteItem.split(',').map((val, i) => {
  86. return [
  87. {
  88. type: 'field',
  89. params: [val],
  90. },
  91. { // 对应 mean(val.seleteItem)
  92. type: opt.groupFunc || val.selectType || 'mean',
  93. params: [],
  94. },
  95. { // 确保后端返回columns有 val.label 的别名
  96. type: 'alias',
  97. params: [asItems[i]],
  98. },
  99. ]
  100. })
  101. } else {
  102. select = val.seleteItem.split(',').map((val, i) => {
  103. return [
  104. {
  105. type: 'field',
  106. params: [val],
  107. },
  108. { // 对应 mean(val.seleteItem)
  109. type: opt.groupFunc || 'mean',
  110. params: [],
  111. },
  112. { // 确保后端返回columns有 val.label 的别名
  113. type: 'alias',
  114. params: [val],
  115. },
  116. ]
  117. })
  118. }
  119. const tags = [
  120. {
  121. key: 'rds_id',
  122. value: this.dbId,
  123. operator: '=',
  124. },
  125. ]
  126. if (R.is(Object, val.tags)) {
  127. R.forEachObjIndexed((value, key) => {
  128. tags.push({
  129. condition: 'AND',
  130. key,
  131. value,
  132. operator: '=',
  133. })
  134. }, val.tags)
  135. }
  136. const model = {
  137. measurement: val.fromItem,
  138. select,
  139. tags,
  140. }
  141. // azure sqlserver 增加groupby
  142. if (this.data.brand === 'Azure' && (this.data.engine || '').indexOf('SQLServer') !== -1) {
  143. model.groupBy = [{ type: 'tag', params: ['database'] }]
  144. }
  145. const data = {
  146. metric_query: [
  147. {
  148. model,
  149. },
  150. ],
  151. scope: this.$store.getters.scope,
  152. unit: true,
  153. }
  154. return data
  155. },
  156. },
  157. }
  158. </script>