perf: Use strconv.Itoa instead of fmt.Sprintf for int conversion

strconv.Itoa is faster than fmt.Sprintf("%d", ...) because it doesn't
need to parse a format string. Changed 4 occurrences in monitoring
package where integers are converted to strings.
This commit is contained in:
rcourtman 2025-12-02 15:21:41 +00:00
parent a965285738
commit b47a04aa97
2 changed files with 4 additions and 4 deletions

View file

@ -7264,7 +7264,7 @@ func buildGuestLookups(snapshot models.StateSnapshot, metadataStore *config.Gues
key := alerts.BuildGuestKey(vm.Instance, vm.Node, vm.VMID)
byKey[key] = info
vmidKey := fmt.Sprintf("%d", vm.VMID)
vmidKey := strconv.Itoa(vm.VMID)
byVMID[vmidKey] = append(byVMID[vmidKey], info)
// Persist last-known name and type for this guest
@ -7286,7 +7286,7 @@ func buildGuestLookups(snapshot models.StateSnapshot, metadataStore *config.Gues
byKey[key] = info
}
vmidKey := fmt.Sprintf("%d", ct.VMID)
vmidKey := strconv.Itoa(ct.VMID)
byVMID[vmidKey] = append(byVMID[vmidKey], info)
// Persist last-known name and type for this guest
@ -7320,7 +7320,7 @@ func enrichWithPersistedMetadata(metadataStore *config.GuestMetadataStore, byVMI
continue // Invalid key format
}
vmidKey := fmt.Sprintf("%d", vmid)
vmidKey := strconv.Itoa(vmid)
// Check if we already have a live entry for this exact guest
hasLiveEntry := false

View file

@ -259,7 +259,7 @@ func (tc *TemperatureCollector) runSSHCommand(ctx context.Context, host, command
"-o", "BatchMode=yes",
"-o", "LogLevel=ERROR", // Suppress host key warnings that break JSON parsing
"-o", "ConnectTimeout=5",
"-p", fmt.Sprintf("%d", tc.sshPort), // Use configured SSH port
"-p", strconv.Itoa(tc.sshPort), // Use configured SSH port
}
if tc.hostKeys != nil && tc.hostKeys.Path() != "" {