{"id":28446477,"url":"https://github.com/phmatray/computerinfo","last_synced_at":"2025-06-29T23:31:42.315Z","repository":{"id":296216950,"uuid":"866410246","full_name":"phmatray/ComputerInfo","owner":"phmatray","description":"Get computer info from a BackgroundService based on a SignalR connection","archived":false,"fork":false,"pushed_at":"2025-05-29T13:59:23.000Z","size":51,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-29T15:06:55.052Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phmatray.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-02T07:56:59.000Z","updated_at":"2025-05-29T13:58:53.000Z","dependencies_parsed_at":"2025-05-29T15:19:29.554Z","dependency_job_id":null,"html_url":"https://github.com/phmatray/ComputerInfo","commit_stats":null,"previous_names":["phmatray/computerinfo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phmatray%2FComputerInfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phmatray%2FComputerInfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phmatray%2FComputerInfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phmatray%2FComputerInfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phmatray","download_url":"https://codeload.github.com/phmatray/ComputerInfo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phmatray%2FComputerInfo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258389078,"owners_count":22693299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-06T10:41:39.813Z","updated_at":"2025-06-29T23:31:42.306Z","avatar_url":"https://github.com/phmatray.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Computer Information Collector - POC\n\n## Overview\n\nThis project is a **Proof of Concept (POC)** for a cross-platform service that collects system and machine information such as memory, disk usage, CPU details, and network adapters. The service is designed to run on **Windows**, **Linux**, and **macOS** platforms, providing detailed insights into the system's current state.\n\nThe project demonstrates a clean, maintainable, and extendable architecture by splitting platform-specific logic into separate services. The implementation relies on **dependency injection** to choose the appropriate provider based on the host operating system.\n\n## Features\n\n- **Cross-platform compatibility**: Supports **Windows**, **Linux**, and **macOS**.\n- **Platform-specific implementations**: Uses different strategies for each platform to retrieve machine information, such as memory and disk usage.\n- **Modular architecture**: The platform-specific logic is neatly separated into individual services, making the code more maintainable and easy to extend.\n- **System information collected**:\n    - Machine name\n    - Operating system description and architecture\n    - CPU architecture and processor count\n    - Total and available memory\n    - Disk drives information (total size, free space)\n    - Network adapter details (IP address, MAC address)\n    - System uptime\n\n## Components\n\n### 1. `IMachineInfoProvider`\nAn interface that defines the contract for collecting machine information.\n\n### 2. Platform-specific Providers\nThree separate implementations of `IMachineInfoProvider`, each tailored to a specific platform:\n- **`WindowsMachineInfoProvider`**: Collects machine info using Windows APIs like `PerformanceCounter`.\n- **`MacOSMachineInfoProvider`**: Uses `sysctl` and `vm_stat` commands to gather system info on macOS.\n- **`UnixMachineInfoProvider`**: Retrieves information from `/proc/meminfo` and other system files for Linux-based systems.\n\n### 3. Dependency Injection\nThe project uses **dependency injection** to select the appropriate `IMachineInfoProvider` implementation based on the current platform. This ensures that platform-specific logic is isolated and only the relevant provider is used.\n\n### 4. `MachineInfoWorker`\nA background service that periodically collects and sends system information. It leverages the `IMachineInfoProvider` to gather system details and can be easily adapted to send or log the information to various outputs (e.g., APIs, log files).\n\n## Setup \u0026 Usage\n\n### Prerequisites\n\n- .NET 8.0 or later\n- The project is compatible with **Windows**, **Linux**, and **macOS**.\n\n### Clone the Repository\n\n```bash\ngit clone https://github.com/phmatray/ComputerInfo.git\ncd ComputerInfo\n```\n\n### Build and Run the Project\n\n```bash\ndotnet build\ndotnet run\n```\n\n### Dependency Injection Setup\n\nThe platform-specific provider is injected using the following logic in `Program.cs`:\n\n```csharp\nif (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))\n{\n    services.AddSingleton\u003cIMachineInfoProvider, WindowsMachineInfoProvider\u003e();\n}\nelse if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))\n{\n    services.AddSingleton\u003cIMachineInfoProvider, MacOSMachineInfoProvider\u003e();\n}\nelse if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))\n{\n    services.AddSingleton\u003cIMachineInfoProvider, UnixMachineInfoProvider\u003e();\n}\n```\n\n### Customization\n\nYou can modify or extend the project by adding additional platform-specific providers or collecting more machine details. The architecture is designed to be modular and adaptable.\n\n## Architecture\n\nThe architecture follows the **Single Responsibility Principle (SRP)**, with platform-specific logic abstracted into separate classes. This modular approach ensures maintainability and scalability, allowing future improvements or the addition of more platforms without complicating the existing structure.\n\n### Flow\n\n1. **Startup**: During startup, the appropriate `IMachineInfoProvider` is injected based on the current operating system.\n2. **Execution**: The `MachineInfoWorker` runs as a background service, periodically invoking the `IMachineInfoProvider` to retrieve machine information.\n3. **Logging**: For demonstration purposes, the collected information is logged to the console. In a production scenario, this could be extended to send the information to an API or save it to a database.\n\n## Limitations\n\n- This is a **POC** and may not handle all edge cases or offer full error handling for production use.\n- Platform-specific implementations might need further testing and adjustments depending on the target system configuration.\n- The `PerformanceCounter` API used for memory info on Windows may require elevated permissions on some systems.\n\n## Contributing\n\nFeel free to fork the repository and submit pull requests. Contributions to improve platform support or add new features are welcome!\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphmatray%2Fcomputerinfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphmatray%2Fcomputerinfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphmatray%2Fcomputerinfo/lists"}