mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-11-04 08:20:58 +00:00 
			
		
		
		
	Improve proxmox widget
This commit is contained in:
		
							parent
							
								
									d75505acc8
								
							
						
					
					
						commit
						43b5263f41
					
				@ -289,6 +289,7 @@ export function cleanServiceGroups(groups) {
 | 
				
			|||||||
          enableNowPlaying,
 | 
					          enableNowPlaying,
 | 
				
			||||||
          volume, // diskstation widget,
 | 
					          volume, // diskstation widget,
 | 
				
			||||||
          enableQueue, // sonarr/radarr
 | 
					          enableQueue, // sonarr/radarr
 | 
				
			||||||
 | 
					          node, // Proxmox
 | 
				
			||||||
        } = cleanedService.widget;
 | 
					        } = cleanedService.widget;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let fieldsList = fields;
 | 
					        let fieldsList = fields;
 | 
				
			||||||
@ -299,7 +300,7 @@ export function cleanServiceGroups(groups) {
 | 
				
			|||||||
            fieldsList = null;
 | 
					            fieldsList = null;
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        cleanedService.widget = {
 | 
					        cleanedService.widget = {
 | 
				
			||||||
          type,
 | 
					          type,
 | 
				
			||||||
          fields: fieldsList || null,
 | 
					          fields: fieldsList || null,
 | 
				
			||||||
@ -319,6 +320,9 @@ export function cleanServiceGroups(groups) {
 | 
				
			|||||||
        if (type === "unifi") {
 | 
					        if (type === "unifi") {
 | 
				
			||||||
          if (site) cleanedService.widget.site = site;
 | 
					          if (site) cleanedService.widget.site = site;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        if (type === "proxmox") {
 | 
				
			||||||
 | 
					          if (node) cleanedService.widget.node = node;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        if (type === "kubernetes") {
 | 
					        if (type === "kubernetes") {
 | 
				
			||||||
          if (namespace) cleanedService.widget.namespace = namespace;
 | 
					          if (namespace) cleanedService.widget.namespace = namespace;
 | 
				
			||||||
          if (app) cleanedService.widget.app = app;
 | 
					          if (app) cleanedService.widget.app = app;
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,7 @@ import Container from "components/services/widget/container";
 | 
				
			|||||||
import Block from "components/services/widget/block";
 | 
					import Block from "components/services/widget/block";
 | 
				
			||||||
import useWidgetAPI from "utils/proxy/use-widget-api";
 | 
					import useWidgetAPI from "utils/proxy/use-widget-api";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function calcRunning(total, current) {
 | 
					function calcRunning(total, current) {
 | 
				
			||||||
  return current.status === "running" ? total + 1 : total;
 | 
					  return current.status === "running" ? total + 1 : total;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -25,29 +26,40 @@ export default function Component({ service }) {
 | 
				
			|||||||
        <Block label="proxmox.vms" />
 | 
					        <Block label="proxmox.vms" />
 | 
				
			||||||
        <Block label="proxmox.lxc" />
 | 
					        <Block label="proxmox.lxc" />
 | 
				
			||||||
        <Block label="resources.cpu" />
 | 
					        <Block label="resources.cpu" />
 | 
				
			||||||
        <Block label="resources.ram" />
 | 
					        <Block label="resources.mem" />
 | 
				
			||||||
      </Container>
 | 
					      </Container>
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const { data } = clusterData ;
 | 
					  const { data } = clusterData ;
 | 
				
			||||||
  const vms = data.filter(item => item.type === "qemu" && item.template === 0) || [];
 | 
					  const vms = data.filter(item => item.type === "qemu" && item.template === 0 && (widget.node === undefined || widget.node === item.node)) || [];
 | 
				
			||||||
  const lxc = data.filter(item => item.type === "lxc" && item.template === 0) || [];
 | 
					  const lxc = data.filter(item => item.type === "lxc" && item.template === 0 && (widget.node === undefined || widget.node === item.node)) || [];
 | 
				
			||||||
  const nodes = data.filter(item => item.type === "node") || [];
 | 
					  const nodes = data.filter(item => item.type === "node" && (widget.node === undefined || widget.node === item.node)) || [];
 | 
				
			||||||
 | 
					 | 
				
			||||||
  const runningVMs = vms.reduce(calcRunning, 0);
 | 
					  const runningVMs = vms.reduce(calcRunning, 0);
 | 
				
			||||||
  const runningLXC = lxc.reduce(calcRunning, 0);
 | 
					  const runningLXC = lxc.reduce(calcRunning, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // TODO: support more than one node
 | 
					  if (nodes.length === 0) {
 | 
				
			||||||
  // TODO: better handling of cluster with zero nodes
 | 
					    return (
 | 
				
			||||||
  const node = nodes.length > 0 ? nodes[0] : { cpu: 0.0, mem: 0, maxmem: 0 };
 | 
					      <Container service={service}>
 | 
				
			||||||
 | 
					        <Block label="proxmox.vms" value={`${runningVMs} / ${vms.length}`} />
 | 
				
			||||||
 | 
					        <Block label="proxmox.lxc" value={`${runningLXC} / ${lxc.length}`} />
 | 
				
			||||||
 | 
					        <Block label="resources.cpu" />
 | 
				
			||||||
 | 
					        <Block label="resources.mem" />
 | 
				
			||||||
 | 
					      </Container>
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const maxMemory = nodes.reduce((sum, n) => n.maxmem + sum, 0);
 | 
				
			||||||
 | 
					  const usedMemory = nodes.reduce((sum, n) => n.mem + sum, 0);
 | 
				
			||||||
 | 
					  const maxCpu = nodes.reduce((sum, n) => n.maxcpu + sum, 0);
 | 
				
			||||||
 | 
					  const usedCpu = nodes.reduce((sum, n) => (n.cpu * n.maxcpu) + sum, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <Container service={service}>
 | 
					    <Container service={service}>
 | 
				
			||||||
      <Block label="proxmox.vms" value={`${runningVMs} / ${vms.length}`} />
 | 
					      <Block label="proxmox.vms" value={`${runningVMs} / ${vms.length}`} />
 | 
				
			||||||
      <Block label="proxmox.lxc" value={`${runningLXC} / ${lxc.length}`} />
 | 
					      <Block label="proxmox.lxc" value={`${runningLXC} / ${lxc.length}`} />
 | 
				
			||||||
      <Block label="resources.cpu" value={t("common.percent", { value: (node.cpu * 100) })} />
 | 
					      <Block label="resources.cpu" value={t("common.percent", { value: ((usedCpu / maxCpu) * 100) })} />
 | 
				
			||||||
      <Block label="resources.mem" value={t("common.percent", { value: ((node.mem / node.maxmem) * 100) })} />
 | 
					      <Block label="resources.mem" value={t("common.percent", { value: ((usedMemory / maxMemory) * 100) })} />
 | 
				
			||||||
    </Container>
 | 
					    </Container>
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user