refactor: small comment / structure updates

This commit is contained in:
henrygd
2026-01-05 16:25:30 -05:00
parent 6282794004
commit 3d970defe9
2 changed files with 13 additions and 20 deletions

View File

@@ -2,13 +2,13 @@ package agent
import ( import (
"fmt" "fmt"
"log/slog"
"strings" "strings"
"time" "time"
"unsafe" "unsafe"
"github.com/ebitengine/purego" "github.com/ebitengine/purego"
"github.com/henrygd/beszel/internal/entities/system" "github.com/henrygd/beszel/internal/entities/system"
"log/slog"
) )
// NVML constants and types // NVML constants and types
@@ -180,7 +180,7 @@ func (c *nvmlCollector) collect() {
var temp uint32 var temp uint32
nvmlDeviceGetTemperature(device, 0, &temp) // 0 is NVML_TEMPERATURE_GPU nvmlDeviceGetTemperature(device, 0, &temp) // 0 is NVML_TEMPERATURE_GPU
// only poll memory if GPU is active to avoid resetting 21 second suspend timer // Memory: only poll if GPU is active to avoid leaving D3cold state (#1522)
if utilization.Gpu > 0 { if utilization.Gpu > 0 {
var usedMem, totalMem uint64 var usedMem, totalMem uint64
if c.isV2 { if c.isV2 {

View File

@@ -20,24 +20,6 @@ import (
var errNoActiveTime = errors.New("no active time") var errNoActiveTime = errors.New("no active time")
// isSystemdAvailable checks if systemd is running as the init system (PID 1).
// This prevents unnecessary connection attempts on systems using other init systems
// like OpenRC, runit, or when running in containers without systemd.
func isSystemdAvailable() bool {
// Check if /run/systemd/system directory exists - this is a reliable indicator
// that systemd is running as the init system
if _, err := os.Stat("/run/systemd/system"); err == nil {
return true
}
// Fallback: check if PID 1 is systemd by reading /proc/1/comm
if data, err := os.ReadFile("/proc/1/comm"); err == nil {
return strings.TrimSpace(string(data)) == "systemd"
}
return false
}
// systemdManager manages the collection of systemd service statistics. // systemdManager manages the collection of systemd service statistics.
type systemdManager struct { type systemdManager struct {
sync.Mutex sync.Mutex
@@ -47,6 +29,17 @@ type systemdManager struct {
patterns []string patterns []string
} }
// isSystemdAvailable checks if systemd is used on the system to avoid unnecessary connection attempts.
func isSystemdAvailable() bool {
if _, err := os.Stat("/run/systemd/system"); err == nil {
return true
}
if data, err := os.ReadFile("/proc/1/comm"); err == nil {
return strings.TrimSpace(string(data)) == "systemd"
}
return false
}
// newSystemdManager creates a new systemdManager. // newSystemdManager creates a new systemdManager.
func newSystemdManager() (*systemdManager, error) { func newSystemdManager() (*systemdManager, error) {
if skipSystemd, _ := GetEnv("SKIP_SYSTEMD"); skipSystemd == "true" { if skipSystemd, _ := GetEnv("SKIP_SYSTEMD"); skipSystemd == "true" {