mirror of
https://github.com/henrygd/beszel.git
synced 2026-03-23 05:56:17 +01:00
updates
This commit is contained in:
@@ -140,6 +140,9 @@ type Stats struct {
|
||||
Status string `json:"-" cbor:"6,keyasint"`
|
||||
Id string `json:"-" cbor:"7,keyasint"`
|
||||
Image string `json:"-" cbor:"8,keyasint"`
|
||||
MaxCPU uint64 `json:"-" cbor:"10,keyasint,omitzero"` // PVE: max vCPU count
|
||||
MaxMem uint64 `json:"-" cbor:"11,keyasint,omitzero"` // PVE: max memory bytes
|
||||
Uptime uint64 `json:"-" cbor:"12,keyasint,omitzero"` // PVE: uptime in seconds
|
||||
// PrevCpu [2]uint64 `json:"-"`
|
||||
CpuSystem uint64 `json:"-"`
|
||||
CpuContainer uint64 `json:"-"`
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"log/slog"
|
||||
"math/rand"
|
||||
"net"
|
||||
"strings"
|
||||
@@ -213,6 +214,7 @@ func (sys *System) createRecords(data *system.CombinedData) (*core.Record, error
|
||||
if len(data.PVEStats) > 0 {
|
||||
if data.PVEStats[0].Id != "" {
|
||||
if err := createPVEVMRecords(txApp, data.PVEStats, sys.Id); err != nil {
|
||||
slog.Error("Error creating PVE VM records", "err", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -225,6 +227,7 @@ func (sys *System) createRecords(data *system.CombinedData) (*core.Record, error
|
||||
pveStatsRecord.Set("stats", data.PVEStats)
|
||||
pveStatsRecord.Set("type", "1m")
|
||||
if err := txApp.SaveNoValidate(pveStatsRecord); err != nil {
|
||||
slog.Error("Error creating PVE stats records", "err", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -364,20 +367,20 @@ func createPVEVMRecords(app core.App, data []*container.Stats, systemId string)
|
||||
valueStrings := make([]string, 0, len(data))
|
||||
for i, vm := range data {
|
||||
suffix := fmt.Sprintf("%d", i)
|
||||
valueStrings = append(valueStrings, fmt.Sprintf("({:id%[1]s}, {:system}, {:name%[1]s}, {:type%[1]s}, {:cpu%[1]s}, {:memory%[1]s}, {:net%[1]s}, {:updated})", suffix))
|
||||
valueStrings = append(valueStrings, fmt.Sprintf("({:id%[1]s}, {:system}, {:name%[1]s}, {:type%[1]s}, {:cpu%[1]s}, {:mem%[1]s}, {:net%[1]s}, {:maxcpu%[1]s}, {:maxmem%[1]s}, {:uptime%[1]s}, {:updated})", suffix))
|
||||
params["id"+suffix] = makeStableHashId(systemId, vm.Id)
|
||||
params["name"+suffix] = vm.Name
|
||||
params["type"+suffix] = vm.Image // "qemu" or "lxc"
|
||||
params["cpu"+suffix] = vm.Cpu
|
||||
params["memory"+suffix] = vm.Mem
|
||||
params["mem"+suffix] = vm.Mem
|
||||
params["maxcpu"+suffix] = vm.MaxCPU
|
||||
params["maxmem"+suffix] = vm.MaxMem
|
||||
params["uptime"+suffix] = vm.Uptime
|
||||
netBytes := vm.Bandwidth[0] + vm.Bandwidth[1]
|
||||
if netBytes == 0 {
|
||||
netBytes = uint64((vm.NetworkSent + vm.NetworkRecv) * 1024 * 1024)
|
||||
}
|
||||
params["net"+suffix] = netBytes
|
||||
}
|
||||
queryString := fmt.Sprintf(
|
||||
"INSERT INTO pve_vms (id, system, name, type, cpu, memory, net, updated) VALUES %s ON CONFLICT(id) DO UPDATE SET system=excluded.system, name=excluded.name, type=excluded.type, cpu=excluded.cpu, memory=excluded.memory, net=excluded.net, updated=excluded.updated",
|
||||
"INSERT INTO pve_vms (id, system, name, type, cpu, mem, net, maxcpu, maxmem, uptime, updated) VALUES %s ON CONFLICT(id) DO UPDATE SET system=excluded.system, name=excluded.name, type=excluded.type, cpu=excluded.cpu, mem=excluded.mem, net=excluded.net, maxcpu=excluded.maxcpu, maxmem=excluded.maxmem, uptime=excluded.uptime, updated=excluded.updated",
|
||||
strings.Join(valueStrings, ","),
|
||||
)
|
||||
_, err := app.DB().NewQuery(queryString).Bind(params).Execute()
|
||||
|
||||
@@ -1691,11 +1691,11 @@ func init() {
|
||||
"deleteRule": null,
|
||||
"fields": [
|
||||
{
|
||||
"autogeneratePattern": "[a-z0-9]{15}",
|
||||
"autogeneratePattern": "[a-z0-9]{10}",
|
||||
"hidden": false,
|
||||
"id": "text3208210256",
|
||||
"max": 15,
|
||||
"min": 15,
|
||||
"max": 10,
|
||||
"min": 10,
|
||||
"name": "id",
|
||||
"pattern": "^[a-z0-9]+$",
|
||||
"presentable": false,
|
||||
@@ -1765,11 +1765,11 @@ func init() {
|
||||
"type": "autodate"
|
||||
}
|
||||
],
|
||||
"id": "pve_stats_col001",
|
||||
"id": "pvestats",
|
||||
"indexes": [
|
||||
"CREATE INDEX ` + "`" + `idx_pve_stats_sys_type_created` + "`" + ` ON ` + "`" + `pve_stats` + "`" + ` (\n ` + "`" + `system` + "`" + `,\n ` + "`" + `type` + "`" + `,\n ` + "`" + `created` + "`" + `\n)"
|
||||
],
|
||||
"listRule": "@request.auth.id != \"\"",
|
||||
"listRule": "@request.auth.id != \"\" && system.users.id ?= @request.auth.id",
|
||||
"name": "pve_stats",
|
||||
"system": false,
|
||||
"type": "base",
|
||||
@@ -1852,7 +1852,7 @@ func init() {
|
||||
"id": "pve_vms_mem001",
|
||||
"max": null,
|
||||
"min": 0,
|
||||
"name": "memory",
|
||||
"name": "mem",
|
||||
"onlyInt": false,
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
@@ -1871,6 +1871,42 @@ func init() {
|
||||
"system": false,
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "number1253106325",
|
||||
"max": null,
|
||||
"min": null,
|
||||
"name": "maxcpu",
|
||||
"onlyInt": false,
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "number1693954525",
|
||||
"max": null,
|
||||
"min": null,
|
||||
"name": "maxmem",
|
||||
"onlyInt": false,
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "number1563400775",
|
||||
"max": null,
|
||||
"min": null,
|
||||
"name": "uptime",
|
||||
"onlyInt": false,
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "pve_vms_upd001",
|
||||
@@ -1884,7 +1920,7 @@ func init() {
|
||||
"type": "number"
|
||||
}
|
||||
],
|
||||
"id": "pve_vms_col0001",
|
||||
"id": "pvevms",
|
||||
"indexes": [
|
||||
"CREATE INDEX ` + "`" + `idx_pve_vms_updated` + "`" + ` ON ` + "`" + `pve_vms` + "`" + ` (` + "`" + `updated` + "`" + `)",
|
||||
"CREATE INDEX ` + "`" + `idx_pve_vms_system` + "`" + ` ON ` + "`" + `pve_vms` + "`" + ` (` + "`" + `system` + "`" + `)"
|
||||
@@ -1896,6 +1932,7 @@ func init() {
|
||||
"updateRule": null,
|
||||
"viewRule": null
|
||||
}
|
||||
|
||||
]`
|
||||
|
||||
err := app.ImportCollectionsByMarshaledJSON([]byte(jsonData), false)
|
||||
Reference in New Issue
Block a user