4 <p class="title is-4">{{ item.name }}</p>
5 <p class="subtitle is-6">
6 <template v-if="item.subtitle">
9 <template v-else-if="vms">
11 <strong>Loading...</strong>
13 <div v-else-if="error">
14 <strong class="danger">Error loading info</strong>
16 <div v-else class="metrics" :class="{'is-size-7-mobile': item.small_font_on_small_screens, 'is-small': item.small_font_on_desktop}">
17 <span v-if="isValueShown('vms')" class="margined">VMs: <span class="is-number"><span class="has-text-weight-bold">{{ vms.running }}</span><span v-if="isValueShown('vms_total')">/{{vms.total}}</span></span></span>
18 <span v-if="isValueShown('lxcs')" class="margined">LXCs: <span class="is-number"><span class="has-text-weight-bold">{{ lxcs.running }}</span><span v-if="isValueShown('lxcs_total')">/{{lxcs.total}}</span></span></span>
19 <span v-if="isValueShown('disk')" class="margined">Disk: <span class="has-text-weight-bold is-number" :class="statusClass(diskUsed)">{{ diskUsed }}%</span></span>
20 <span v-if="isValueShown('mem')" class="margined">Mem: <span class="has-text-weight-bold is-number" :class="statusClass(memoryUsed)">{{ memoryUsed }}%</span></span>
21 <span v-if="isValueShown('cpu')" class="margined">CPU: <span class="has-text-weight-bold is-number" :class="statusClass(cpuUsed)">{{ cpuUsed }}%</span></span>
27 <i v-if="loading" class="fa fa-circle-notch fa-spin fa-2xl"></i>
28 <i v-if="error" class="fa fa-exclamation-circle fa-2xl danger"></i>
34 import service from "@/mixins/service.js";
35 import Generic from "./Generic.vue";
63 if (this.item.hide) this.hide = this.item.hide;
68 if (value > this.item.danger_value) return 'danger';
69 if (value > this.item.warning_value) return 'warning';
72 fetchStatus: async function () {
76 "Authorization": this.item.api_token
79 const status = await this.fetch(`/api2/json/nodes/${this.item.node}/status`, options);
81 const decimalsToShow = this.item.hide_decimals ? 0 : 1;
82 this.memoryUsed = ( (status.data.memory.used * 100) / status.data.memory.total ).toFixed(decimalsToShow);
83 this.diskUsed = ( (status.data.rootfs.used * 100) / status.data.rootfs.total ).toFixed(decimalsToShow);
84 this.cpuUsed = (status.data.cpu * 100).toFixed(decimalsToShow);
86 if (this.isValueShown('vms')) {
87 const vms = await this.fetch(`/api2/json/nodes/${this.item.node}/qemu`, options);
88 this.parseVMsAndLXCs(vms, this.vms);
91 if (this.isValueShown('lxcs')) {
92 const lxcs = await this.fetch(`/api2/json/nodes/${this.item.node}/lxc`, options);
93 this.parseVMsAndLXCs(lxcs, this.lxcs);
100 this.loading = false;
102 parseVMsAndLXCs(items, value) {
103 value.total += items.data.length;
104 value.running += items.data.filter( i => i.status === 'running' ).length;
105 // if no vms, hide this value:
106 if (value.total == 0) this.hide.push('lxcs');
108 isValueShown(value) {
109 return this.hide.indexOf(value) == -1;
115 <style scoped lang="scss">
128 .metrics .margined:not(:first-child) {