class_docstr: Takes care of collecting, sampling, serializing, and publishing a set of metrics.
class_docstr_tok: ["Takes","care","of","collecting",",","sampling",",","serializing",",","and","publishing","a","set","of","metrics","."]
docstr: Poll the Asset metrics.
docstr_tok: ["Poll","the","Asset","metrics","."]
code: def monitor(self) -> None:
      """Poll the Asset metrics."""
      while not self._shutdown_event.is_set():
          for _ in range(self.samples_to_aggregate):
              for metric in self.metrics:
                  try:
                      metric.sample()
                  except psutil.NoSuchProcess:
                      logger.info(f"Process {metric.name} has exited.")
                      self._shutdown_event.set()
                      break
                  except Exception as e:
                      logger.error(f"Failed to sample metric: {e}")
              self._shutdown_event.wait(self.sampling_interval)
              if self._shutdown_event.is_set():
                  break
          self.publish()
  
imports: import datetime
  import logging
  import sys
  import threading
  from typing import TYPE_CHECKING, Any, List, Optional, TypeVar
  import psutil
label_desc: Use image node_id 2 for calling the MetricsMonitor obj's underlying member method code with example usage: obj.monitor() without return types