| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <template>
- <div>
- <dashboard-cards ref="dashboardCards" useLocalPanels :extraParams="extraParams" :localPanels="localPanels" />
- </div>
- </template>
- <script>
- import WindowsMixin from '@/mixins/windows'
- import DashboardCards from '@Monitor/components/MonitorCard/DashboardCards'
- import { KVM_MONITOR_OPTS, VMWARE_MONITOR_OPTS, NIC_RSRC_MON_OPTS, RADEONTOP_OPTS, VASMI_OPTS } from '../constants'
- export default {
- name: 'HostMonitorSidepage',
- components: {
- DashboardCards,
- },
- mixins: [WindowsMixin],
- props: {
- data: { // listItemData
- type: Object,
- required: true,
- },
- needFetchResource: {
- type: Boolean,
- default: false,
- },
- },
- data () {
- return {
- host: this.data,
- singleActions: [],
- }
- },
- computed: {
- hostType () {
- return this.host.host_type
- },
- isolatedDeviceTypes () {
- return Object.keys(this.host.isolated_device_type_count || {})
- },
- monitorConstants () {
- let list = VMWARE_MONITOR_OPTS
- if ((this.hostType === 'hypervisor' || this.hostType === 'container') && !this.host.manager_id) {
- list = [...KVM_MONITOR_OPTS]
- if (this.isolatedDeviceTypes.some(type => ['NETINT_CA_QUADRA', 'NETINT_CA_ASIC'].includes(type))) {
- list = [...list, ...NIC_RSRC_MON_OPTS]
- }
- if (this.isolatedDeviceTypes.some(type => ['CPH_AMD_GPU'].includes(type))) {
- list = [...list, ...RADEONTOP_OPTS]
- }
- if (this.isolatedDeviceTypes.some(type => ['VASTAITECH_GPU'].includes(type))) {
- list = [...list, ...VASMI_OPTS]
- }
- }
- return list
- },
- hostId () {
- return this.host.id
- },
- localPanels () {
- return this.monitorConstants.map(item => {
- return {
- panel_name: `${item.label}${item.metric ? `(${item.metric})` : `(${item.fromItem}.${item.seleteItem})`}`,
- constants: item,
- queryData: this.genQueryData(item),
- }
- })
- },
- },
- created () {
- this.$bus.$on('VmMonitorTypeChange', (tab) => {
- this.$refs.dashboardCards.initMonitorConfig()
- })
- },
- methods: {
- genQueryData (val) {
- const opt = val
- if (!val.extraTags) {
- val.extraTags = []
- }
- let select = []
- if (val.as) {
- const asItems = val.as.split(',')
- select = val.seleteItem.split(',').map((val, i) => {
- return [
- {
- type: 'field',
- params: [val],
- },
- { // 对应 mean(val.seleteItem)
- type: opt.groupFunc || opt.selectFunction || 'mean',
- params: [],
- },
- { // 确保后端返回columns有 val.label 的别名
- type: 'alias',
- params: [asItems[i]],
- },
- ]
- })
- } else {
- select = val.seleteItem.split(',').map((val, i) => {
- return [
- {
- type: 'field',
- params: [val],
- },
- { // 对应 mean(val.seleteItem)
- type: opt.groupFunc || opt.selectFunction || 'mean',
- params: [],
- },
- { // 确保后端返回columns有 val.label 的别名
- type: 'alias',
- params: [val],
- },
- ]
- })
- }
- const model = {
- measurement: val.fromItem,
- select,
- group_by: [
- // { type: 'tag', params: ['host_id'] },
- ],
- tags: [
- {
- key: 'host_id',
- value: this.hostId,
- operator: '=',
- },
- ...val.extraTags,
- ],
- }
- if (val.groupBy && val.groupBy.length > 0) {
- val.groupBy.forEach(group => {
- model.group_by.push({
- type: 'tag',
- params: [group],
- })
- })
- }
- const data = {
- metric_query: [
- {
- model,
- },
- ],
- scope: this.$store.getters.scope,
- unit: true,
- skip_check_series: true,
- }
- return data
- },
- },
- }
- </script>
|