Update api.func
This commit is contained in:
parent
bc8a96b3fd
commit
f4ccccfb32
102
misc/api.func
102
misc/api.func
@ -168,6 +168,43 @@ explain_exit_code() {
|
|||||||
# SECTION 2: TELEMETRY FUNCTIONS
|
# SECTION 2: TELEMETRY FUNCTIONS
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# detect_gpu()
|
||||||
|
#
|
||||||
|
# - Detects GPU vendor and passthrough type
|
||||||
|
# - Sets GPU_VENDOR and GPU_PASSTHROUGH globals
|
||||||
|
# - Used for GPU analytics
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
detect_gpu() {
|
||||||
|
GPU_VENDOR=""
|
||||||
|
GPU_PASSTHROUGH="none"
|
||||||
|
|
||||||
|
# Detect Intel GPU
|
||||||
|
if lspci 2>/dev/null | grep -qi "VGA.*Intel"; then
|
||||||
|
GPU_VENDOR="intel"
|
||||||
|
GPU_PASSTHROUGH="igpu"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Detect AMD GPU
|
||||||
|
if lspci 2>/dev/null | grep -qi "VGA.*AMD\|VGA.*ATI"; then
|
||||||
|
GPU_VENDOR="amd"
|
||||||
|
# Check if discrete
|
||||||
|
if lspci 2>/dev/null | grep -qi "AMD.*Radeon"; then
|
||||||
|
GPU_PASSTHROUGH="dgpu"
|
||||||
|
else
|
||||||
|
GPU_PASSTHROUGH="igpu"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Detect NVIDIA GPU
|
||||||
|
if lspci 2>/dev/null | grep -qi "VGA.*NVIDIA\|3D.*NVIDIA"; then
|
||||||
|
GPU_VENDOR="nvidia"
|
||||||
|
GPU_PASSTHROUGH="dgpu"
|
||||||
|
fi
|
||||||
|
|
||||||
|
export GPU_VENDOR GPU_PASSTHROUGH
|
||||||
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# post_to_api()
|
# post_to_api()
|
||||||
#
|
#
|
||||||
@ -215,6 +252,13 @@ post_to_api() {
|
|||||||
pve_version=$(pveversion 2>/dev/null | awk -F'[/ ]' '{print $2}') || true
|
pve_version=$(pveversion 2>/dev/null | awk -F'[/ ]' '{print $2}') || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Detect GPU if not already set
|
||||||
|
if [[ -z "${GPU_VENDOR:-}" ]]; then
|
||||||
|
detect_gpu
|
||||||
|
fi
|
||||||
|
local gpu_vendor="${GPU_VENDOR:-}"
|
||||||
|
local gpu_passthrough="${GPU_PASSTHROUGH:-none}"
|
||||||
|
|
||||||
local JSON_PAYLOAD
|
local JSON_PAYLOAD
|
||||||
JSON_PAYLOAD=$(
|
JSON_PAYLOAD=$(
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
@ -230,7 +274,9 @@ post_to_api() {
|
|||||||
"os_type": "${var_os:-}",
|
"os_type": "${var_os:-}",
|
||||||
"os_version": "${var_version:-}",
|
"os_version": "${var_version:-}",
|
||||||
"pve_version": "${pve_version}",
|
"pve_version": "${pve_version}",
|
||||||
"method": "${METHOD:-default}"
|
"method": "${METHOD:-default}",
|
||||||
|
"gpu_vendor": "${gpu_vendor}",
|
||||||
|
"gpu_passthrough": "${gpu_passthrough}"
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
@ -335,7 +381,11 @@ post_update_to_api() {
|
|||||||
|
|
||||||
local status="${1:-failed}"
|
local status="${1:-failed}"
|
||||||
local raw_exit_code="${2:-1}"
|
local raw_exit_code="${2:-1}"
|
||||||
local exit_code=0 error="" pb_status
|
local exit_code=0 error="" pb_status error_category=""
|
||||||
|
|
||||||
|
# Get GPU info (if detected)
|
||||||
|
local gpu_vendor="${GPU_VENDOR:-}"
|
||||||
|
local gpu_passthrough="${GPU_PASSTHROUGH:-}"
|
||||||
|
|
||||||
# Map status to telemetry values: installing, success, failed, unknown
|
# Map status to telemetry values: installing, success, failed, unknown
|
||||||
case "$status" in
|
case "$status" in
|
||||||
@ -343,6 +393,7 @@ post_update_to_api() {
|
|||||||
pb_status="success"
|
pb_status="success"
|
||||||
exit_code=0
|
exit_code=0
|
||||||
error=""
|
error=""
|
||||||
|
error_category=""
|
||||||
;;
|
;;
|
||||||
failed)
|
failed)
|
||||||
pb_status="failed"
|
pb_status="failed"
|
||||||
@ -360,16 +411,17 @@ post_update_to_api() {
|
|||||||
exit_code=1
|
exit_code=1
|
||||||
fi
|
fi
|
||||||
error=$(explain_exit_code "$exit_code")
|
error=$(explain_exit_code "$exit_code")
|
||||||
|
error_category=$(categorize_error "$exit_code")
|
||||||
[[ -z "$error" ]] && error="Unknown error"
|
[[ -z "$error" ]] && error="Unknown error"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Calculate duration if timer was started
|
# Calculate duration if timer was started
|
||||||
local duration=0
|
local duration=0
|
||||||
if [[ -n "${INSTALL_START_TIME:-}" ]]; then
|
if [[ -n "${INSTALL_START_TIME:-}" ]]; then
|
||||||
duration=$(( $(date +%s) - INSTALL_START_TIME ))
|
duration=$(($(date +%s) - INSTALL_START_TIME))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Update payload: only fields that change (status, error, exit_code, duration)
|
# Update payload: only fields that change (status, error, exit_code, duration, gpu)
|
||||||
# The Go service will find the record by random_id and PATCH only these fields
|
# The Go service will find the record by random_id and PATCH only these fields
|
||||||
local JSON_PAYLOAD
|
local JSON_PAYLOAD
|
||||||
JSON_PAYLOAD=$(
|
JSON_PAYLOAD=$(
|
||||||
@ -381,7 +433,10 @@ post_update_to_api() {
|
|||||||
"status": "${pb_status}",
|
"status": "${pb_status}",
|
||||||
"exit_code": ${exit_code},
|
"exit_code": ${exit_code},
|
||||||
"error": "${error}",
|
"error": "${error}",
|
||||||
"install_duration": ${duration}
|
"error_category": "${error_category}",
|
||||||
|
"install_duration": ${duration},
|
||||||
|
"gpu_vendor": "${gpu_vendor}",
|
||||||
|
"gpu_passthrough": "${gpu_passthrough}"
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
@ -461,43 +516,6 @@ get_install_duration() {
|
|||||||
echo $((now - INSTALL_START_TIME))
|
echo $((now - INSTALL_START_TIME))
|
||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# detect_gpu()
|
|
||||||
#
|
|
||||||
# - Detects GPU vendor and passthrough type
|
|
||||||
# - Sets GPU_VENDOR and GPU_PASSTHROUGH globals
|
|
||||||
# - Used for GPU analytics
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
detect_gpu() {
|
|
||||||
GPU_VENDOR=""
|
|
||||||
GPU_PASSTHROUGH="none"
|
|
||||||
|
|
||||||
# Detect Intel GPU
|
|
||||||
if lspci 2>/dev/null | grep -qi "VGA.*Intel"; then
|
|
||||||
GPU_VENDOR="intel"
|
|
||||||
GPU_PASSTHROUGH="igpu"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Detect AMD GPU
|
|
||||||
if lspci 2>/dev/null | grep -qi "VGA.*AMD\|VGA.*ATI"; then
|
|
||||||
GPU_VENDOR="amd"
|
|
||||||
# Check if discrete
|
|
||||||
if lspci 2>/dev/null | grep -qi "AMD.*Radeon"; then
|
|
||||||
GPU_PASSTHROUGH="dgpu"
|
|
||||||
else
|
|
||||||
GPU_PASSTHROUGH="igpu"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Detect NVIDIA GPU
|
|
||||||
if lspci 2>/dev/null | grep -qi "VGA.*NVIDIA\|3D.*NVIDIA"; then
|
|
||||||
GPU_VENDOR="nvidia"
|
|
||||||
GPU_PASSTHROUGH="dgpu"
|
|
||||||
fi
|
|
||||||
|
|
||||||
export GPU_VENDOR GPU_PASSTHROUGH
|
|
||||||
}
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# post_tool_to_api()
|
# post_tool_to_api()
|
||||||
#
|
#
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user