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"]
docstr: Generate a list of Record class for worker proceses.
  
  This API automatically sets the component_name of record as
  the name of worker processes. I.e., ray::* so that we can report
  per task/actor (grouped by a func/class name) resource usages.
  
  Args:
      stats: a list of stats dict generated by `psutil.as_dict`
          for worker processes.
docstr_tok: ["Generate","a","list","of","Record","class","for","worker","proceses",".","This","API","automatically","sets","the","component_name","of","record","as","the","name","of","worker","processes",".","I.e.",",","ray",":",":","*","so","that","we","can","report","per","task\/actor","(","grouped","by","a","func\/class","name",")","resource","usages",".","Args",":","stats",":","a","list","of","stats","dict","generated","by","`","psutil.as_dict","`","for","worker","processes","."]
code: def generate_worker_stats_record(
      self, worker_stats: List[dict]
  ) -> List[Record]:
      """Generate a list of Record class for worker proceses.
  
      This API automatically sets the component_name of record as
      the name of worker processes. I.e., ray::* so that we can report
      per task/actor (grouped by a func/class name) resource usages.
  
      Args:
          stats: a list of stats dict generated by `psutil.as_dict`
              for worker processes.
      """
      # worekr cmd name (ray::*) -> stats dict.
      proc_name_to_stats = defaultdict(list)
      for stat in worker_stats:
          cmdline = stat.get("cmdline")
          # All ray processes start with ray::
          if (
              cmdline
              and len(cmdline) > 0
              and cmdline[0].startswith("ray::")
          ):
              proc_name = cmdline[0]
              proc_name_to_stats[proc_name].append(stat)
          # We will lose worker stats that don't follow the ray worker proc
          # naming convention. Theoretically, there should be no data loss here
          # because all worker processes are renamed to ray::.
  
      records = []
      for proc_name, stats in proc_name_to_stats.items():
          records.extend(
              self._generate_system_stats_record(stats, proc_name)
          )
  
      # Reset worker metrics that are from finished processes.
      new_proc_names = set(proc_name_to_stats.keys())
      stale_procs = self._latest_worker_proc_names - new_proc_names
      self._latest_worker_proc_names = new_proc_names
  
      for stale_proc_name in stale_procs:
          records.extend(
              self._generate_reseted_stats_record(stale_proc_name)
          )
  
      return records
  
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 21 for calling the ReporterAgent obj's underlying member method code with example usage: obj.generate_worker_stats_record(worker_stats) and returns: records