Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

refactor: remove unnecessary type conversions

rcourtman2ff0a0988f6f
diff --git a/cmd/pulse/config.go b/cmd/pulse/config.go
index 3fb6789dcd..1ccab0cc98 100644
--- a/cmd/pulse/config.go
+++ b/cmd/pulse/config.go
@@ -177,7 +177,7 @@ func getPassphrase(prompt string, confirm bool) string {
// Interactive prompt
fmt.Print(prompt)
- bytePassword, err := term.ReadPassword(int(syscall.Stdin))
+ bytePassword, err := term.ReadPassword(syscall.Stdin)
fmt.Println()
if err != nil {
return ""
@@ -188,7 +188,7 @@ func getPassphrase(prompt string, confirm bool) string {
// Confirm if requested
if confirm {
fmt.Print("Confirm passphrase: ")
- bytePassword2, err := term.ReadPassword(int(syscall.Stdin))
+ bytePassword2, err := term.ReadPassword(syscall.Stdin)
fmt.Println()
if err != nil {
return ""
diff --git a/internal/mock/generator.go b/internal/mock/generator.go
index 532b1579c8..859d49b278 100644
--- a/internal/mock/generator.go
+++ b/internal/mock/generator.go
@@ -1008,8 +1008,8 @@ func generateGuestNetworkInfo() ([]string, []models.GuestNetworkInterface) {
ipAddresses = append(ipAddresses, ip)
}
- rxBytes := int64(rand.Int63n(8*1024*1024*1024) + rand.Int63n(256*1024*1024))
- txBytes := int64(rand.Int63n(6*1024*1024*1024) + rand.Int63n(256*1024*1024))
+ rxBytes := rand.Int63n(8*1024*1024*1024) + rand.Int63n(256*1024*1024)
+ txBytes := rand.Int63n(6*1024*1024*1024) + rand.Int63n(256*1024*1024)
interfaces = append(interfaces, models.GuestNetworkInterface{
Name: name,
@@ -2537,7 +2537,7 @@ func generateBackups(vms []models.VM, containers []models.Container) []models.St
numBackups := 1 + rand.Intn(3)
for i := 0; i < numBackups; i++ {
backupTime := time.Now().Add(-time.Duration(rand.Intn(30*24)) * time.Hour)
- backupSize := int64(vm.Disk.Total/10 + rand.Int63n(vm.Disk.Total/5)) // 10-30% of disk size
+ backupSize := vm.Disk.Total/10 + rand.Int63n(vm.Disk.Total/5) // 10-30% of disk size
backup := models.StorageBackup{
ID: fmt.Sprintf("backup-%s-vm-%d-%d", vm.Node, vm.VMID, i),
@@ -2575,22 +2575,22 @@ func generateBackups(vms []models.VM, containers []models.Container) []models.St
numBackups := 1 + rand.Intn(2)
for i := 0; i < numBackups; i++ {
backupTime := time.Now().Add(-time.Duration(rand.Intn(30*24)) * time.Hour)
- backupSize := int64(ct.Disk.Total/20 + rand.Int63n(ct.Disk.Total/10)) // 5-15% of disk size
+ backupSize := ct.Disk.Total/20 + rand.Int63n(ct.Disk.Total/10) // 5-15% of disk size
backup := models.StorageBackup{
- ID: fmt.Sprintf("backup-%s-ct-%d-%d", ct.Node, int(ct.VMID), i),
+ ID: fmt.Sprintf("backup-%s-ct-%d-%d", ct.Node, ct.VMID, i),
Storage: "local",
Node: ct.Node,
Instance: ct.Instance,
Type: "lxc",
- VMID: int(ct.VMID),
+ VMID: ct.VMID,
Time: backupTime,
CTime: backupTime.Unix(),
Size: backupSize,
Format: "tar.zst",
Notes: fmt.Sprintf("Backup of %s", ct.Name),
Protected: rand.Float64() > 0.9, // 10% protected
- Volid: fmt.Sprintf("local:backup/vzdump-lxc-%d-%s.tar.zst", int(ct.VMID), backupTime.Format("2006_01_02-15_04_05")),
+ Volid: fmt.Sprintf("local:backup/vzdump-lxc-%d-%s.tar.zst", ct.VMID, backupTime.Format("2006_01_02-15_04_05")),
IsPBS: false,
Verified: rand.Float64() > 0.2, // 80% verified
}
@@ -2784,7 +2784,7 @@ func generatePBSBackups(vms []models.VM, containers []models.Container) []models
BackupType: "vm",
VMID: fmt.Sprintf("%d", vm.VMID),
BackupTime: backupTime,
- Size: int64(vm.Disk.Total/8 + rand.Int63n(vm.Disk.Total/4)),
+ Size: vm.Disk.Total/8 + rand.Int63n(vm.Disk.Total/4),
Protected: rand.Float64() > 0.85, // 15% protected
Verified: rand.Float64() > 0.2, // 80% verified
Comment: fmt.Sprintf("Automated backup of %s", vm.Name),
@@ -2807,14 +2807,14 @@ func generatePBSBackups(vms []models.VM, containers []models.Container) []models
backupTime := time.Now().Add(-time.Duration(rand.Intn(45*24)) * time.Hour)
backup := models.PBSBackup{
- ID: fmt.Sprintf("pbs-backup-ct-%d-%d", int(ct.VMID), i),
+ ID: fmt.Sprintf("pbs-backup-ct-%d-%d", ct.VMID, i),
Instance: pbsInstances[rand.Intn(len(pbsInstances))],
Datastore: datastores[rand.Intn(len(datastores))],
Namespace: "root",
BackupType: "ct",
- VMID: fmt.Sprintf("%d", int(ct.VMID)),
+ VMID: fmt.Sprintf("%d", ct.VMID),
BackupTime: backupTime,
- Size: int64(ct.Disk.Total/15 + rand.Int63n(ct.Disk.Total/8)),
+ Size: ct.Disk.Total/15 + rand.Int63n(ct.Disk.Total/8),
Protected: rand.Float64() > 0.9, // 10% protected
Verified: rand.Float64() > 0.15, // 85% verified
Comment: fmt.Sprintf("Daily backup of %s", ct.Name),
@@ -2839,9 +2839,9 @@ func generatePBSBackups(vms []models.VM, containers []models.Container) []models
BackupType: "ct", // Host configs are stored as 'ct' type in PBS
VMID: "0", // VMID 0 indicates host config
BackupTime: backupTime,
- Size: int64(50*1024*1024 + rand.Int63n(100*1024*1024)), // 50-150MB for host configs
- Protected: rand.Float64() > 0.7, // 30% protected
- Verified: rand.Float64() > 0.1, // 90% verified
+ Size: 50*1024*1024 + rand.Int63n(100*1024*1024), // 50-150MB for host configs
+ Protected: rand.Float64() > 0.7, // 30% protected
+ Verified: rand.Float64() > 0.1, // 90% verified
Comment: "PMG host configuration backup",
Owner: "root@pam",
}
@@ -3076,12 +3076,12 @@ func generateSnapshots(vms []models.VM, containers []models.Container) []models.
snapshotTime := time.Now().Add(-time.Duration(rand.Intn(60*24)) * time.Hour)
snapshot := models.GuestSnapshot{
- ID: fmt.Sprintf("snapshot-%s-ct-%d-%d", ct.Node, int(ct.VMID), i),
+ ID: fmt.Sprintf("snapshot-%s-ct-%d-%d", ct.Node, ct.VMID, i),
Name: snapshotNames[rand.Intn(len(snapshotNames))],
Node: ct.Node,
Instance: ct.Instance,
Type: "lxc",
- VMID: int(ct.VMID),
+ VMID: ct.VMID,
Time: snapshotTime,
Description: fmt.Sprintf("Container snapshot for %s", ct.Name),
VMState: false, // Containers don't have VM state
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index 3c45e6ed05..81e5ef2f95 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -6913,7 +6913,7 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
Status: res.Status,
Type: "lxc",
CPU: safeFloat(res.CPU),
- CPUs: int(res.MaxCPU),
+ CPUs: res.MaxCPU,
Memory: models.Memory{
Total: int64(memTotal),
Used: int64(memUsed),
@@ -8132,7 +8132,7 @@ func (m *Monitor) pollStorageBackupsWithNodes(ctx context.Context, instanceName
}
for _, ct := range snapshot.Containers {
if ct.Instance == instanceName {
- guestNodeMap[int(ct.VMID)] = ct.Node
+ guestNodeMap[ct.VMID] = ct.Node
}
}
@@ -8465,9 +8465,9 @@ func buildGuestLookups(snapshot models.StateSnapshot, metadataStore *config.Gues
Instance: ct.Instance,
Node: ct.Node,
Type: ct.Type,
- VMID: int(ct.VMID),
+ VMID: ct.VMID,
}
- key := alerts.BuildGuestKey(ct.Instance, ct.Node, int(ct.VMID))
+ key := alerts.BuildGuestKey(ct.Instance, ct.Node, ct.VMID)
if _, exists := byKey[key]; !exists {
byKey[key] = info
}
diff --git a/internal/monitoring/monitor_polling.go b/internal/monitoring/monitor_polling.go
index bcb49ed782..2a2d1d59e0 100644
--- a/internal/monitoring/monitor_polling.go
+++ b/internal/monitoring/monitor_polling.go
@@ -443,8 +443,8 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, cli
// Calculate disk usage - start with allocated disk size
// NOTE: The Proxmox cluster/resources API always returns 0 for VM disk usage
// We must query the guest agent to get actual disk usage
- diskUsed := uint64(vm.Disk)
- diskTotal := uint64(vm.MaxDisk)
+ diskUsed := vm.Disk
+ diskTotal := vm.MaxDisk
diskFree := diskTotal - diskUsed
diskUsage := safePercentage(float64(diskUsed), float64(diskTotal))
diskStatusReason := ""
@@ -733,7 +733,7 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, cli
Status: vm.Status,
Type: "qemu",
CPU: cpuUsage,
- CPUs: int(vm.CPUs),
+ CPUs: vm.CPUs,
Memory: memory,
Disk: models.Disk{
Total: int64(diskTotal),