class_docstr: A monitor process for monitoring Ray nodes.
  
  Attributes:
      dashboard_agent: The DashboardAgent object contains global config
class_docstr_tok: ["A","monitor","process","for","monitoring","Ray","nodes",".","Attributes",":","dashboard_agent",":","The","DashboardAgent","object","contains","global","config"]
code: def _get_gpu_usage():
      import ray._private.thirdparty.pynvml as pynvml
  
      global enable_gpu_usage_check
      if not enable_gpu_usage_check:
          return []
      gpu_utilizations = []
  
      def decode(b: Union[str, bytes]) -> str:
          if isinstance(b, bytes):
              return b.decode("utf-8")  # for python3, to unicode
          return b
  
      try:
          pynvml.nvmlInit()
      except Exception as e:
          logger.debug(
              f"pynvml failed to retrieve GPU information: {e}"
          )
  
          # On machines without GPUs, pynvml.nvmlInit() can run subprocesses that
          # spew to stderr. Then with log_to_driver=True, we get log spew from every
          # single raylet. To avoid this, disable the GPU usage check on
          # certain errors.
          # https://github.com/ray-project/ray/issues/14305
          # https://github.com/ray-project/ray/pull/21686
          if type(e).__name__ == "NVMLError_DriverNotLoaded":
              enable_gpu_usage_check = False
          return gpu_utilizations
  
      num_gpus = pynvml.nvmlDeviceGetCount()
      for i in range(num_gpus):
          gpu_handle = pynvml.nvmlDeviceGetHandleByIndex(i)
          memory_info = pynvml.nvmlDeviceGetMemoryInfo(gpu_handle)
          utilization = None
          try:
              utilization_info = pynvml.nvmlDeviceGetUtilizationRates(
                  gpu_handle
              )
              utilization = int(utilization_info.gpu)
          except pynvml.NVMLError as e:
              logger.debug(
                  f"pynvml failed to retrieve GPU utilization: {e}"
              )
  
          # processes pids
          processes_pids = None
          try:
              nv_comp_processes = (
                  pynvml.nvmlDeviceGetComputeRunningProcesses(
                      gpu_handle
                  )
              )
              nv_graphics_processes = (
                  pynvml.nvmlDeviceGetGraphicsRunningProcesses(
                      gpu_handle
                  )
              )
              processes_pids = [
                  ProcessGPUInfo(
                      pid=int(nv_process.pid),
                      gpu_memory_usage=int(nv_process.usedGpuMemory)
                      // MB
                      if nv_process.usedGpuMemory
                      else 0,
                  )
                  for nv_process in (
                      nv_comp_processes + nv_graphics_processes
                  )
              ]
          except pynvml.NVMLError as e:
              logger.debug(
                  f"pynvml failed to retrieve GPU processes: {e}"
              )
  
          info = GpuUtilizationInfo(
              index=i,
              name=decode(pynvml.nvmlDeviceGetName(gpu_handle)),
              uuid=decode(pynvml.nvmlDeviceGetUUID(gpu_handle)),
              utilization_gpu=utilization,
              memory_used=int(memory_info.used) // MB,
              memory_total=int(memory_info.total) // MB,
              processes_pids=processes_pids,
          )
          gpu_utilizations.append(info)
      pynvml.nvmlShutdown()
  
      return gpu_utilizations
  
imports: import asyncio
  import datetime
  import json
  import logging
  import os
  import socket
  import sys
  import traceback
  import psutil
  from typing import List, Optional, Tuple, TypedDict, Union
  from collections import defaultdict
  import ray
  import ray._private.services
  import ray._private.utils
  from ray.dashboard.consts import GCS_RPC_TIMEOUT_SECONDS, COMPONENT_METRICS_TAG_KEYS
  from ray.dashboard.modules.reporter.profile_manager import CpuProfilingManager, MemoryProfilingManager
  import ray.dashboard.modules.reporter.reporter_consts
  import ray.dashboard.utils
  from opencensus.stats import stats
  import ray._private.prometheus_exporter
  from prometheus_client.core import REGISTRY
  from ray._private.metrics_agent import Gauge, MetricsAgent, Record
  from ray._private.ray_constants import DEBUG_AUTOSCALING_STATUS
  from ray.core.generated import reporter_pb2, reporter_pb2_grpc
  from ray.dashboard import k8s_utils
  from ray._raylet import WorkerID
label_desc: Use image node_id 3 for calling the ReporterAgent obj's underlying member method code with example usage: obj._get_gpu_usage() and returns: gpu_utilizations, list, b, b, gpu_utilizations