Skip to content
Snippets Groups Projects
Commit 0c31fcab authored by František Řezníček's avatar František Řezníček
Browse files

fix: avoid crashing on read(line) when no GPU found

parent 0c515077
No related branches found
No related tags found
No related merge requests found
Pipeline #161333 passed
...@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [1.2.2] - 2022-06-07
### Added
- gpumon: avoid crashing on no GPU (readlink)
## [1.2.1] - 2022-06-07 ## [1.2.1] - 2022-06-07
### Added ### Added
- gpumon: avoid crashing on no GPU - gpumon: avoid crashing on no GPU
......
...@@ -56,26 +56,27 @@ fi ...@@ -56,26 +56,27 @@ fi
# browse the GPUs and export metrics # browse the GPUs and export metrics
METRIC_NAME="gpumon_device_state_code" METRIC_NAME="gpumon_device_state_code"
STAGE_NAME="GPU cards ${METRIC_NAME} metrics generated" STAGE_NAME="GPU devices ${METRIC_NAME} metrics generated"
if [ -n "${GPU_DEVICES}" ]; then if [ -n "${GPU_DEVICES}" ]; then
get_metric_help "${METRIC_NAME}" "gauge" "GPU device state code (0/1 ~ available free/unavailable used)." get_metric_help "${METRIC_NAME}" "gauge" "GPU device state code (0/1 ~ available free/unavailable used)."
echo "${GPU_DEVICES}" | \
while read i_gpu_device ; do
STAGE_NAME="GPU device ${METRIC_NAME} metrics generated (${i_gpu_device})"
[ -z "${i_gpu_device}" ] && \
continue
i_gpu_device_location="$(echo "${i_gpu_device}" | awk '{printf $1}')"
i_gpu_device_vendor="$(echo "${i_gpu_device}" | gawk 'BEGIN{FPAT = "(\"[^\"]+\")"}{printf $2}' | tr -d '"')"
i_gpu_device_model="$(echo "${i_gpu_device}" | gawk 'BEGIN{FPAT = "(\"[^\"]+\")"}{printf $3}' | tr -d '"')"
i_gpu_device_revision="$(echo "${i_gpu_device}" | grep -Eo -- "-r[^ \t]+")"
i_gpu_attached=0
i_vm_domain_name=""
if lspci -v -s "${i_gpu_device_location}" | grep -qE 'Kernel driver in use: .+'; then
i_gpu_attached=1
i_vm_domain_file="$(find_gpu_passthough_vm_manifest "${i_gpu_device_location}")"
i_vm_domain_name="$(basename $(echo "${i_vm_domain_file}" | head -1) | sed 's/.xml//g')"
fi
printf '%s{device="%s",vendor="%s",location="%s",revision="%s",domain="%s"} %d\n' "${METRIC_NAME}" \
"${i_gpu_device_model}" "${i_gpu_device_vendor}" "${i_gpu_device_location}" \
"${i_gpu_device_revision:2}" "${i_vm_domain_name}" "${i_gpu_attached}"
done
fi fi
echo "${GPU_DEVICES}" | \
while read i_gpu_device ; do
[ -z "${i_gpu_device}" ] && \
continue
i_gpu_device_location="$(echo "${i_gpu_device}" | awk '{printf $1}')"
i_gpu_device_vendor="$(echo "${i_gpu_device}" | gawk 'BEGIN{FPAT = "(\"[^\"]+\")"}{printf $2}' | tr -d '"')"
i_gpu_device_model="$(echo "${i_gpu_device}" | gawk 'BEGIN{FPAT = "(\"[^\"]+\")"}{printf $3}' | tr -d '"')"
i_gpu_device_revision="$(echo "${i_gpu_device}" | grep -Eo -- "-r[^ \t]+")"
i_gpu_attached=0
i_vm_domain_name=""
if lspci -v -s "${i_gpu_device_location}" | grep -qE 'Kernel driver in use: .+'; then
i_gpu_attached=1
i_vm_domain_file="$(find_gpu_passthough_vm_manifest "${i_gpu_device_location}")"
i_vm_domain_name="$(basename $(echo "${i_vm_domain_file}" | head -1) | sed 's/.xml//g')"
fi
printf '%s{device="%s",vendor="%s",location="%s",revision="%s",domain="%s"} %d\n' "${METRIC_NAME}" \
"${i_gpu_device_model}" "${i_gpu_device_vendor}" "${i_gpu_device_location}" \
"${i_gpu_device_revision:2}" "${i_vm_domain_name}" "${i_gpu_attached}"
done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment