Skip to content

Commit

Permalink
Switched to PCIE bus ids to identify cards + small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptopoo committed Mar 31, 2022
1 parent 98171b5 commit 25449bc
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions opt/gddr6x_temps/gddr6x_temps
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,23 @@ LOLMINER_API_URL="http://127.0.0.1:44444/summary"

function init() {
nvidia_indexes_array=$(cat "${GPU_STATS_JSON}" 2>/dev/null | jq -c '[ .brand | to_entries[] | select(.value == "nvidia") | .key ]')
gpus_indexes_array=$(cat "${GPU_STATS_JSON}" 2>/dev/null | jq -c '[ .brand | to_entries[] | select(.value != "cpu") | .key ]')
bus_indexes_array=$(cat "${GPU_STATS_JSON}" 2>/dev/null | jq -c '.busids')
if [ "${nvidia_indexes_array}" == "" ] || [ "${nvidia_indexes_array}" == "[]" ]; then
exit 1
fi
}

function process_stats() {
local stats="$1"
local gpus_array="$2"

if [ "${stats}" == "" ] || [ "${gpus_array}" == "" ]; then
if [ "${stats}" == "" ]; then
return 1
fi

for x in ${stats}; do
local k=$(echo ${gpus_array} | jq -c ".[${x%%,*}]")
local k=$(echo ${bus_indexes_array} | jq -c "index(\"${x%%,*}\")")
local v=${x#*,}
if [ "${k}" != "null" ] && [ -n "${k}" ]; then
if [ -n "${k}" ] && [ -n "${v}" ] && [ "${v}" != "0" ]; then
local temp=$(jq -ceM ".[${k}] = \"${v}\"" <<< "${MEMORY_TEMPS}")

if [ $? -eq 0 ]; then
Expand All @@ -45,21 +44,21 @@ function process_stats() {
}

function process_gminer_api() {
local stats=$(curl -s "${GMINER_API_URL}" | jq -c ' .devices| to_entries[] | select(.value.memory_temperature) | [(.value.gpu_id|tostring), (.value.memory_temperature|tostring)] | join(",")' | tr -d '"')
local stats=$(curl -m 1 -s "${GMINER_API_URL}" | jq -c ' .devices| to_entries[] | select(.value.memory_temperature) | [(.value.bus_id|capture("....:(?<busid>.*)").busid|tostring), (.value.memory_temperature|tostring)] | join(",")' | tr -d '"')

process_stats "${stats}" "${gpus_indexes_array}"
process_stats "${stats}"
}

function process_trex_api() {
local stats=$(curl -s "${TREX_API_URL}" | jq -c ' .gpus| to_entries[] | select(.value.memory_temperature) | [(.value.gpu_id|tostring), (.value.memory_temperature|tostring)] | join(",")' | tr -d '"')
local stats=$(curl -m 1 -s "${TREX_API_URL}" | jq -c ' .gpus| to_entries[] | select(.value.memory_temperature) | [(.value.pci_bus|tostring), (.value.memory_temperature|tostring)] | join(" ")' | tr -d '"' | xargs -n2 printf '%.2x:00.0,%d\n')

process_stats "${stats}" "${nvidia_indexes_array}"
process_stats "${stats}"
}

function process_lolminer_api() {
local stats=$(curl -s "${LOLMINER_API_URL}" | jq -c ' .Workers | to_entries[] | select(.value.Mem_Temp) | [(.value.Index|tostring), (.value.Mem_Temp|tostring)] | join(",")' | tr -d '"')
local stats=$(curl -m 1 -s "${LOLMINER_API_URL}" | jq -c ' .Workers | to_entries[] | select(.value.Mem_Temp) | [(.value.PCIE_Address|capture("(?<busid>.*):0").busid|tostring), (.value.Mem_Temp|tostring)] | join(" ")' | tr -d '"' | xargs -n2 printf '%.2x:00.0,%d\n')

process_stats "${stats}" "${gpus_indexes_array}"
process_stats "${stats}"
}

function patch_stats() {
Expand All @@ -76,7 +75,7 @@ function loop() {
MEMORY_TEMPS=$(cat "${GPU_STATS_JSON}" 2>/dev/null | jq -cM ' . | if has("mtemp") then .mtemp else (.temp | .[]=0) end')

# Tricking the agent so it will wait a bit more for us to be done, not really 3 seconds anyway ;)
touch -d "3 seconds ago" ${GPU_STATS_JSON}
touch -d "5 seconds ago" ${GPU_STATS_JSON}

if [ -s "${CUR_MINER}" ]; then
while read miner; do
Expand Down

0 comments on commit 25449bc

Please sign in to comment.