refactor nvidia collection and cleanup

This commit is contained in:
Meliox 2026-01-11 14:00:04 +01:00
parent e19f9174c9
commit 6fb9e1cf75

View File

@ -271,8 +271,9 @@ sub _collector_for_intel_device {
sub _parse_graphic_info {
my ($line) = @_;
# Create an intel file with
# Timestamp Device index, name, Render/3D, Blitter, Video, VideoEnhance, power consumption
# Create a RRD Database (One-Time Setup)
# Collect intel GPU data and save it into the database
return undef;
}
@ -304,7 +305,7 @@ sub _collector_for_amd_device {
}
# ============================================================================
# NVIDIA GPU Support (Placeholder)
# NVIDIA GPU Support
# ============================================================================
sub get_nvidia_gpu_devices {
@ -315,8 +316,6 @@ sub get_nvidia_gpu_devices {
# 0, NVIDIA GeForce RTX 3080
# 1, NVIDIA RTX A4000
if ($nvidia_debug_mode && -f $nvidia_debug_devices) {
_debug(__LINE__, "Debug mode: reading NVIDIA GPU devices from $nvidia_debug_devices");
if (open my $fh, '<', $nvidia_debug_devices) {
@ -424,31 +423,8 @@ sub parse_nvidia_gpu_line {
return $stats;
}
sub _collector_for_nvidia_devices {
sub _get_and_write_nvidia_stats {
my ($devices) = @_;
$process_type = 'collector';
$0 = "collector-gpu-nvidia-all";
_debug(__LINE__, "NVIDIA collector started for " . scalar(@$devices) . " GPU(s)");
# Set up signal handlers for graceful shutdown
my $shutdown = 0;
$SIG{TERM} = sub {
_debug(__LINE__, "NVIDIA collector received SIGTERM");
$shutdown = 1;
};
$SIG{INT} = sub {
_debug(__LINE__, "NVIDIA collector received SIGINT");
$shutdown = 1;
};
# Expected CSV format (with header):
# index, name, temperature.gpu, utilization.gpu, utilization.memory, memory.used, memory.total, power.draw, power.limit, fan.speed
# 0, NVIDIA GeForce RTX 3080, 62, 79, 44, 8260, 10240, 268.12, 320.00, 67
# 1, NVIDIA RTX A4000, 58, 45, 32, 4120, 16384, 145.50, 200.00, 55
while (!$shutdown) {
my @all_stats;
if ($nvidia_debug_mode && -f $nvidia_debug_output) {
@ -543,6 +519,37 @@ sub _collector_for_nvidia_devices {
_debug(__LINE__, "No valid NVIDIA GPU stats collected");
}
return scalar(@all_stats);
}
sub _collector_for_nvidia_devices {
my ($devices) = @_;
$process_type = 'collector';
$0 = "collector-gpu-nvidia-all";
_debug(__LINE__, "NVIDIA collector started for " . scalar(@$devices) . " GPU(s)");
# Set up signal handlers for graceful shutdown
my $shutdown = 0;
$SIG{TERM} = sub {
_debug(__LINE__, "NVIDIA collector received SIGTERM");
$shutdown = 1;
};
$SIG{INT} = sub {
_debug(__LINE__, "NVIDIA collector received SIGINT");
$shutdown = 1;
};
# Expected CSV format (with header):
# index, name, temperature.gpu, utilization.gpu, utilization.memory, memory.used, memory.total, power.draw, power.limit, fan.speed
# 0, NVIDIA GeForce RTX 3080, 62, 79, 44, 8260, 10240, 268.12, 320.00, 67
# 1, NVIDIA RTX A4000, 58, 45, 32, 4120, 16384, 145.50, 200.00, 55
while (!$shutdown) {
# Collect and write NVIDIA GPU stats
_get_and_write_nvidia_stats($devices);
sleep $data_pull_interval unless $shutdown;
}
@ -579,8 +586,6 @@ sub _start_child_collector {
return $pid;
}
# Legacy PID file functions removed - worker now manages collectors directly via %collectors hash
# ============================================================================
# Temperature Sensors
# ============================================================================