Monitor.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div>
  3. <a-tabs @change="handleTabChange">
  4. <a-tab-pane v-for="type in types" :key="type" :tab="$t(`compute.monitor.${type}`)">
  5. <base-monitor v-if="type === 'basic'" :data="server" :constants="monitorConstants" idKey="vm_id" monitorType="basic" :currentMonitorType="currentMonitorType" />
  6. <div v-else>
  7. <install-agent-form-visible
  8. :data="server"
  9. :serverColumns="serverColumns"
  10. :isPageDestroyed="isPageDestroyed" />
  11. <agent-monitor
  12. :data="server"
  13. :currentMonitorType="currentMonitorType"
  14. idKey="vm_id"
  15. monitorType="agent"
  16. key="monitor-agent" />
  17. </div>
  18. </a-tab-pane>
  19. </a-tabs>
  20. </div>
  21. </template>
  22. <script>
  23. import BaseMonitor from '@Compute/sections/monitor/BaseMonitor'
  24. import AgentMonitor from '@Compute/sections/monitor/AgentMonitor.vue'
  25. import { ONECLOUD_MONITOR, VMWARE_MONITOR, OTHER_MONITOR, SANGFOR_MONITOR } from '@Compute/views/vminstance/constants'
  26. import { HYPERVISORS_MAP } from '@/constants'
  27. import WindowsMixin from '@/mixins/windows'
  28. import InstallAgentFormVisible from '../../vminstance/components/InstallAgentFormVisible'
  29. export default {
  30. name: 'VminstanceMonitorSidepage',
  31. components: {
  32. BaseMonitor,
  33. AgentMonitor,
  34. InstallAgentFormVisible,
  35. },
  36. mixins: [WindowsMixin],
  37. props: {
  38. data: { // listItemData
  39. type: Object,
  40. required: true,
  41. },
  42. serverColumns: {
  43. type: Array,
  44. required: true,
  45. },
  46. isPageDestroyed: Boolean,
  47. needFetchResource: {
  48. type: Boolean,
  49. default: false,
  50. },
  51. agentStatus: String,
  52. },
  53. data () {
  54. return {
  55. currentMonitorType: this.data.hypervisor === 'kvm' ? 'agent' : 'basic',
  56. alertType: 'warning',
  57. time: '1h',
  58. timeGroup: '1m',
  59. monitorList: [],
  60. server: this.data,
  61. types: this.data.hypervisor === 'kvm' ? ['agent', 'basic'] : ['basic', 'agent'],
  62. }
  63. },
  64. computed: {
  65. hypervisor () {
  66. return this.server.hypervisor
  67. },
  68. monitorConstants () {
  69. if (this.hypervisor === HYPERVISORS_MAP.esxi.key) {
  70. return VMWARE_MONITOR
  71. } else if (this.hypervisor === HYPERVISORS_MAP.kvm.key) {
  72. return ONECLOUD_MONITOR
  73. } else if (this.hypervisor === HYPERVISORS_MAP.sangfor.key) {
  74. return SANGFOR_MONITOR
  75. } else {
  76. // aliyun apsara 虚拟机磁盘使用率增加groupBy: device
  77. const otherMonitor = OTHER_MONITOR.map(item => {
  78. if (['Aliyun', 'Apsara'].includes(this.server.brand) && item.fromItem === 'vm_disk') {
  79. item.groupBy = ['device']
  80. }
  81. // azure windows 虚拟机磁盘使用率增加groupBy: device
  82. if (['Azure'].includes(this.server.brand) && item.fromItem === 'vm_disk' && this.server.os_type === 'Windows') {
  83. item.groupBy = ['device']
  84. }
  85. return item
  86. })
  87. return otherMonitor.filter(item => {
  88. if (!['Aliyun', 'Qcloud'].includes(this.server.brand) && item.seleteItem === 'out_bandwidth_usage') {
  89. return false
  90. }
  91. return true
  92. })
  93. }
  94. },
  95. serverId () {
  96. return this.server.id
  97. },
  98. },
  99. watch: {
  100. 'data.id' () {
  101. this.fetchResource()
  102. },
  103. },
  104. created () {
  105. this.fetchResource()
  106. },
  107. methods: {
  108. async fetchResource () {
  109. if (this.needFetchResource) {
  110. try {
  111. const { data } = await new this.$Manager('servers', 'v1').get({ id: this.data.id, params: { details: true } })
  112. this.server = data
  113. } catch (err) {
  114. throw err
  115. }
  116. }
  117. },
  118. handleTabChange (tab) {
  119. this.currentMonitorType = tab
  120. this.$nextTick(() => {
  121. this.$bus.$emit('VmMonitorTypeChange', tab)
  122. })
  123. },
  124. },
  125. }
  126. </script>