implement ups debug and intel debug

This commit is contained in:
Meliox 2026-06-13 18:23:13 +02:00
parent bfce5e7f0c
commit d5723821ec
2 changed files with 27 additions and 13 deletions

View File

@ -69,6 +69,7 @@ _load_conf() {
debug.lm_sensors_output_file) DEBUG_LM_SENSORS_FILE="$val" ;; debug.lm_sensors_output_file) DEBUG_LM_SENSORS_FILE="$val" ;;
debug.intel_mode) DEBUG_INTEL="$val" ;; debug.intel_mode) DEBUG_INTEL="$val" ;;
debug.intel_devices_file) DEBUG_INTEL_FILE="$val" ;; debug.intel_devices_file) DEBUG_INTEL_FILE="$val" ;;
debug.intel_output_file) DEBUG_INTEL_OUTPUT_FILE="$val" ;;
debug.nvidia_mode) DEBUG_NVIDIA="$val" ;; debug.nvidia_mode) DEBUG_NVIDIA="$val" ;;
debug.nvidia_devices_file) DEBUG_NVIDIA_DEVICES_FILE="$val" ;; debug.nvidia_devices_file) DEBUG_NVIDIA_DEVICES_FILE="$val" ;;
debug.nvidia_output_file) DEBUG_NVIDIA_OUTPUT_FILE="$val" ;; debug.nvidia_output_file) DEBUG_NVIDIA_OUTPUT_FILE="$val" ;;
@ -311,7 +312,6 @@ configure_node_info() {
if [[ -n "$nvidiaCards" ]]; then if [[ -n "$nvidiaCards" ]]; then
info "NVIDIA GPU(s) detected (debug):" info "NVIDIA GPU(s) detected (debug):"
echo "$nvidiaCards" | while IFS= read -r line; do echo " $line"; done echo "$nvidiaCards" | while IFS= read -r line; do echo " $line"; done
// look for nvidia-smi output file as well, to determine whether to enable GPU stats graphs
if [[ -f "$DEBUG_NVIDIA_OUTPUT_FILE" ]]; then if [[ -f "$DEBUG_NVIDIA_OUTPUT_FILE" ]]; then
info "[debug] NVIDIA GPU stats output file found at $DEBUG_NVIDIA_OUTPUT_FILE" info "[debug] NVIDIA GPU stats output file found at $DEBUG_NVIDIA_OUTPUT_FILE"
ENABLE_NVIDIA_GPU_INFO=1 ENABLE_NVIDIA_GPU_INFO=1
@ -358,16 +358,20 @@ configure_node_info() {
[yY]) [yY])
local upsConn modelName upsOutput local upsConn modelName upsOutput
upsConn=$(ask "Enter UPS connection string (e.g. upsname@hostname[:port])") upsConn=$(ask "Enter UPS connection string (e.g. upsname@hostname[:port])")
if [[ "$DEBUG_UPS" -eq 1 && -f "$DEBUG_UPS_FILE" ]]; then if [[ "$DEBUG_UPS" -eq 1 ]]; then
info "[debug] Using UPS data from $DEBUG_UPS_FILE" if [[ -f "$DEBUG_UPS_FILE" ]]; then
upsOutput=$(cat "$DEBUG_UPS_FILE") info "[debug] Using UPS data from $DEBUG_UPS_FILE"
else else
if ! command -v upsc &>/dev/null; then warn "[debug] Debug mode for UPS is enabled but file not found at $DEBUG_UPS_FILE."
err "'upsc' is not available. Install 'nut-client' first."
fi fi
upsOutput=$(upsc "$upsConn" 2>&1) upsOutput=$(cat "$DEBUG_UPS_FILE" || true)
ENABLE_UPS=1
elif _check_or_install_tool upsc nut-client "Network UPS Tools (upsc)" && [[ -n "$upsConn" ]]; then
upsOutput=$(upsc "$upsConn" 2>/dev/null || true)
else
warn "Could not connect to UPS at '$upsConn'. UPS info will be disabled."
fi fi
if echo "$upsOutput" | grep -q "device.model:"; then if [[ -n "$upsOutput" ]]; then
modelName=$(echo "$upsOutput" | grep "device.model:" | cut -d: -f2- | xargs) modelName=$(echo "$upsOutput" | grep "device.model:" | cut -d: -f2- | xargs)
ENABLE_UPS=1 ENABLE_UPS=1
UPS_DEVICE_NAME="$upsConn" UPS_DEVICE_NAME="$upsConn"
@ -376,7 +380,7 @@ configure_node_info() {
warn "Could not connect to UPS at '$upsConn'. UPS info will be disabled." warn "Could not connect to UPS at '$upsConn'. UPS info will be disabled."
ENABLE_UPS=0 ENABLE_UPS=0
fi fi
;; ;;
*) info "UPS information disabled." ;; *) info "UPS information disabled." ;;
esac esac
#endregion UPS #endregion UPS

View File

@ -6,7 +6,7 @@ use Exporter 'import';
use JSON; use JSON;
use PVE::PVEMod::Config qw($process_type $ups_state_file); use PVE::PVEMod::Config qw(%config $process_type $ups_state_file);
use PVE::PVEMod::Utils qw(debug setup_collector_signals); use PVE::PVEMod::Utils qw(debug setup_collector_signals);
our @EXPORT_OK = qw( our @EXPORT_OK = qw(
@ -40,7 +40,7 @@ sub collector_for_ups {
debug(__LINE__, "Error writing UPS data: $@"); debug(__LINE__, "Error writing UPS data: $@");
} }
sleep 1 unless $shutdown; # $config{intervals}{data_pull} sleep $config{intervals}{data_pull} unless $shutdown;
} }
debug(__LINE__, "UPS collector shutting down"); debug(__LINE__, "UPS collector shutting down");
@ -56,7 +56,17 @@ sub _get_ups_status {
debug(__LINE__, "Collecting UPS status for $ups_name"); debug(__LINE__, "Collecting UPS status for $ups_name");
my $output = `/usr/bin/upsc $ups_name 2>/dev/null`; my $output;
if ($config{debug}{ups_mode} && -f $config{debug}{ups_output_file}) {
debug(__LINE__, "Debug mode: reading UPS data from $config{debug}{ups_output_file}");
open my $fh, '<', $config{debug}{ups_output_file}
or do { debug(__LINE__, "Failed to open debug file $config{debug}{ups_output_file}: $!"); return encode_json({ error => "Failed to open debug file" }); };
local $/;
$output = <$fh>;
close $fh;
} else {
$output = `/usr/bin/upsc $ups_name 2>/dev/null`;
}
unless (defined $output && length($output) > 0) { unless (defined $output && length($output) > 0) {
debug(__LINE__, "No output from upsc for $ups_name"); debug(__LINE__, "No output from upsc for $ups_name");