implement ups debug and intel debug
This commit is contained in:
parent
bfce5e7f0c
commit
d5723821ec
@ -69,6 +69,7 @@ _load_conf() {
|
||||
debug.lm_sensors_output_file) DEBUG_LM_SENSORS_FILE="$val" ;;
|
||||
debug.intel_mode) DEBUG_INTEL="$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_devices_file) DEBUG_NVIDIA_DEVICES_FILE="$val" ;;
|
||||
debug.nvidia_output_file) DEBUG_NVIDIA_OUTPUT_FILE="$val" ;;
|
||||
@ -311,7 +312,6 @@ configure_node_info() {
|
||||
if [[ -n "$nvidiaCards" ]]; then
|
||||
info "NVIDIA GPU(s) detected (debug):"
|
||||
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
|
||||
info "[debug] NVIDIA GPU stats output file found at $DEBUG_NVIDIA_OUTPUT_FILE"
|
||||
ENABLE_NVIDIA_GPU_INFO=1
|
||||
@ -358,16 +358,20 @@ configure_node_info() {
|
||||
[yY])
|
||||
local upsConn modelName upsOutput
|
||||
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
|
||||
if [[ -f "$DEBUG_UPS_FILE" ]]; then
|
||||
info "[debug] Using UPS data from $DEBUG_UPS_FILE"
|
||||
upsOutput=$(cat "$DEBUG_UPS_FILE")
|
||||
else
|
||||
if ! command -v upsc &>/dev/null; then
|
||||
err "'upsc' is not available. Install 'nut-client' first."
|
||||
warn "[debug] Debug mode for UPS is enabled but file not found at $DEBUG_UPS_FILE."
|
||||
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
|
||||
if echo "$upsOutput" | grep -q "device.model:"; then
|
||||
if [[ -n "$upsOutput" ]]; then
|
||||
modelName=$(echo "$upsOutput" | grep "device.model:" | cut -d: -f2- | xargs)
|
||||
ENABLE_UPS=1
|
||||
UPS_DEVICE_NAME="$upsConn"
|
||||
|
||||
@ -6,7 +6,7 @@ use Exporter 'import';
|
||||
|
||||
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);
|
||||
|
||||
our @EXPORT_OK = qw(
|
||||
@ -40,7 +40,7 @@ sub collector_for_ups {
|
||||
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");
|
||||
@ -56,7 +56,17 @@ sub _get_ups_status {
|
||||
|
||||
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) {
|
||||
debug(__LINE__, "No output from upsc for $ups_name");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user