]> git.immae.eu Git - github/bastienwirtz/homer.git/commitdiff
Proxmox improvements
authorBastien Wirtz <bastien.wirtz@gmail.com>
Sat, 5 Nov 2022 14:21:18 +0000 (15:21 +0100)
committerBastien Wirtz <bastien.wirtz@gmail.com>
Sat, 5 Nov 2022 14:21:18 +0000 (15:21 +0100)
docs/customservices.md
src/components/services/Proxmox.vue

index 65f3d4ca3559a34b4e9fe2326e1f9d2b9cad9a5f..2e74443bc0fb46f35e1bd50af811433d22f68df5 100644 (file)
@@ -298,6 +298,11 @@ Configuration example:
   warning_value: 50
   danger_value: 80
   api_token: "PVEAPIToken=root@pam!your-api-token-name=your-api-token-key"
+  # values below this line are optional (default value are false/empty):
+  hide_decimals: true # removes decimals from stats values.
+  hide: ["vms", "vms_total", "lxcs", "lxcs_total", "disk", "mem", "cpu"] # hides values included in the array
+  small_font_on_small_screens: true # uses small font on small screens (like mobile)
+  small_font_on_desktop: true # uses small font on desktops (just in case you're showing much info)
 ```
 
 ## qBittorrent
index 1d2c2c93ef61515cde6bb7acc80c993fa9043739..2b533db673e1b0ed5d2527a2d3cad9814f40e0c1 100644 (file)
             <div v-else-if="error">
               <strong class="danger">Error loading info</strong>
             </div>
-            <div v-else class="metrics">
-              <span>VMs: <span class="is-number"><strong>{{ vms.running }}</strong>/{{vms.total}}</span></span>
-              <span>Disk: <strong class="is-number" :class="statusClass(diskUsed)">{{ diskUsed }}%</strong></span>
-              <span>Mem: <strong class="is-number" :class="statusClass(memoryUsed)">{{ memoryUsed }}%</strong></span>
-              <span>CPU: <strong class="is-number" :class="statusClass(cpuUsed)">{{ cpuUsed }}%</strong></span>
+            <div v-else class="metrics" :class="{'is-size-7-mobile': item.small_font_on_small_screens, 'is-small': item.small_font_on_desktop}">
+              <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>
+              <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>
+              <span v-if="isValueShown('disk')" class="margined">Disk: <span class="has-text-weight-bold is-number" :class="statusClass(diskUsed)">{{ diskUsed }}%</span></span>
+              <span v-if="isValueShown('mem')" class="margined">Mem: <span class="has-text-weight-bold is-number" :class="statusClass(memoryUsed)">{{ memoryUsed }}%</span></span>
+              <span v-if="isValueShown('cpu')" class="margined">CPU: <span class="has-text-weight-bold is-number" :class="statusClass(cpuUsed)">{{ cpuUsed }}%</span></span>
             </div>
           </template>
         </p>
         total: 0,
         running: 0
       },
+      lxcs: {
+        total: 0,
+        running: 0
+      },
       memoryUsed: 0,
       diskUsed: 0,
       cpuUsed: 0,
+      hide: [],
       error: false,
       loading: true
     }),
     created() {
+      if (this.item.hide) this.hide = this.item.hide;
       this.fetchStatus();
     },
     methods: {
           }
           const status = await this.fetch(`/api2/json/nodes/${this.item.node}/status`, options);
           // main metrics:
-          this.memoryUsed = ( (status.data.memory.used * 100) / status.data.memory.total ).toFixed(1);
-          this.diskUsed = ( (status.data.rootfs.used * 100) / status.data.rootfs.total ).toFixed(1);
-          this.cpuUsed = (status.data.cpu * 100).toFixed(1);
+          const decimalsToShow = this.item.hide_decimals ? 0 : 1;
+          this.memoryUsed = ( (status.data.memory.used * 100) / status.data.memory.total ).toFixed(decimalsToShow);
+          this.diskUsed = ( (status.data.rootfs.used * 100) / status.data.rootfs.total ).toFixed(decimalsToShow);
+          this.cpuUsed = (status.data.cpu * 100).toFixed(decimalsToShow);
           // vms:
-          const vms = await this.fetch(`/api2/json/nodes/${this.item.node}/qemu`, options);
-          this.vms.total += vms.data.length;
-          this.vms.running += vms.data.filter( i => i.status === 'running' ).length;
+          if (this.isValueShown('vms')) {
+            const vms = await this.fetch(`/api2/json/nodes/${this.item.node}/qemu`, options);
+            this.parseVMsAndLXCs(vms, this.vms);
+          }
+          // lxc containers:
+          if (this.isValueShown('lxcs')) {
+            const lxcs = await this.fetch(`/api2/json/nodes/${this.item.node}/lxc`, options);
+            this.parseVMsAndLXCs(lxcs, this.lxcs);
+          }
           this.error = false;
         } catch(err) {
           console.log(err);
         }
         this.loading = false;
       },
+      parseVMsAndLXCs(items, value) {
+        value.total += items.data.length;
+        value.running += items.data.filter( i => i.status === 'running' ).length;
+        // if no vms, hide this value:
+        if (value.total == 0) this.hide.push('lxcs');
+      },
+      isValueShown(value) {
+        return this.hide.indexOf(value) == -1;
+      }
     },
   };
   </script>
   .danger {
     color: red
   }
-  .metrics {
-    display: flex;
-    justify-content: space-between;
+  .metrics .margined:not(:first-child) {
+    margin-left: 0.3rem;
+  }
+  .is-small {
+    font-size: small;
   }
   </style>
   
\ No newline at end of file