mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51:03 +00:00
Use $(STATEMENT) instead of legacy STATEMENT
https://github.com/koalaman/shellcheck/wiki/SC2006
This commit is contained in:
parent
00c0da18d5
commit
2a84478fea
1 changed files with 20 additions and 20 deletions
|
@ -64,7 +64,7 @@ faken@fakenmc.com
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
# Determine name of parameter to monitor
|
# Determine name of parameter to monitor
|
||||||
name=`basename $0 | sed 's/^nvidia_gpu_//g'`
|
name=$(basename "$0" | sed 's/^nvidia_gpu_//g')
|
||||||
|
|
||||||
# Get location of nvidia-smi executable or use default
|
# Get location of nvidia-smi executable or use default
|
||||||
nvSmiExec=${smiexec:-'/usr/bin/nvidia-smi'}
|
nvSmiExec=${smiexec:-'/usr/bin/nvidia-smi'}
|
||||||
|
@ -91,8 +91,8 @@ if [ "$1" = "suggest" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get number of GPUs
|
# Get number of GPUs
|
||||||
nGpusOutput=`$nvSmiExec -L`
|
nGpusOutput=$($nvSmiExec -L)
|
||||||
nGpus=`echo "$nGpusOutput" | wc -l`
|
nGpus=$(echo "$nGpusOutput" | wc -l)
|
||||||
if [ $nGpus -eq 0 ]; then
|
if [ $nGpus -eq 0 ]; then
|
||||||
# Exit if no GPUs found
|
# Exit if no GPUs found
|
||||||
echo "No NVIDIA GPUs detected. Exiting."
|
echo "No NVIDIA GPUs detected. Exiting."
|
||||||
|
@ -100,13 +100,13 @@ if [ $nGpus -eq 0 ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get full output from nvidia-smi
|
# Get full output from nvidia-smi
|
||||||
smiOutput=`$nvSmiExec -q`
|
smiOutput=$($nvSmiExec -q)
|
||||||
|
|
||||||
# Check if config was requested
|
# Check if config was requested
|
||||||
if [ "$1" = "config" ]; then
|
if [ "$1" = "config" ]; then
|
||||||
|
|
||||||
# Get driver version
|
# Get driver version
|
||||||
driverVersion=`nvidia-smi -q | grep "Driver Version" | cut -d : -f 2 | tr -d ' '`
|
driverVersion=$(nvidia-smi -q | grep "Driver Version" | cut -d : -f 2 | tr -d ' ')
|
||||||
|
|
||||||
# Configure graph depending on what which quantity will be plotted
|
# Configure graph depending on what which quantity will be plotted
|
||||||
case $name in
|
case $name in
|
||||||
|
@ -119,7 +119,7 @@ if [ "$1" = "config" ]; then
|
||||||
nGpusCounter=0
|
nGpusCounter=0
|
||||||
while [ $nGpusCounter -lt $nGpus ]
|
while [ $nGpusCounter -lt $nGpus ]
|
||||||
do
|
do
|
||||||
gpuName=`echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1`
|
gpuName=$(echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1)
|
||||||
echo "temp${nGpusCounter}.warning ${warning:-75}"
|
echo "temp${nGpusCounter}.warning ${warning:-75}"
|
||||||
echo "temp${nGpusCounter}.critical ${critical:-95}"
|
echo "temp${nGpusCounter}.critical ${critical:-95}"
|
||||||
echo "temp${nGpusCounter}.info Temperature information for $gpuName"
|
echo "temp${nGpusCounter}.info Temperature information for $gpuName"
|
||||||
|
@ -128,14 +128,14 @@ if [ "$1" = "config" ]; then
|
||||||
;;
|
;;
|
||||||
mem)
|
mem)
|
||||||
# First determine total memory of each GPU...
|
# First determine total memory of each GPU...
|
||||||
gpusTotalMemOutput=`echo "$smiOutput" | grep -v BAR1 | grep -A 3 "Memory Usage" | grep "Total" | cut -d : -f 2 | tr -d ' '`
|
gpusTotalMemOutput=$(echo "$smiOutput" | grep -v BAR1 | grep -A 3 "Memory Usage" | grep "Total" | cut -d : -f 2 | tr -d ' ')
|
||||||
gpusTotalMem=''
|
gpusTotalMem=''
|
||||||
nGpusCounter=0
|
nGpusCounter=0
|
||||||
while [ $nGpusCounter -lt $nGpus ]
|
while [ $nGpusCounter -lt $nGpus ]
|
||||||
do
|
do
|
||||||
gpuName=`echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1`
|
gpuName=$(echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1)
|
||||||
echo "mem${nGpusCounter}.info Memory information for $gpuName"
|
echo "mem${nGpusCounter}.info Memory information for $gpuName"
|
||||||
gpuMem=`echo "$gpusTotalMemOutput"| sed -n $(( $nGpusCounter + 1 ))p`
|
gpuMem=$(echo "$gpusTotalMemOutput"| sed -n $(( $nGpusCounter + 1 ))p)
|
||||||
gpusTotalMem="${gpusTotalMem}${gpuMem} for GPU ${nGpusCounter}"
|
gpusTotalMem="${gpusTotalMem}${gpuMem} for GPU ${nGpusCounter}"
|
||||||
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
||||||
if [ $nGpusCounter -lt $nGpus ]; then
|
if [ $nGpusCounter -lt $nGpus ]; then
|
||||||
|
@ -158,7 +158,7 @@ if [ "$1" = "config" ]; then
|
||||||
nGpusCounter=0
|
nGpusCounter=0
|
||||||
while [ $nGpusCounter -lt $nGpus ]
|
while [ $nGpusCounter -lt $nGpus ]
|
||||||
do
|
do
|
||||||
gpuName=`echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1`
|
gpuName=$(echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1)
|
||||||
echo "fan${nGpusCounter}.info Fan information for $gpuName"
|
echo "fan${nGpusCounter}.info Fan information for $gpuName"
|
||||||
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
||||||
done
|
done
|
||||||
|
@ -171,7 +171,7 @@ if [ "$1" = "config" ]; then
|
||||||
nGpusCounter=0
|
nGpusCounter=0
|
||||||
while [ $nGpusCounter -lt $nGpus ]
|
while [ $nGpusCounter -lt $nGpus ]
|
||||||
do
|
do
|
||||||
gpuName=`echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1`
|
gpuName=$(echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1)
|
||||||
echo "power${nGpusCounter}.info power consumption of $gpuName"
|
echo "power${nGpusCounter}.info power consumption of $gpuName"
|
||||||
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
||||||
done
|
done
|
||||||
|
@ -187,7 +187,7 @@ if [ "$1" = "config" ]; then
|
||||||
nGpusCounter=0
|
nGpusCounter=0
|
||||||
while [ $nGpusCounter -lt $nGpus ]
|
while [ $nGpusCounter -lt $nGpus ]
|
||||||
do
|
do
|
||||||
gpuName=`echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1`
|
gpuName=$(echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1)
|
||||||
echo "${name}${nGpusCounter}.label $gpuName"
|
echo "${name}${nGpusCounter}.label $gpuName"
|
||||||
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
||||||
#print_warning $name
|
#print_warning $name
|
||||||
|
@ -200,27 +200,27 @@ fi
|
||||||
# Get requested value
|
# Get requested value
|
||||||
case $name in
|
case $name in
|
||||||
temp)
|
temp)
|
||||||
valueGpus=`echo "$smiOutput" | grep -A 1 "Temperature" | grep -i "Gpu" | cut -d : -f 2 | cut -d ' ' -f 2`
|
valueGpus=$(echo "$smiOutput" | grep -A 1 "Temperature" | grep -i "Gpu" | cut -d : -f 2 | cut -d ' ' -f 2)
|
||||||
;;
|
;;
|
||||||
mem)
|
mem)
|
||||||
totalMemGpus=`echo "$smiOutput" | grep -v BAR1 | grep -A 3 "Memory Usage" | grep "Total" | cut -d : -f 2 | cut -d ' ' -f 2`
|
totalMemGpus=$(echo "$smiOutput" | grep -v BAR1 | grep -A 3 "Memory Usage" | grep "Total" | cut -d : -f 2 | cut -d ' ' -f 2)
|
||||||
usedMemGpus=`echo "$smiOutput" | grep -v BAR1 | grep -A 3 "Memory Usage" | grep "Used" | cut -d : -f 2 | cut -d ' ' -f 2`
|
usedMemGpus=$(echo "$smiOutput" | grep -v BAR1 | grep -A 3 "Memory Usage" | grep "Used" | cut -d : -f 2 | cut -d ' ' -f 2)
|
||||||
valueGpus=''
|
valueGpus=''
|
||||||
nGpusCounter=0
|
nGpusCounter=0
|
||||||
while [ $nGpusCounter -lt $nGpus ]
|
while [ $nGpusCounter -lt $nGpus ]
|
||||||
do
|
do
|
||||||
totalMemGpu=`echo "$totalMemGpus" | sed -n $(( $nGpusCounter + 1 ))p`
|
totalMemGpu=$(echo "$totalMemGpus" | sed -n $(( $nGpusCounter + 1 ))p)
|
||||||
usedMemGpu=`echo "$usedMemGpus" | sed -n $(( $nGpusCounter + 1 ))p`
|
usedMemGpu=$(echo "$usedMemGpus" | sed -n $(( $nGpusCounter + 1 ))p)
|
||||||
percentMemUsed=$(( $usedMemGpu * 100 / $totalMemGpu ))
|
percentMemUsed=$(( $usedMemGpu * 100 / $totalMemGpu ))
|
||||||
valueGpus="${valueGpus}${percentMemUsed}"$'\n'
|
valueGpus="${valueGpus}${percentMemUsed}"$'\n'
|
||||||
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
fan)
|
fan)
|
||||||
valueGpus=`echo "$smiOutput" | grep "Fan Speed" | cut -d ':' -f 2 | cut -d ' ' -f 2`
|
valueGpus=$(echo "$smiOutput" | grep "Fan Speed" | cut -d ':' -f 2 | cut -d ' ' -f 2)
|
||||||
;;
|
;;
|
||||||
power)
|
power)
|
||||||
valueGpus=`echo "$smiOutput" | grep "Power Draw" | cut -d ':' -f 2 | cut -d ' ' -f 2`
|
valueGpus=$(echo "$smiOutput" | grep "Power Draw" | cut -d ':' -f 2 | cut -d ' ' -f 2)
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Can't run without a proper symlink. Exiting."
|
echo "Can't run without a proper symlink. Exiting."
|
||||||
|
@ -234,7 +234,7 @@ case $name in
|
||||||
nGpusCounter=0
|
nGpusCounter=0
|
||||||
while [ $nGpusCounter -lt $nGpus ]
|
while [ $nGpusCounter -lt $nGpus ]
|
||||||
do
|
do
|
||||||
value=`echo "$valueGpus" | sed -n $(( $nGpusCounter + 1 ))p`
|
value=$(echo "$valueGpus" | sed -n $(( $nGpusCounter + 1 ))p)
|
||||||
echo "${name}${nGpusCounter}.value $value"
|
echo "${name}${nGpusCounter}.value $value"
|
||||||
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
||||||
done
|
done
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue