Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / gpu / nvidia_gpu_ @ 3c481585

Historique | Voir | Annoter | Télécharger (7,24 ko)

1
#!/bin/bash
2
# -*- sh -*-
3

    
4
: << =cut
5

    
6
=head1 NAME
7

    
8
nvidia_gpu_ - Wildcard plugin to monitor NVIDIA GPUs. Uses nvidia-smi utility,
9
usually bundled with NVIDIA GPU driver, to obtain information.
10

    
11
=head1 CONFIGURATION
12

    
13
This is a wildcard plugin. The wildcard prefix link name should be the
14
value to monitor.
15

    
16
This plugin uses the following configuration variables:
17

    
18
 [nvidia_gpu_*]
19
  env.smiexec - Location of nvidia-smi executable.
20
  env.warning - Warning temperature
21
  env.critical - Critical temperature
22

    
23
=head2 DEFAULT CONFIGURATION
24

    
25
The default configuration is to set "env.smiexec" to /usr/bin/nvidia-smi and
26
assume warning and critical temperatures of 75 and 95 degrees celsius, respectively.
27

    
28
=head2 EXAMPLE WILDCARD USAGE
29

    
30
C<ln -s /usr/share/munin/plugins/nvidia_gpu_ /etc/munin/plugins/nvidia_gpu_temp>
31

    
32
...will monitor the temperature of available GPUs.
33

    
34
=head1 TODO
35

    
36
=over 4
37

    
38
=item *
39

    
40
Add support for specific professional GPU features such as number of compute processes, clocks and so on.
41

    
42
=item *
43

    
44
Use multigraphs for multiple GPUs (http://munin-monitoring.org/wiki/MultigraphSampleOutput).
45

    
46
=back
47

    
48
=head1 AUTHOR
49

    
50
Nuno Fachada
51
faken@fakenmc.com
52

    
53
=head1 LICENSE
54

    
55
 GNU General Public License, version 2
56
 http://www.gnu.org/licenses/gpl-2.0.html
57

    
58
=head1 MAGIC MARKERS
59

    
60
 #%# family=auto
61
 #%# capabilities=autoconf suggest
62

    
63
=cut
64

    
65
# Determine name of parameter to monitor
66
name=$(basename "$0" | sed 's/^nvidia_gpu_//g')
67

    
68
# Get location of nvidia-smi executable or use default
69
nvSmiExec=${smiexec:-'/usr/bin/nvidia-smi'}
70

    
71
# Check if autoconf was requested
72
if [ "$1" = "autoconf" ]; then
73
	# Autoconf only returns yes if nvidia-smi exists and is executable
74
	if [ -x "$nvSmiExec" ]; then
75
		echo yes
76
		exit 0
77
	else
78
		echo "no (nvidia-smi executable not found)"
79
		exit 0
80
	fi
81
fi
82

    
83
# Check if suggest was requested
84
if [ "$1" = "suggest" ]; then
85
	echo "temp"
86
	echo "mem"
87
	echo "fan"
88
	echo "power"
89
	echo "utilization"
90
	exit 0
91
fi
92

    
93
# Get number of GPUs
94
nGpusOutput=$("$nvSmiExec" -L)
95
nGpus=$(echo "$nGpusOutput" | wc -l)
96
if [ "$nGpus" -eq 0 ]; then
97
	# Exit if no GPUs found
98
	echo "No NVIDIA GPUs detected. Exiting."
99
	exit 1
100
fi
101

    
102
# Get full output from nvidia-smi
103
smiOutput=$("$nvSmiExec" -q)
104

    
105
# Check if config was requested
106
if [ "$1" = "config" ]; then
107

    
108
	# Get driver version
109
	driverVersion=$(echo "$smiOutput" | grep "Driver Version" | cut -d : -f 2 | tr -d ' ')
110

    
111
	# Configure graph depending on what which quantity will be plotted
112
	case $name in
113
		temp)
114
			echo 'graph_title GPU temperature'
115
			echo 'graph_args -l 0 -u 120'
116
			echo 'graph_vlabel degrees Celsius'
117
			echo 'graph_category sensors'
118
			echo "graph_info Temperature information for NVIDIA GPUs using driver version $driverVersion"
119
			nGpusCounter=0
120
			while [ $nGpusCounter -lt "$nGpus" ]
121
			do
122
				gpuName=$(echo "$nGpusOutput" | sed -n $((nGpusCounter+1))p | cut -d \( -f 1)
123
				echo "${name}${nGpusCounter}.warning ${warning:-75}"
124
				echo "${name}${nGpusCounter}.critical ${critical:-95}"
125
				echo "${name}${nGpusCounter}.info Temperature information for $gpuName"
126
				: $((nGpusCounter=nGpusCounter+1))
127
			done
128
			;;
129
		mem)
130
			# First determine total memory of each GPU...
131
			gpusTotalMemOutput=$(echo "$smiOutput" | grep -v BAR1 | grep -A 3 "Memory Usage" | grep "Total" | cut -d : -f 2 | tr -d ' ')
132
			gpusTotalMem=''
133
			nGpusCounter=0
134
			while [ $nGpusCounter -lt "$nGpus" ]
135
			do
136
				gpuName=$(echo "$nGpusOutput" | sed -n $((nGpusCounter+1))p | cut -d \( -f 1)
137
				echo "${name}${nGpusCounter}.info Memory information for $gpuName"
138
				gpuMem=$(echo "$gpusTotalMemOutput"| sed -n $((nGpusCounter+1))p)
139
				gpusTotalMem="${gpusTotalMem}${gpuMem} for GPU ${nGpusCounter}"
140
				: $((nGpusCounter=nGpusCounter+1))
141
				if [ "$nGpusCounter" -lt "$nGpus" ]; then
142
					gpusTotalMem="${gpusTotalMem}, "
143
				fi
144
			done
145
			# ...then output config data.
146
			echo 'graph_title GPU memory usage'
147
			echo 'graph_args -l 0 -u 100'
148
			echo 'graph_vlabel %'
149
			echo 'graph_category memory'
150
			echo "graph_info FB Memory usage for NVIDIA GPUs using driver version $driverVersion (total memory is $gpusTotalMem)"
151
			;;
152
		fan)
153
			echo 'graph_title GPU fan speed'
154
			echo 'graph_args -l 0 -u 100'
155
			echo 'graph_vlabel %'
156
			echo 'graph_category sensors'
157
			echo "graph_info Fan speed of NVIDIA GPUs using driver version $driverVersion"
158
			nGpusCounter=0
159
			while [ $nGpusCounter -lt "$nGpus" ]
160
			do
161
				gpuName=$(echo "$nGpusOutput" | sed -n $((nGpusCounter+1))p | cut -d \( -f 1)
162
				echo "${name}${nGpusCounter}.info Fan information for $gpuName"
163
				: $((nGpusCounter=nGpusCounter+1))
164
				done
165
			;;
166
		power)
167
			echo 'graph_title GPU power consumption'
168
			echo 'graph_vlabel Watt'
169
			echo 'graph_category sensors'
170
			echo "graph_info power consumption of NVIDIA GPUs using driver version $driverVersion"
171
			nGpusCounter=0
172
			while [ $nGpusCounter -lt "$nGpus" ]
173
			do
174
				gpuName=$(echo "$nGpusOutput" | sed -n $((nGpusCounter+1))p | cut -d \( -f 1)
175
				echo "${name}${nGpusCounter}.info power consumption of $gpuName"
176
				: $((nGpusCounter=nGpusCounter+1))
177
				done
178
			;;
179
		utilization)
180
			echo 'graph_title GPU utilization'
181
			echo 'graph_args -l 0 -u 100'
182
			echo 'graph_vlabel %'
183
			echo 'graph_category system'
184
			echo "graph_info GPU utilization of NVIDIA GPUs using driver version $driverVersion"
185
			nGpusCounter=0
186
			while [ $nGpusCounter -lt "$nGpus" ]
187
			do
188
				gpuName=$(echo "$nGpusOutput" | sed -n $((nGpusCounter+1))p | cut -d \( -f 1)
189
				echo "${name}${nGpusCounter}.info GPU utilization information for $gpuName"
190
				: $((nGpusCounter=nGpusCounter+1))
191
				done
192
			;;
193
		*)
194
			echo "Can't run without a proper symlink. Exiting."
195
			echo "Try running munin-node-configure --suggest."
196
			exit 1
197
			;;
198
	esac
199

    
200
	# Common stuff for all quantities
201
	nGpusCounter=0
202
	while [ $nGpusCounter -lt "$nGpus" ]
203
	do
204
		gpuName=$(echo "$nGpusOutput" | sed -n $((nGpusCounter+1))p | cut -d \( -f 1)
205
		echo "${name}${nGpusCounter}.label $gpuName"
206
		: $((nGpusCounter=nGpusCounter+1))
207
		#print_warning $name
208
		#print_critical $name
209
	done
210

    
211
	exit 0
212
fi
213

    
214
# Get requested value
215
case $name in
216
	temp)
217
		valueGpus=$(echo "$smiOutput" | grep "GPU Current Temp" | cut -d : -f 2 | cut -d ' ' -f 2)
218
		;;
219
	mem)
220
		totalMemGpus=$(echo "$smiOutput" | grep -v BAR1 | grep -A 3 "Memory Usage" | grep "Total" | cut -d : -f 2 | cut -d ' ' -f 2)
221
		usedMemGpus=$(echo "$smiOutput" | grep -v BAR1 | grep -A 3 "Memory Usage" | grep "Used" | cut -d : -f 2 | cut -d ' ' -f 2)
222
		valueGpus=''
223
		nGpusCounter=0
224
		while [ $nGpusCounter -lt "$nGpus" ]
225
		do
226
			totalMemGpu=$(echo "$totalMemGpus" | sed -n $((nGpusCounter+1))p)
227
			usedMemGpu=$(echo "$usedMemGpus" | sed -n $((nGpusCounter+1))p)
228
			percentMemUsed=$((usedMemGpu*100/totalMemGpu))
229
			valueGpus="${valueGpus}${percentMemUsed}"$'\n'
230
			: $((nGpusCounter=nGpusCounter+1))
231
		done
232
		;;
233
	fan)
234
		valueGpus=$(echo "$smiOutput" | grep "Fan Speed" | cut -d ':' -f 2 | cut -d ' ' -f 2)
235
		;;
236
	power)
237
		valueGpus=$(echo "$smiOutput" | grep "Power Draw" | cut -d ':' -f 2 | cut -d ' ' -f 2)
238
		;;
239
	utilization)
240
		valueGpus=$(echo "$smiOutput" | grep "Gpu" | cut -d ':' -f 2 | cut -d ' ' -f 2)
241
		;;
242
	*)
243
		echo "Can't run without a proper symlink. Exiting."
244
		echo "Try running munin-node-configure --suggest."
245
		exit 1
246
		;;
247
	esac
248

    
249

    
250
# Print requested value
251
nGpusCounter=0
252
while [ $nGpusCounter -lt "$nGpus" ]
253
do
254
	value=$(echo "$valueGpus" | sed -n $((nGpusCounter+1))p)
255
	echo "${name}${nGpusCounter}.value $value"
256
	: $((nGpusCounter=nGpusCounter+1))
257
done