code: def gpu_utilization(num_of_gpu):
      """
      Collect gpu metrics.
  
      :param num_of_gpu:
      :return:
      """
      if num_of_gpu <= 0:
          return
  
      # pylint: disable=wrong-import-position
      # pylint: disable=import-outside-toplevel
      import nvgpu
      import pynvml
      from nvgpu import list_gpus
  
      # pylint: enable=wrong-import-position
      # pylint: enable=import-outside-toplevel
  
      info = nvgpu.gpu_info()
      for value in info:
          dimension_gpu = [
              Dimension("Level", "Host"),
              Dimension("device_id", value["index"]),
          ]
          system_metrics.append(
              Metric(
                  "GPUMemoryUtilization",
                  value["mem_used_percent"],
                  "percent",
                  dimension_gpu,
              )
          )
          system_metrics.append(
              Metric(
                  "GPUMemoryUsed",
                  value["mem_used"],
                  "MB",
                  dimension_gpu,
              )
          )
  
      try:
          statuses = list_gpus.device_statuses()
      except pynvml.nvml.NVMLError_NotSupported:
          logging.error("gpu device monitoring not supported")
          statuses = []
  
      for idx, status in enumerate(statuses):
          dimension_gpu = [
              Dimension("Level", "Host"),
              Dimension("device_id", idx),
          ]
          system_metrics.append(
              Metric(
                  "GPUUtilization",
                  status["utilization"],
                  "percent",
                  dimension_gpu,
              )
          )
  
file_path: serve/ts/metrics/system_metrics.py
imports: import logging
  import types
  from builtins import str
  import psutil
  from ts.metrics.dimension import Dimension
  from ts.metrics.metric import Metric
label_desc: Use image node_id 8 for calling a global function with example usage: gpu_utilization(num_of_gpu) without return types