Monitor.vue 3.0 KB

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