diff --git a/plugins/gpu/nvidia_gpu_by_user b/plugins/gpu/nvidia_gpu_by_user new file mode 100755 index 000000000..41dc8a627 --- /dev/null +++ b/plugins/gpu/nvidia_gpu_by_user @@ -0,0 +1,253 @@ +#!/bin/sh +# -*- sh -*- + +: </dev/null | cut -d\" \" -f 2 | sed -e \"s/^[^A-Za-z_]/_/\" -e \"s/[^A-Za-z0-9_]/_/g\" | tr \"\n\" \" \" | tr -d \" \"" | getline tmpid + if (tmpid == "") tmpid = "other"; + m = getUserIdxInGpu(n, tmpid); + gpu["user", n, m] = tmpid; +} + +$0 ~ "^Used GPU Memory" { + split ($2, tmp, " "); + if (gpu["used", n, m] == "") gpu["used", n, m] = tmp[1]; + else gpu["used", n, m] += tmp[1]; +} + +END { + if (n < 0) { + + print "No NVIDIA GPUs detected. Exiting." > stderr; + exit 1; + + } + + # add other 0% if not exists (for displaying graph) + split (gpuUsers, gu_array, " "); + gu_idx = 1; + while (gu_array[gu_idx] != "") { + gu = gu_array[gu_idx]; + for (i=0; i<=n; i++) { + j = getUserIdxInGpu(i, gu); + if (j == getUserCountInGpu(i)) { + gpu["user", i, j] = gu; + gpu["used", i, j] = "0"; + } + } + gu_idx++; + } + + if (arg == "config") { + # print graph summary + + print "multigraph gpu_multigraph" + print "graph_title GPU memory usage by user" + print "graph_args --base 1000 -r --lower-limit 0" + print "graph_category gpu_by_user" + print "graph_info This graph shows GPU memory usage, for monitored users." + print "graph_vlabel %" + print "graph_period second" + + if (order == 1) { + printf "graph_order" + for (i=0; i<=n; i++) { + gu_idx = 1; + while (gu_array[gu_idx] != "") { + gu = gu_array[gu_idx]; + printf (" gpu%s_%s", i, gu); + gu_idx++; + } + } + print "" + } + + for (i=0; i<=n; i++) { + m = getUserCountInGpu(i); + for (j=0; j