Monitor.vue 3.1 KB

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