Skip to main content

An NVIDIA GPU monitoring plugin for the cjm-plugin-system that provides real-time hardware telemetry via nvitop.

Project description

cjm-system-monitor-nvidia

Install

pip install cjm_system_monitor_nvidia

Project Structure

nbs/
├── meta.ipynb   # Metadata introspection for the NVIDIA monitor plugin used by cjm-ctl to generate the registration manifest
└── plugin.ipynb # Plugin implementation for NVIDIA GPU monitoring using nvitop

Total: 2 notebooks

Module Dependencies

graph LR
    meta["meta<br/>meta"]
    plugin["plugin<br/>plugin"]

No cross-module dependencies detected.

CLI Reference

No CLI commands found in this project.

Module Overview

Detailed documentation for each module in the project:

meta (meta.ipynb)

Metadata introspection for the NVIDIA monitor plugin used by cjm-ctl to generate the registration manifest

Import

from cjm_system_monitor_nvidia.meta import (
    get_plugin_metadata
)

Functions

def get_plugin_metadata() -> Dict[str, Any]:  # Plugin metadata for manifest generation
    """Return metadata required to register this plugin with the PluginManager."""
    # Fallback base path (current behavior for backward compatibility)
    base_path = os.path.dirname(os.path.dirname(sys.executable))
    
    # Use CJM config if available, else fallback to env-relative paths
    cjm_plugin_data_dir = os.environ.get("CJM_PLUGIN_DATA_DIR")
    
    # Plugin data directory
    plugin_name = "cjm-system-monitor-nvidia"
    if cjm_plugin_data_dir
    "Return metadata required to register this plugin with the PluginManager."

plugin (plugin.ipynb)

Plugin implementation for NVIDIA GPU monitoring using nvitop

Import

from cjm_system_monitor_nvidia.plugin import (
    NvidiaMonitorPlugin
)

Classes

class NvidiaMonitorPlugin:
    def __init__(self):
        """Initialize the NVIDIA monitor plugin."""
        self.logger = logging.getLogger(f"{__name__}.{type(self).__name__}")
        self.config = {}

    @property
    def name(self) -> str:  # Tool identity, derived from the installed distribution (PILLAR 1c)
    "NVIDIA System Monitor using nvitop (a pure-telemetry ToolCapability)."
    
    def __init__(self):
            """Initialize the NVIDIA monitor plugin."""
            self.logger = logging.getLogger(f"{__name__}.{type(self).__name__}")
            self.config = {}
    
        @property
        def name(self) -> str:  # Tool identity, derived from the installed distribution (PILLAR 1c)
        "Initialize the NVIDIA monitor plugin."
    
    def name(self) -> str:  # Tool identity, derived from the installed distribution (PILLAR 1c)
            """Get the tool name (the installed distribution name)."""
            from importlib.metadata import metadata, packages_distributions
            # `__package__` is None in a notebook/__main__ context, so guard the
            # derivation with the known package module name.
            pkg = __package__ or "cjm_system_monitor_nvidia"
            dist = (packages_distributions().get(pkg) or [pkg.replace("_", "-")])[0]
            return metadata(dist)["Name"]
    
        @property
        def version(self) -> str:  # Tool version
        "Get the tool name (the installed distribution name)."
    
    def version(self) -> str:  # Tool version
            """Get the tool version string."""
            from cjm_system_monitor_nvidia import __version__
            return __version__
    
        def initialize(
            self,
            config: Optional[Dict[str, Any]] = None  # Configuration dictionary
        ) -> None
        "Get the tool version string."
    
    def initialize(
            self,
            config: Optional[Dict[str, Any]] = None  # Configuration dictionary
        ) -> None
        "Initialize or reconfigure the plugin."
    
    def get_config_schema(self) -> Dict[str, Any]:  # JSON Schema
            """Return JSON Schema for configuration."""
            return {}  # No config needed for monitoring
    
        def get_current_config(self) -> Dict[str, Any]:  # Current config
        "Return JSON Schema for configuration."
    
    def get_current_config(self) -> Dict[str, Any]:  # Current config
            """Return current configuration."""
            return self.config
    
    
    
        def _get_gpu_info_internal(self) -> Dict[str, Any]:  # Raw GPU data
        "Return current configuration."
    
    def get_system_status(self) -> SystemStats:  # Current system telemetry
            """Collect host CPU/RAM + aggregated GPU stats as a typed SystemStats.
    
            Per-process GPU usage is exposed separately via `list_processes()`. This
            is the native-dispatch surface the substrate's `_get_global_stats` calls
            for resource-derived admission (`MonitorToolProtocol`).
            """
            # 1. Get Host CPU/RAM (psutil)
            vm = psutil.virtual_memory()
    
            # 2. Get GPU Data
            gpu_raw = self._get_gpu_info_internal()
    
            # 3. Aggregate GPU Stats for the Scheduler
            total_vram_free = 0
            total_vram_total = 0
            total_vram_used = 0
            max_load = 0
    
            if gpu_raw['available']
        "Collect host CPU/RAM + aggregated GPU stats as a typed SystemStats.

Per-process GPU usage is exposed separately via `list_processes()`. This
is the native-dispatch surface the substrate's `_get_global_stats` calls
for resource-derived admission (`MonitorToolProtocol`)."
    
    def list_processes(self) -> List[ProcessStats]:  # Per-process GPU usage
        "Per-process GPU memory usage as typed ProcessStats.

Sources the same nvitop/nvidia-smi enumeration `get_system_status` uses;
returns `[]` when there is no GPU or no per-process attribution available.
The substrate's GPU subtree attribution intersects these PIDs with the
worker's process tree (`attribute_gpu_to_worker_subtree`)."

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cjm_system_monitor_nvidia-0.0.24.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cjm_system_monitor_nvidia-0.0.24-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file cjm_system_monitor_nvidia-0.0.24.tar.gz.

File metadata

File hashes

Hashes for cjm_system_monitor_nvidia-0.0.24.tar.gz
Algorithm Hash digest
SHA256 f5a63de89df93f9a956fdd2ebddede95775244c271969640767b066a7ea6e6d2
MD5 a0a76efd5de432d154deb8f7bc251e77
BLAKE2b-256 aae133850ffe748c1e82a5022ed04a8c5a1d61ee429c7aa4f42c96ab1089879c

See more details on using hashes here.

File details

Details for the file cjm_system_monitor_nvidia-0.0.24-py3-none-any.whl.

File metadata

File hashes

Hashes for cjm_system_monitor_nvidia-0.0.24-py3-none-any.whl
Algorithm Hash digest
SHA256 bf7312e39e251e8b00e855779385b674f9718437961414e6370bf727d9b184a8
MD5 cb5fde88f8c6446ebd97bfdc470dfc4c
BLAKE2b-256 1ef861926b1e7571c68acfa1c6e616c5ba9ac11826bd31ea9507b36c0ec47374

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page