add more config debug modes. remove duplicate code. refactor of start collector
This commit is contained in:
parent
d45407fc7e
commit
16fa01f9d4
@ -21,16 +21,6 @@ sub collector_for_temperature_sensors {
|
||||
my ($device) = @_;
|
||||
$process_type = 'collector';
|
||||
$0 = "collector-temperature-sensors";
|
||||
|
||||
debug(__LINE__, "Temperature sensor collector started");
|
||||
|
||||
unless (check_executable('/usr/bin/sensors', 'lm-sensors',
|
||||
$config{debug}{sensors_mode},
|
||||
$config{debug}{sensors_output_file})) {
|
||||
debug(__LINE__, "sensors not available and not in debug mode, exiting");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
my %cache;
|
||||
my $shutdown = 0;
|
||||
setup_collector_signals('temperature-sensors', \$shutdown);
|
||||
@ -65,39 +55,39 @@ sub _get_temperature_sensors {
|
||||
|
||||
my $sensors_output;
|
||||
|
||||
if ($config{debug}{sensors_mode} && -f $config{debug}{sensors_output_file}) {
|
||||
debug(__LINE__, "Debug mode: reading sensors data from $config{debug}{sensors_output_file}");
|
||||
if (open my $fh, '<', $config{debug}{sensors_output_file}) {
|
||||
if ($config{debug}{lm_sensors_mode} && -f $config{debug}{lm_sensors_output_file}) {
|
||||
debug(__LINE__, "Debug mode: reading lm-sensors data from $config{debug}{lm_sensors_output_file}");
|
||||
if (open my $fh, '<', $config{debug}{lm_sensors_output_file}) {
|
||||
local $/;
|
||||
$sensors_output = <$fh>;
|
||||
close $fh;
|
||||
debug(__LINE__, "Read sensors data from debug file, length: "
|
||||
debug(__LINE__, "Read lm-sensors data from debug file, length: "
|
||||
. length($sensors_output) . " bytes");
|
||||
} else {
|
||||
debug(__LINE__, "Failed to open debug file $config{debug}{sensors_output_file}: $!");
|
||||
debug(__LINE__, "Failed to open debug file $config{debug}{lm_sensors_output_file}: $!");
|
||||
$sensors_output = '{}';
|
||||
}
|
||||
} else {
|
||||
$sensors_output = `sensors -j 2>/dev/null | python3 -m json.tool`;
|
||||
debug(__LINE__, "Raw sensors output collected from command");
|
||||
debug(__LINE__, "Raw lm-sensors output collected from command");
|
||||
}
|
||||
|
||||
debug(__LINE__, "Raw sensors output collected");
|
||||
debug(__LINE__, "Raw lm-sensors output collected");
|
||||
|
||||
my $data = _sanitize_sensors($sensors_output);
|
||||
debug(__LINE__, "Sanitized sensors output");
|
||||
debug(__LINE__, "Sanitized lm-sensors output");
|
||||
|
||||
$data = _get_drive_names($data, $cache_ref);
|
||||
debug(__LINE__, "Translated drive names in sensors output");
|
||||
debug(__LINE__, "Translated drive names in lm-sensors output");
|
||||
|
||||
$data = _get_cpu_name($data, $cache_ref);
|
||||
debug(__LINE__, "Translated CPU names in sensors output");
|
||||
debug(__LINE__, "Translated CPU names in lm-sensors output");
|
||||
|
||||
# Wrap in top-level key
|
||||
my $sensors_json;
|
||||
eval { $sensors_json = decode_json($data); };
|
||||
if ($@) {
|
||||
debug(__LINE__, "Failed to parse final sensors JSON: $@");
|
||||
debug(__LINE__, "Failed to parse final lm-sensors JSON: $@");
|
||||
return $data;
|
||||
}
|
||||
|
||||
@ -126,7 +116,7 @@ sub _sanitize_sensors {
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Enrich sensors data with drive device info
|
||||
# Enrich lm-sensors data with drive device info
|
||||
# ============================================================================
|
||||
|
||||
sub _get_drive_names {
|
||||
@ -144,7 +134,7 @@ sub _get_drive_names {
|
||||
/^drivetemp-scsi-/ || /^drivetemp-nvme-/ || /^nvme-pci-/
|
||||
} keys %{$sensors_data};
|
||||
|
||||
debug(__LINE__, "Found " . scalar(@entries) . " drive entries in sensors output");
|
||||
debug(__LINE__, "Found " . scalar(@entries) . " drive entries in lm-sensors output");
|
||||
|
||||
my @drive_names;
|
||||
|
||||
@ -282,7 +272,7 @@ sub _get_drive_names {
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Enrich sensors data with CPU model info
|
||||
# Enrich lm-sensors data with CPU model info
|
||||
# ============================================================================
|
||||
|
||||
sub _get_cpu_name {
|
||||
|
||||
@ -38,13 +38,22 @@ our %config = (
|
||||
nvidia_mode => 1,
|
||||
nvidia_devices_file => '/tmp/nvidia-smi-devices.csv',
|
||||
nvidia_output_file => '/tmp/nvidia-smi-output.csv',
|
||||
sensors_mode => 0,
|
||||
sensors_output_file => '/tmp/sensors-output.json',
|
||||
intel_mode => 0,
|
||||
intel_devices_file => '/tmp/intel-gpu-devices.json',
|
||||
amd_mode => 0,
|
||||
amd_devices_file => '/tmp/amd-gpu-devices.json',
|
||||
ups_mode => 0,
|
||||
ups_output_file => '/tmp/ups-output.json',
|
||||
lm_sensors_mode => 0,
|
||||
lm_sensors_output_file => '/tmp/sensors-output.json',
|
||||
},
|
||||
intervals => {
|
||||
data_pull => 1, # seconds between data pulls
|
||||
collector_timeout => 10, # stop collectors after N seconds of inactivity
|
||||
},
|
||||
lm_sensors => {
|
||||
enabled => 1,
|
||||
},
|
||||
ups => {
|
||||
enabled => 1,
|
||||
device_name => 'ups@192.168.3.2',
|
||||
|
||||
@ -234,38 +234,27 @@ sub _pve_mod_keep_alive {
|
||||
# ============================================================================
|
||||
|
||||
sub _start_sensors_collector {
|
||||
debug(__LINE__, "Starting temperature sensor collector");
|
||||
|
||||
unless (check_executable('/usr/bin/sensors', 'lm-sensors',
|
||||
$config{debug}{sensors_mode},
|
||||
$config{debug}{sensors_output_file})) {
|
||||
debug(__LINE__, "sensors not available and not in debug mode, skipping");
|
||||
return;
|
||||
}
|
||||
return unless $config{lm_sensors}{enabled};
|
||||
return unless check_executable('/usr/bin/sensors', 'lm-sensors',
|
||||
$config{debug}{lm_sensors_mode},
|
||||
$config{debug}{lm_sensors_output_file});
|
||||
|
||||
debug(__LINE__, "Starting lm-sensors collector");
|
||||
_start_collector('sensors', 'sensors',
|
||||
\&collector_for_temperature_sensors,
|
||||
{ name => 'sensors' });
|
||||
}
|
||||
|
||||
sub _start_ups_collector {
|
||||
unless ($config{ups}{enabled}) {
|
||||
debug(__LINE__, "UPS support not enabled, skipping collector startup");
|
||||
return;
|
||||
}
|
||||
|
||||
debug(__LINE__, "Starting UPS collector");
|
||||
|
||||
unless (check_executable('/usr/bin/upsc', 'UPS')) {
|
||||
debug(__LINE__, "upsc not available, skipping UPS collector startup");
|
||||
return;
|
||||
}
|
||||
|
||||
unless ($config{ups}{device_name}) {
|
||||
debug(__LINE__, "No UPS configured, skipping collector startup");
|
||||
unless ($config{ups}{enabled} && $config{ups}{device_name}) {
|
||||
debug(__LINE__, "UPS collection disabled/invalid in config, skipping");
|
||||
return;
|
||||
}
|
||||
return unless check_executable('/usr/bin/upsc', 'UPS',
|
||||
$config{debug}{ups_mode},
|
||||
$config{debug}{ups_output_file});
|
||||
|
||||
debug(__LINE__, "Starting UPS collector: $config{ups}{device_name}");
|
||||
_start_collector('ups', 'ups', \&collector_for_ups,
|
||||
{ ups_name => $config{ups}{device_name} });
|
||||
}
|
||||
@ -284,7 +273,9 @@ sub _start_graphics_collectors {
|
||||
my @nvidia_devices;
|
||||
|
||||
# Intel (each GPU has its own collector)
|
||||
if ($config{gpu}{intel_enabled} && check_executable('/usr/bin/intel_gpu_top', 'Intel')) {
|
||||
if ($config{gpu}{intel_enabled} && check_executable('/usr/bin/intel_gpu_top', 'Intel',
|
||||
$config{debug}{intel_mode},
|
||||
$config{debug}{intel_devices_file})) {
|
||||
my @intel_devices = get_intel_gpu_devices();
|
||||
for my $device (@intel_devices) {
|
||||
push @all_devices, $device;
|
||||
@ -294,7 +285,9 @@ sub _start_graphics_collectors {
|
||||
}
|
||||
|
||||
# AMD (each GPU has its own collector)
|
||||
if ($config{gpu}{amd_enabled} && check_executable('/usr/bin/rocm-smi', 'AMD')) {
|
||||
if ($config{gpu}{amd_enabled} && check_executable('/usr/bin/rocm-smi', 'AMD',
|
||||
$config{debug}{amd_mode},
|
||||
$config{debug}{amd_devices_file})) {
|
||||
my @amd_devices = get_amd_gpu_devices();
|
||||
for my $device (@amd_devices) {
|
||||
push @all_devices, $device;
|
||||
@ -304,7 +297,9 @@ sub _start_graphics_collectors {
|
||||
}
|
||||
|
||||
# NVIDIA (all GPUs collected together in one collector due to nvidia-smi design)
|
||||
if ($config{gpu}{nvidia_enabled} && check_executable('/usr/bin/nvidia-smi', 'NVIDIA')) {
|
||||
if ($config{gpu}{nvidia_enabled} && check_executable('/usr/bin/nvidia-smi', 'NVIDIA',
|
||||
$config{debug}{nvidia_mode},
|
||||
$config{debug}{nvidia_devices_file})) {
|
||||
@nvidia_devices = get_nvidia_gpu_devices();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user