Skip to content

Add get_storage_info() method to public library API #115

Description

@inureyes

Summary

The AllSmi library currently provides public methods for retrieving GPU, CPU, memory, and chassis information, but lacks a method for storage/disk information despite having the internal implementation.

This enhancement would complete the resource information API surface and provide library users with programmatic access to disk information.

Current State

  • StorageInfo struct already exists at src/storage/info.rs
  • Disk collection using sysinfo::Disks is implemented in local_collector.rs and api/server.rs
  • Storage info is only accessible internally via AppState
  • Other resources have public API methods:
    • get_gpu_info() -> Vec<GpuInfo>
    • get_cpu_info() -> Vec<CpuInfo>
    • get_memory_info() -> Vec<MemoryInfo>
    • get_chassis_info() -> Option<ChassisInfo>

Proposed Solution

  1. Create a StorageReader trait following the existing reader pattern (similar to GpuReader, CpuReader, MemoryReader, ChassisReader)
  2. Add storage_reader field to AllSmi struct in src/client.rs
  3. Implement get_storage_info() -> Vec<StorageInfo> method on AllSmi
  4. Reuse existing filter_docker_aware_disks() utility from src/utils.rs

Implementation Details

Component Location Description
StorageReader trait src/storage/reader.rs (new) Define the reader interface
LocalStorageReader src/storage/reader.rs (new) Implementation using sysinfo::Disks
AllSmi modification src/client.rs Add storage_reader field and get_storage_info() method
Public exports src/lib.rs Export StorageInfo and related types

Example API Usage

use all_smi::AllSmi;

let smi = AllSmi::new();

for storage in smi.get_storage_info() {
    println!("Disk: {} ({:?})", storage.name, storage.kind);
    println!("  Mount: {}", storage.mount_point);
    println!("  Total: {} bytes", storage.total_space);
    println!("  Used: {} bytes", storage.used_space);
    println!("  Available: {} bytes", storage.available_space);
}

Benefits

  • Consistent API design: Matches the pattern of other resource types
  • Library accessibility: Users can access disk information programmatically without using the TUI or API server
  • Code reuse: Leverages existing StorageInfo struct and filter_docker_aware_disks() utility
  • Minimal changes: Follows established patterns, reducing implementation complexity

Acceptance Criteria

  • Create StorageReader trait in src/storage/reader.rs
  • Implement LocalStorageReader using sysinfo::Disks
  • Add storage_reader field to AllSmi struct
  • Implement get_storage_info() -> Vec<StorageInfo> method
  • Export StorageInfo in public API (src/lib.rs)
  • Add unit tests for the new method
  • Update examples/library_usage.rs with storage info example
  • Update library API documentation

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions