mirror of
https://github.com/henrygd/beszel.git
synced 2026-03-21 21:26:16 +01:00
refactor: small comment / structure updates
This commit is contained in:
@@ -2,13 +2,13 @@ package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/ebitengine/purego"
|
||||
"github.com/henrygd/beszel/internal/entities/system"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
// NVML constants and types
|
||||
@@ -180,7 +180,7 @@ func (c *nvmlCollector) collect() {
|
||||
var temp uint32
|
||||
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 {
|
||||
var usedMem, totalMem uint64
|
||||
if c.isV2 {
|
||||
|
||||
@@ -20,24 +20,6 @@ import (
|
||||
|
||||
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.
|
||||
type systemdManager struct {
|
||||
sync.Mutex
|
||||
@@ -47,6 +29,17 @@ type systemdManager struct {
|
||||
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.
|
||||
func newSystemdManager() (*systemdManager, error) {
|
||||
if skipSystemd, _ := GetEnv("SKIP_SYSTEMD"); skipSystemd == "true" {
|
||||
|
||||
Reference in New Issue
Block a user