scitex_resource

scitex-resource — system resource info, monitoring, RAM limit (standalone).

Public API is loaded lazily via PEP 562 __getattr__ so import scitex_resource stays fast (<100ms cold-start) — Click runs the CLI program once per Tab press for completion, and pulling in matplotlib/psutil/yaml at top-level made that path ~2s slow.

scitex_resource.get_host_config()[source]

Return the host: block from config (falls back to machine:).

If a config file declares only the legacy machine: key, a one-time DeprecationWarning is emitted and that block is returned.

Return type:

dict[str, Any]

scitex_resource.get_host_name()[source]

Return the canonical host name.

See module docstring for the resolution cascade. Always returns a non-empty string — the short hostname is the last-resort fallback.

Return type:

str

scitex_resource.load_config()[source]

Return the merged config dict — project file overrides user file.

Empty dict if no config files exist or PyYAML isn’t installed.

Return type:

dict[str, Any]

scitex_resource.get_machine_config()[source]

Deprecated alias for get_host_config().

Return type:

dict[str, Any]

scitex_resource.get_machine_name()[source]

Deprecated alias for get_host_name().

Return type:

str

scitex_resource.get_metrics(gpu=True)[source]

Return a flat dict of current system metrics suitable for heartbeats.

Parameters:

gpu (bool) – When True (default) probe NVIDIA GPUs via nvidia-smi. Set to False on hot paths to skip the ~200 ms shellout when you know there’s no GPU or when you cache GPU info separately.

Returns:

See module docstring for the full key list and contract.

Return type:

dict

scitex_resource.get_processor_usages()[source]

Gets current system resource usage statistics.

Returns:

Resource usage data with columns: - Timestamp: Timestamp - CPU [%]: CPU utilization - RAM [GiB]: RAM usage - GPU [%]: GPU utilization - VRAM [GiB]: VRAM usage

Return type:

pd.DataFrame

Example

>>> df = get_proccessor_usages()
>>> print(df)
             Timestamp  CPU [%]  RAM [GiB]  GPU [%]  VRAM [GiB]
0  2024-11-04 10:30:15    25.3      8.2     65.0        4.5
scitex_resource.get_specs(system=True, cpu=True, gpu=True, disk=True, network=True, verbose=False, yaml=False)[source]

Collects and returns system specifications including system information, CPU, GPU, disk, and network details.

This function gathers various pieces of system information based on the parameters provided. It can return the data in a dictionary format or print it out based on the verbose flag. Additionally, there’s an option to format the output as YAML.

Parameters:
  • system (bool) – If True, collects system-wide information such as OS and node name. Default is True.

  • boot_time (bool) – If True, collects system boot time. Currently commented out in the implementation. Default is True.

  • cpu (bool) – If True, collects CPU-specific information including frequency and usage. Default is True.

  • gpu (bool) – If True, collects GPU-specific information. Default is True.

  • disk (bool) – If True, collects disk usage information for all partitions. Default is True.

  • network (bool) – If True, collects network interface and traffic information. Default is True.

  • verbose (bool) – If True, prints the collected information using pprint. Default is False.

  • yaml (bool) – If True, formats the collected information as YAML. This modifies the return type to a YAML formatted string. Default is False.

Returns:

By default, returns a dictionary containing the collected system specifications. If yaml is True, returns a YAML-formatted string instead.

Return type:

dict or str

Note

  • The actual collection of system, CPU, GPU, disk, and network information depends on the availability of corresponding libraries and access permissions.

  • The boot_time argument is currently not used as its corresponding code is commented out.

  • The function uses global variables and imports within its scope, which might affect its reusability and testability.

Example

>>> specs = get_specs(verbose=True)
This will print and return the system specifications based on the default parameters.
Dependencies:
  • This function depends on the scitex library for accessing system information and formatting output. Ensure this library is installed and properly configured.

  • Python standard libraries: datetime, platform, psutil, yaml (optional for YAML output).

Raises:

PermissionError – If the function lacks necessary permissions to access certain system information, especially disk and network details.

scitex_resource.log_processor_usages(path='/tmp/scitex/processor_usages.csv', limit_min=30, interval_s=1, init=True, verbose=False, background=False)[source]

Logs system resource usage over time.

Parameters:
  • path (str) – Path to save the log file

  • limit_min (float) – Monitoring duration in minutes

  • interval_s (float) – Sampling interval in seconds

  • init (bool) – Whether to clear existing log file

  • verbose (bool) – Whether to print the log

  • background (bool) – Whether to run in background

Returns:

Process object if background=True, None otherwise

Return type:

Union[None, Process]

scitex_resource.main(path='/tmp/scitex/processor_usages.csv', limit_min=30, interval_s=1, init=True, verbose=False, background=False)

Logs system resource usage over time.

Parameters:
  • path (str) – Path to save the log file

  • limit_min (float) – Monitoring duration in minutes

  • interval_s (float) – Sampling interval in seconds

  • init (bool) – Whether to clear existing log file

  • verbose (bool) – Whether to print the log

  • background (bool) – Whether to run in background

Returns:

Process object if background=True, None otherwise

Return type:

Union[None, Process]

Modules

limit_ram