Skip to content

inspector_helpers

sc_crawler.inspector_helpers #

Helpers to parse the hardware details of servers from the sc-inspector-data repository.

Classes:

Name Description
StorageInfo

Bundled storage of a server, parsed from lsblk and lshw outputs.

CpuCacheInfo

Size and sharing of a CPU cache level, parsed from lscpu and lstopo outputs.

StorageInfo dataclass #

Bundled storage of a server, parsed from lsblk and lshw outputs.

Source code in sc_crawler/inspector_helpers.py
@dataclass
class StorageInfo:
    """Bundled storage of a server, parsed from lsblk and lshw outputs."""

    storage_type: StorageType = None
    storage_size: int = 0
    storages: List[Disk] = field(default_factory=list)

    def __bool__(self):
        return bool(self.storage_type) or bool(self.storage_size) or bool(self.storages)

CpuCacheInfo dataclass #

Size and sharing of a CPU cache level, parsed from lscpu and lstopo outputs.

Source code in sc_crawler/inspector_helpers.py
@dataclass
class CpuCacheInfo:
    """Size and sharing of a CPU cache level, parsed from lscpu and lstopo outputs."""

    level: str
    total_bytes: int
    instances: int
    cores_per_domain: float = 0.0
    effective_per_core_bytes: float = 0.0

    @property
    def per_instance_bytes(self) -> int:
        return self.total_bytes // self.instances if self.instances else 0

    def as_dict(self) -> Dict[str, object]:
        def fmt_bytes(n: int) -> Tuple[Optional[int], Optional[float]]:
            if n <= 0:
                return None, None
            kib = n // 1024
            if kib <= 0:
                return None, None
            return kib, n / (1024.0 * 1024.0)

        pi_kib, pi_mib = fmt_bytes(self.per_instance_bytes)
        t_kib, t_mib = fmt_bytes(self.total_bytes)
        return {
            "level": self.level,
            "per_instance_bytes": (
                self.per_instance_bytes if self.per_instance_bytes > 0 else None
            ),
            "per_instance_KiB": pi_kib,
            "per_instance_MiB": pi_mib,
            "total_bytes": self.total_bytes if self.total_bytes > 0 else None,
            "total_KiB": t_kib,
            "total_MiB": t_mib,
            "instances": self.instances,
            "cores_per_domain": self.cores_per_domain,
            "effective_per_core_bytes": self.effective_per_core_bytes,
        }