import { VmInstance, VmTemplate } from "../api"; import BytesSize from "./bytes"; export default function VpsResources({ vm }: { vm: VmInstance | VmTemplate }) { const diskType = "template_id" in vm ? vm.template?.disk_type : vm.disk_type; const region = "region_id" in vm ? vm.region?.name : vm.template?.region?.name; const status = "status" in vm ? vm.status : undefined; return ( <>
{vm.cpu} vCPU, RAM,{" "} {diskType?.toUpperCase()},{" "} {region && <>Location: {region}}
{status && status.state === "running" && (
{" "} {(100 * status.cpu_usage).toFixed(1)}% CPU,{" "} {(100 * status.mem_usage).toFixed(0)}% RAM
)} {status && status.state === "stopped" && (
{" "} Stopped
)} ); }