BaseMonitor.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div>
  3. <dashboard-cards ref="dashboardCards" useLocalPanels :extraParams="extraParams" :localPanels="localPanels" />
  4. </div>
  5. </template>
  6. <script>
  7. import _ from 'lodash'
  8. import { MonitorHelper } from '@/utils/monitor'
  9. import WindowsMixin from '@/mixins/windows'
  10. import DashboardCards from '@Monitor/components/MonitorCard/DashboardCards'
  11. export default {
  12. name: 'BaseMonitor',
  13. components: {
  14. DashboardCards,
  15. },
  16. mixins: [WindowsMixin],
  17. props: {
  18. data: { // listItemData
  19. type: Object,
  20. required: true,
  21. },
  22. constants: {
  23. // import { ONECLOUD_MONITOR, VMWARE_MONITOR, AGENT_MONITOR } from '@Compute/views/vminstance/constants'
  24. type: Object,
  25. required: true,
  26. },
  27. resId: {
  28. type: String,
  29. },
  30. idKey: {
  31. type: String, // vm_id, host_id
  32. },
  33. extraTags: {
  34. type: Array,
  35. },
  36. },
  37. data () {
  38. return {
  39. singleActions: [
  40. {
  41. label: this.$t('compute.text_382'),
  42. action: async obj => {
  43. const alertManager = new this.$Manager('nodealerts', 'v1')
  44. const { metric } = obj.constants
  45. const { data: { data = [] } } = await alertManager.list({
  46. params: {
  47. type: 'guest',
  48. node_id: this.serverId,
  49. metric,
  50. },
  51. })
  52. if (data && data.length) {
  53. if (data.length === 1) {
  54. this.createDialog('UpdateNodeAlert', {
  55. data,
  56. alertType: 'guest',
  57. alertManager,
  58. })
  59. } else {
  60. throw Error(this.$t('compute.text_383'))
  61. }
  62. } else { // 新建报警
  63. this.createDialog('CreateNodeAlert', {
  64. alertType: 'guest',
  65. nodeId: this.serverId,
  66. metric,
  67. alertManager,
  68. })
  69. }
  70. },
  71. meta: (obj) => {
  72. const ret = {
  73. validate: true,
  74. tooltip: '',
  75. }
  76. if (_.get(obj, 'constants.fromItem', '').startsWith('agent_')) {
  77. ret.validate = false
  78. ret.tooltip = this.$t('compute.text_1287', [''])
  79. }
  80. return ret
  81. },
  82. },
  83. ],
  84. helper: new MonitorHelper(this.$Manager, this.$store.getters.scope),
  85. }
  86. },
  87. computed: {
  88. serverId () {
  89. return this.resId || this.data.id
  90. },
  91. localPanels () {
  92. return this.constants.map(item => {
  93. return {
  94. panel_name: `${item.label}${item.metric ? `(${item.metric})` : ''}`,
  95. constants: item,
  96. queryData: this.helper.genServerQueryData(this.serverId, item, '', '', this.idKey, '', true, this.extraTags),
  97. }
  98. })
  99. },
  100. },
  101. created () {
  102. this.$bus.$on('VmMonitorTypeChange', (tab) => {
  103. this.$refs.dashboardCards.initMonitorConfig()
  104. })
  105. },
  106. methods: {
  107. },
  108. }
  109. </script>