Monitor.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div>
  3. <dashboard-cards ref="dashboardCards" useLocalPanels :extraParams="extraParams" :localPanels="localPanels" />
  4. </div>
  5. </template>
  6. <script>
  7. import WindowsMixin from '@/mixins/windows'
  8. import DashboardCards from '@Monitor/components/MonitorCard/DashboardCards'
  9. import { KVM_MONITOR_OPTS, VMWARE_MONITOR_OPTS, NIC_RSRC_MON_OPTS, RADEONTOP_OPTS, VASMI_OPTS } from '../constants'
  10. export default {
  11. name: 'HostMonitorSidepage',
  12. components: {
  13. DashboardCards,
  14. },
  15. mixins: [WindowsMixin],
  16. props: {
  17. data: { // listItemData
  18. type: Object,
  19. required: true,
  20. },
  21. needFetchResource: {
  22. type: Boolean,
  23. default: false,
  24. },
  25. },
  26. data () {
  27. return {
  28. host: this.data,
  29. singleActions: [],
  30. }
  31. },
  32. computed: {
  33. hostType () {
  34. return this.host.host_type
  35. },
  36. isolatedDeviceTypes () {
  37. return Object.keys(this.host.isolated_device_type_count || {})
  38. },
  39. monitorConstants () {
  40. let list = VMWARE_MONITOR_OPTS
  41. if ((this.hostType === 'hypervisor' || this.hostType === 'container') && !this.host.manager_id) {
  42. list = [...KVM_MONITOR_OPTS]
  43. if (this.isolatedDeviceTypes.some(type => ['NETINT_CA_QUADRA', 'NETINT_CA_ASIC'].includes(type))) {
  44. list = [...list, ...NIC_RSRC_MON_OPTS]
  45. }
  46. if (this.isolatedDeviceTypes.some(type => ['CPH_AMD_GPU'].includes(type))) {
  47. list = [...list, ...RADEONTOP_OPTS]
  48. }
  49. if (this.isolatedDeviceTypes.some(type => ['VASTAITECH_GPU'].includes(type))) {
  50. list = [...list, ...VASMI_OPTS]
  51. }
  52. }
  53. return list
  54. },
  55. hostId () {
  56. return this.host.id
  57. },
  58. localPanels () {
  59. return this.monitorConstants.map(item => {
  60. return {
  61. panel_name: `${item.label}${item.metric ? `(${item.metric})` : `(${item.fromItem}.${item.seleteItem})`}`,
  62. constants: item,
  63. queryData: this.genQueryData(item),
  64. }
  65. })
  66. },
  67. },
  68. created () {
  69. this.$bus.$on('VmMonitorTypeChange', (tab) => {
  70. this.$refs.dashboardCards.initMonitorConfig()
  71. })
  72. },
  73. methods: {
  74. genQueryData (val) {
  75. const opt = val
  76. if (!val.extraTags) {
  77. val.extraTags = []
  78. }
  79. let select = []
  80. if (val.as) {
  81. const asItems = val.as.split(',')
  82. select = val.seleteItem.split(',').map((val, i) => {
  83. return [
  84. {
  85. type: 'field',
  86. params: [val],
  87. },
  88. { // 对应 mean(val.seleteItem)
  89. type: opt.groupFunc || opt.selectFunction || 'mean',
  90. params: [],
  91. },
  92. { // 确保后端返回columns有 val.label 的别名
  93. type: 'alias',
  94. params: [asItems[i]],
  95. },
  96. ]
  97. })
  98. } else {
  99. select = val.seleteItem.split(',').map((val, i) => {
  100. return [
  101. {
  102. type: 'field',
  103. params: [val],
  104. },
  105. { // 对应 mean(val.seleteItem)
  106. type: opt.groupFunc || opt.selectFunction || 'mean',
  107. params: [],
  108. },
  109. { // 确保后端返回columns有 val.label 的别名
  110. type: 'alias',
  111. params: [val],
  112. },
  113. ]
  114. })
  115. }
  116. const model = {
  117. measurement: val.fromItem,
  118. select,
  119. group_by: [
  120. // { type: 'tag', params: ['host_id'] },
  121. ],
  122. tags: [
  123. {
  124. key: 'host_id',
  125. value: this.hostId,
  126. operator: '=',
  127. },
  128. ...val.extraTags,
  129. ],
  130. }
  131. if (val.groupBy && val.groupBy.length > 0) {
  132. val.groupBy.forEach(group => {
  133. model.group_by.push({
  134. type: 'tag',
  135. params: [group],
  136. })
  137. })
  138. }
  139. const data = {
  140. metric_query: [
  141. {
  142. model,
  143. },
  144. ],
  145. scope: this.$store.getters.scope,
  146. unit: true,
  147. skip_check_series: true,
  148. }
  149. return data
  150. },
  151. },
  152. }
  153. </script>