{
  "$schema": "./.schemas/page.schema.json",
  "title": "Guests",
  "icon": "square.stack.3d.up",
  "sidebar": false,
  "sources": {
    "pve": {
      "auth": {
        "name": "Authorization",
        "type": "header"
      },
      "derive": [
        {
          "name": "host_status",
          "value": {
            "first": "status",
            "of": "resources.data",
            "where": {
              "equals": "node",
              "path": "type"
            }
          }
        },
        {
          "name": "up_days",
          "value": {
            "divide": [
              "node.data.uptime",
              86400
            ],
            "round": 0
          }
        },
        {
          "name": "cpu_pct",
          "value": {
            "path": "node.data.cpu",
            "round": 0,
            "scale": 100
          }
        },
        {
          "name": "mem_pct",
          "value": {
            "divide": [
              "node.data.memory.used",
              "node.data.memory.total"
            ],
            "round": 0,
            "scale": 100
          }
        },
        {
          "name": "mem_used_gb",
          "value": {
            "path": "node.data.memory.used",
            "round": 1,
            "scale": 1e-09
          }
        },
        {
          "name": "mem_total_gb",
          "value": {
            "path": "node.data.memory.total",
            "round": 0,
            "scale": 1e-09
          }
        },
        {
          "name": "guests",
          "value": {
            "each": "resources.data",
            "fields": {
              "cpu_pct": {
                "path": "cpu",
                "round": 1,
                "scale": 100
              },
              "max_gb": {
                "path": "maxmem",
                "round": 0,
                "scale": 1e-09
              },
              "mem_gb": {
                "path": "mem",
                "round": 1,
                "scale": 1e-09
              },
              "name": "name",
              "status": "status",
              "tags": "tags",
              "up_days": {
                "divide": [
                  "uptime",
                  86400
                ],
                "round": 0
              },
              "vmid": "vmid"
            },
            "sort": "vmid",
            "where": {
              "equals": "qemu",
              "path": "type"
            }
          }
        },
        {
          "name": "running",
          "value": {
            "count": "guests",
            "where": {
              "equals": "running",
              "path": "status"
            }
          }
        },
        {
          "name": "guest_count",
          "value": {
            "count": "guests"
          }
        },
        {
          "name": "guest_rows",
          "value": {
            "each": "guests",
            "fields": {
              "cpu": {
                "else": {
                  "template": "—"
                },
                "if": {
                  "equals": "running",
                  "path": "status"
                },
                "then": {
                  "template": "{cpu_pct}%"
                }
              },
              "memory": {
                "else": {
                  "template": "{max_gb} GB given"
                },
                "if": {
                  "equals": "running",
                  "path": "status"
                },
                "then": {
                  "template": "{mem_gb} of {max_gb} GB"
                }
              },
              "name": "name",
              "state": {
                "else": {
                  "template": "Stopped"
                },
                "if": {
                  "equals": "running",
                  "path": "status"
                },
                "then": {
                  "template": "Running"
                }
              },
              "up": {
                "else": {
                  "template": "—"
                },
                "if": {
                  "equals": "running",
                  "path": "status"
                },
                "then": {
                  "else": {
                    "template": "{up_days} days"
                  },
                  "if": {
                    "equals": 0,
                    "path": "up_days"
                  },
                  "then": {
                    "template": "Started today"
                  }
                }
              },
              "vmid": "vmid"
            }
          }
        }
      ],
      "every": "1m",
      "requests": {
        "node": "/api2/json/nodes/pve1/status",
        "resources": "/api2/json/cluster/resources",
        "time": "/api2/json/nodes/pve1/time",
        "version": "/api2/json/version"
      },
      "secret": "proxmox",
      "url": "https://proxmox.example.com:8006"
    },
    "pve-slow": {
      "auth": {
        "name": "Authorization",
        "type": "header"
      },
      "derive": [
        {
          "name": "unas_pct",
          "value": {
            "first": "used_fraction",
            "of": "storage.data",
            "round": 0,
            "scale": 100,
            "where": {
              "equals": "backup-nas",
              "path": "storage"
            }
          }
        },
        {
          "name": "lvm_pct",
          "value": {
            "first": "used_fraction",
            "of": "storage.data",
            "round": 0,
            "scale": 100,
            "where": {
              "equals": "local-lvm",
              "path": "storage"
            }
          }
        },
        {
          "name": "newest",
          "value": {
            "each": "backups.data",
            "fields": {
              "at": {
                "max": "ctime",
                "of": "rows"
              },
              "count": "count",
              "gb": {
                "max": "size",
                "of": "rows",
                "round": 1,
                "scale": 1e-09
              },
              "name": {
                "first": "notes",
                "of": "rows"
              },
              "vmid": "key"
            },
            "group": "vmid"
          }
        },
        {
          "name": "uncovered",
          "value": {
            "count": "notbacked.data"
          }
        }
      ],
      "every": "15m",
      "requests": {
        "backups": "/api2/json/nodes/pve1/storage/backup-nas/content?content=backup",
        "jobs": "/api2/json/cluster/backup",
        "notbacked": "/api2/json/cluster/backup-info/not-backed-up",
        "storage": "/api2/json/nodes/pve1/storage"
      },
      "secret": "proxmox",
      "url": "https://proxmox.example.com:8006"
    }
  },
  "cards": [
    {
      "id": "count",
      "label": "Running",
      "source": {
        "map": {
          "delta": {
            "template": "of {guest_count}"
          },
          "value": "running"
        },
        "ref": "pve"
      },
      "type": "stat"
    },
    {
      "id": "host-memory",
      "label": "Host memory",
      "source": {
        "map": {
          "delta": {
            "template": "of {mem_total_gb} GB"
          },
          "value": "mem_used_gb"
        },
        "ref": "pve"
      },
      "type": "stat",
      "unit": "GB"
    },
    {
      "id": "cpu",
      "items": [],
      "label": "CPU now",
      "source": {
        "map": {
          "items": {
            "each": "guests",
            "fields": {
              "label": "name",
              "value": "cpu_pct"
            },
            "sort": {
              "by": "cpu_pct",
              "order": "desc"
            },
            "where": {
              "equals": "running",
              "path": "status"
            }
          }
        },
        "ref": "pve"
      },
      "type": "bars",
      "unit": "%"
    },
    {
      "id": "memory",
      "items": [],
      "label": "Memory",
      "source": {
        "map": {
          "items": {
            "each": "guests",
            "fields": {
              "label": "name",
              "value": "mem_gb"
            },
            "sort": {
              "by": "mem_gb",
              "order": "desc"
            },
            "where": {
              "equals": "running",
              "path": "status"
            }
          }
        },
        "ref": "pve"
      },
      "type": "bars",
      "unit": "GB"
    }
  ]
}
