Jinjinov / Hardware.Info

Battery, BIOS, CPU - processor, storage drive, keyboard, RAM - memory, monitor, motherboard, mouse, NIC - network adapter, printer, sound card - audio card, graphics card - video card. Hardware.Info is a .NET Standard 2.0 library and uses WMI on Windows, /dev, /proc, /sys on Linux and sysctl, system_profiler on macOS.
MIT License
483 stars 77 forks source link

Drive info not available in Linux #61

Closed GusanoGris closed 7 months ago

GusanoGris commented 8 months ago

100.0.1.1

Raspberry OS 5/6, ubuntu 22

Describe the bug

Driver info doesn't work on linux, but it does on windows

To Reproduce

Program.cs

namespace nunaSysMon
{
  public class Program
  {
    public static void Main(string[] args)
    {
      var builder = Host.CreateApplicationBuilder(args);
      builder.Services.AddHostedService<Worker>();

      var host = builder.Build();
      host.Run();
    }
  }
}

worker.cs

using Hardware.Info;

namespace nunaSysMon
{
  public class Worker : BackgroundService
  {
    private readonly ILogger<Worker> _logger;
    private readonly IHardwareInfo _hardwareInfo = new HardwareInfo();

    public Worker(ILogger<Worker> logger)
    {
      _logger = logger;
    }

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
      ulong _cpuTime = 0;
      _hardwareInfo.RefreshAll();
      Console.WriteLine("------------------------------------>>");
      Console.WriteLine($"Delay 21s");
      Console.WriteLine("------------------------------------>>");
      await Task.Delay(21000, stoppingToken);
      while (!stoppingToken.IsCancellationRequested)
      {
        if (_logger.IsEnabled(LogLevel.Information))
        {
          _cpuTime = 0;
          _hardwareInfo.RefreshCPUList();
          _hardwareInfo.CpuList.ForEach(a => _cpuTime += a.PercentProcessorTime);
          _hardwareInfo.RefreshMemoryStatus();
          var _fMemmory = (_hardwareInfo.MemoryStatus.AvailablePhysical / (1024 * 1024 * 1024));
          var _tMemmory = (_hardwareInfo.MemoryStatus.TotalPhysical / (1024 * 1024 * 1024));
          var _fpMemory = _fMemmory * 100 / _tMemmory;
          Console.WriteLine("------------------------------------>>");
          Console.WriteLine($"SO: {_hardwareInfo.OperatingSystem}");

          Console.WriteLine($"CPU %: {_cpuTime}");
          Console.WriteLine($"Mem Free: {_fMemmory.ToString("#,##0.##")}Gb / {_fpMemory}%");

          _hardwareInfo.RefreshDriveList();          
          Console.WriteLine($"Drives:");

          foreach (var drive in _hardwareInfo.DriveList)
          {
            foreach (var partition in drive.PartitionList)
            {
              foreach (Volume v in partition.VolumeList)
              {
                var _pSpace = v.FreeSpace * 100 / v.Size;
                var _fSpace = v.FreeSpace / (1024 * 1024 * 1024);
                Console.WriteLine($"\t{v.Name} {_fSpace}Gb / {_pSpace}%");
              }
            }
          }
        }
        await Task.Delay(15000, stoppingToken);
      }
    }
  }
}

Steps to reproduce the behavior:

  1. Open Visual Studio and create a new project using this template '...'
  2. Add this code '...' in this class '...' to this method '...' in this line '...'
  3. Run the program

If you don't provide C# code to reproduce the problem, the issue will be closed.

Exceptions (if any)

Expected behavior

Additional context

Jinjinov commented 8 months ago

Please describe the problem in more detail.

What do you mean by "driver info"?

What do you expect to happen and what actually happens?

Provide console output from Windows and from Linux.

GusanoGris commented 8 months ago

Info windows

Info Linux

GusanoGris commented 8 months ago

LSHW does not display SSD or virtual disk information. There are options to retrieve the information with lsblk -iOJ. This returns information from the disks in Json format.

I didn't dare to touch the utility's code so as not to interfere with its library.

dzysdy commented 7 months ago

请问这个问题解决了吗

Jinjinov commented 7 months ago

Fixed in https://github.com/Jinjinov/Hardware.Info/releases/tag/v100.1.0.0