2014-10-04 21:21:32 +02:00
|
|
|
#!/bin/bash
|
2012-12-11 20:57:06 +01:00
|
|
|
# -*- sh -*-
|
|
|
|
|
|
|
|
: << =cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
nvidia_gpu_ - Wildcard plugin to monitor NVIDIA GPUs. Uses nvidia-smi utility,
|
|
|
|
usually bundled with NVIDIA GPU driver, to obtain information.
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
This is a wildcard plugin. The wildcard prefix link name should be the
|
|
|
|
value to monitor.
|
|
|
|
|
|
|
|
This plugin uses the following configuration variables:
|
|
|
|
|
|
|
|
[nvidia_gpu_*]
|
|
|
|
env.smiexec - Location of nvidia-smi executable.
|
2013-11-12 12:29:12 +01:00
|
|
|
env.warning - Warning temperature
|
|
|
|
env.critical - Critical temperature
|
2012-12-11 20:57:06 +01:00
|
|
|
|
|
|
|
=head2 DEFAULT CONFIGURATION
|
|
|
|
|
2013-11-12 14:47:45 +01:00
|
|
|
The default configuration is to set "env.smiexec" to /usr/bin/nvidia-smi and
|
|
|
|
assume warning and critical temperatures of 75 and 95 degrees celsius, respectively.
|
2012-12-11 20:57:06 +01:00
|
|
|
|
|
|
|
=head2 EXAMPLE WILDCARD USAGE
|
|
|
|
|
|
|
|
C<ln -s /usr/share/munin/plugins/nvidia_gpu_ /etc/munin/plugins/nvidia_gpu_temp>
|
|
|
|
|
|
|
|
...will monitor the temperature of available GPUs.
|
|
|
|
|
2013-11-12 14:47:45 +01:00
|
|
|
=head1 TODO
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
Add support for specific professional GPU features such as number of compute
|
|
|
|
processes, clocks, power draw, utilization, and so on.
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
Use multigraphs for multiple GPUs (http://munin-monitoring.org/wiki/MultigraphSampleOutput).
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
2012-12-11 20:57:06 +01:00
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Nuno Fachada
|
|
|
|
faken@fakenmc.com
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
GNU General Public License, version 2
|
|
|
|
http://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
|
|
|
|
=head1 MAGIC MARKERS
|
|
|
|
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf suggest
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
# Determine name of parameter to monitor
|
|
|
|
name=`basename $0 | sed 's/^nvidia_gpu_//g'`
|
|
|
|
|
|
|
|
# Get location of nvidia-smi executable or use default
|
|
|
|
nvSmiExec=${smiexec:-'/usr/bin/nvidia-smi'}
|
|
|
|
|
|
|
|
# Check if autoconf was requested
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
|
|
|
# Autoconf only returns yes if nvidia-smi exists and is executable
|
|
|
|
if [ -x $nvSmiExec ]; then
|
|
|
|
echo yes
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "no (nvidia-smi executable not found)"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if suggest was requested
|
|
|
|
if [ "$1" = "suggest" ]; then
|
|
|
|
echo "temp"
|
|
|
|
echo "mem"
|
|
|
|
echo "fan"
|
2017-04-18 18:32:03 +02:00
|
|
|
echo "power"
|
2012-12-11 20:57:06 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get number of GPUs
|
|
|
|
nGpusOutput=`$nvSmiExec -L`
|
|
|
|
nGpus=`echo "$nGpusOutput" | wc -l`
|
|
|
|
if [ $nGpus -eq 0 ]; then
|
|
|
|
# Exit if no GPUs found
|
|
|
|
echo "No NVIDIA GPUs detected. Exiting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get full output from nvidia-smi
|
|
|
|
smiOutput=`$nvSmiExec -q`
|
|
|
|
|
|
|
|
# Check if config was requested
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
|
|
|
|
# Get driver version
|
|
|
|
driverVersion=`nvidia-smi -q | grep "Driver Version" | cut -d : -f 2 | tr -d ' '`
|
|
|
|
|
|
|
|
# Configure graph depending on what which quantity will be plotted
|
|
|
|
case $name in
|
|
|
|
temp)
|
|
|
|
echo 'graph_title GPU temperature'
|
|
|
|
echo 'graph_args -l 0 -u 120'
|
|
|
|
echo 'graph_vlabel Degrees (C)'
|
2017-02-22 05:34:14 +01:00
|
|
|
echo 'graph_category sensors'
|
2012-12-11 20:57:06 +01:00
|
|
|
echo "graph_info Temperature information for NVIDIA GPUs using driver version $driverVersion"
|
|
|
|
nGpusCounter=0
|
|
|
|
while [ $nGpusCounter -lt $nGpus ]
|
|
|
|
do
|
|
|
|
gpuName=`echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1`
|
2013-11-12 12:29:12 +01:00
|
|
|
echo "temp${nGpusCounter}.warning ${warning:-75}"
|
|
|
|
echo "temp${nGpusCounter}.critical ${critical:-95}"
|
2012-12-11 20:57:06 +01:00
|
|
|
echo "temp${nGpusCounter}.info Temperature information for $gpuName"
|
|
|
|
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
mem)
|
|
|
|
# First determine total memory of each GPU...
|
2014-09-16 01:14:57 +02:00
|
|
|
gpusTotalMemOutput=`echo "$smiOutput" | grep -v BAR1 | grep -A 3 "Memory Usage" | grep "Total" | cut -d : -f 2 | tr -d ' '`
|
2012-12-11 20:57:06 +01:00
|
|
|
gpusTotalMem=''
|
|
|
|
nGpusCounter=0
|
|
|
|
while [ $nGpusCounter -lt $nGpus ]
|
|
|
|
do
|
|
|
|
gpuName=`echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1`
|
|
|
|
echo "mem${nGpusCounter}.info Memory information for $gpuName"
|
|
|
|
gpuMem=`echo "$gpusTotalMemOutput"| sed -n $(( $nGpusCounter + 1 ))p`
|
|
|
|
gpusTotalMem="${gpusTotalMem}${gpuMem} for GPU ${nGpusCounter}"
|
|
|
|
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
|
|
|
if [ $nGpusCounter -lt $nGpus ]; then
|
|
|
|
gpusTotalMem="${gpusTotalMem}, "
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# ...then output config data.
|
|
|
|
echo 'graph_title GPU memory usage'
|
|
|
|
echo 'graph_args -l 0 -u 100'
|
|
|
|
echo 'graph_vlabel Percentage'
|
2017-02-22 05:34:14 +01:00
|
|
|
echo 'graph_category memory'
|
2014-05-04 18:46:40 +02:00
|
|
|
echo "graph_info FB Memory usage for NVIDIA GPUs using driver version $driverVersion (total memory is $gpusTotalMem)"
|
2012-12-11 20:57:06 +01:00
|
|
|
;;
|
|
|
|
fan)
|
|
|
|
echo 'graph_title GPU fan speed'
|
|
|
|
echo 'graph_args -l 0 -u 100'
|
|
|
|
echo 'graph_vlabel Percentage'
|
2017-02-22 05:34:14 +01:00
|
|
|
echo 'graph_category sensors'
|
2012-12-11 20:57:06 +01:00
|
|
|
echo "graph_info Fan speed of NVIDIA GPUs using driver version $driverVersion"
|
|
|
|
nGpusCounter=0
|
|
|
|
while [ $nGpusCounter -lt $nGpus ]
|
|
|
|
do
|
|
|
|
gpuName=`echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1`
|
|
|
|
echo "fan${nGpusCounter}.info Fan information for $gpuName"
|
|
|
|
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
|
|
|
done
|
|
|
|
;;
|
2017-04-18 18:32:03 +02:00
|
|
|
power)
|
|
|
|
echo 'graph_title GPU power consumption'
|
|
|
|
echo 'graph_vlabel Watt'
|
|
|
|
echo 'graph_category sensors'
|
|
|
|
echo "graph_info power consumption of NVIDIA GPUs using driver version $driverVersion"
|
|
|
|
nGpusCounter=0
|
|
|
|
while [ $nGpusCounter -lt $nGpus ]
|
|
|
|
do
|
|
|
|
gpuName=`echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1`
|
|
|
|
echo "power${nGpusCounter}.info power consumption of $gpuName"
|
|
|
|
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
|
|
|
done
|
|
|
|
;;
|
2012-12-11 20:57:06 +01:00
|
|
|
*)
|
|
|
|
echo "Can't run without a proper symlink. Exiting."
|
|
|
|
echo "Try running munin-node-configure --suggest."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Common stuff for all quantities
|
|
|
|
nGpusCounter=0
|
|
|
|
while [ $nGpusCounter -lt $nGpus ]
|
|
|
|
do
|
|
|
|
gpuName=`echo "$nGpusOutput" | sed -n $(( $nGpusCounter + 1 ))p | cut -d \( -f 1`
|
|
|
|
echo "${name}${nGpusCounter}.label $gpuName"
|
|
|
|
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
|
|
|
#print_warning $name
|
|
|
|
#print_critical $name
|
|
|
|
done
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get requested value
|
|
|
|
case $name in
|
|
|
|
temp)
|
2014-09-15 23:35:15 +02:00
|
|
|
valueGpus=`echo "$smiOutput" | grep -A 1 "Temperature" | grep -i "Gpu" | cut -d : -f 2 | cut -d ' ' -f 2`
|
2012-12-11 20:57:06 +01:00
|
|
|
;;
|
|
|
|
mem)
|
2014-09-16 01:14:57 +02:00
|
|
|
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`
|
2012-12-11 20:57:06 +01:00
|
|
|
valueGpus=''
|
|
|
|
nGpusCounter=0
|
|
|
|
while [ $nGpusCounter -lt $nGpus ]
|
|
|
|
do
|
|
|
|
totalMemGpu=`echo "$totalMemGpus" | sed -n $(( $nGpusCounter + 1 ))p`
|
|
|
|
usedMemGpu=`echo "$usedMemGpus" | sed -n $(( $nGpusCounter + 1 ))p`
|
|
|
|
percentMemUsed=$(( $usedMemGpu * 100 / $totalMemGpu ))
|
2015-01-14 03:16:57 +01:00
|
|
|
valueGpus="${valueGpus}${percentMemUsed}"$'\n'
|
2012-12-11 20:57:06 +01:00
|
|
|
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
fan)
|
|
|
|
valueGpus=`echo "$smiOutput" | grep "Fan Speed" | cut -d ':' -f 2 | cut -d ' ' -f 2`
|
|
|
|
;;
|
2017-04-18 18:32:03 +02:00
|
|
|
power)
|
|
|
|
valueGpus=`echo "$smiOutput" | grep "Power Draw" | cut -d ':' -f 2 | cut -d ' ' -f 2`
|
|
|
|
;;
|
2012-12-11 20:57:06 +01:00
|
|
|
*)
|
|
|
|
echo "Can't run without a proper symlink. Exiting."
|
|
|
|
echo "Try running munin-node-configure --suggest."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
|
|
# Print requested value
|
|
|
|
nGpusCounter=0
|
|
|
|
while [ $nGpusCounter -lt $nGpus ]
|
|
|
|
do
|
|
|
|
value=`echo "$valueGpus" | sed -n $(( $nGpusCounter + 1 ))p`
|
|
|
|
echo "${name}${nGpusCounter}.value $value"
|
|
|
|
: $(( nGpusCounter = $nGpusCounter + 1 ))
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|