Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

System Information Laravel Package

zetacomponents/system-information

Provides access to system and environment information via the eZ Components/Zeta Components library. Query OS details, hardware and memory stats, CPU and uptime, network interfaces, load, and related runtime metrics for monitoring or diagnostics in PHP apps.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require zetacomponents/system-information
    

    Add to composer.json under require if not using Composer globally.

  2. First Use Case: Fetching Basic System Info

    use Zeta\Components\SystemInformation\SystemInformation;
    
    $systemInfo = new SystemInformation();
    $cpuInfo = $systemInfo->getCpuInfo();
    $memoryInfo = $systemInfo->getMemoryInfo();
    
    // Output CPU details
    echo "CPU: " . $cpuInfo['type'] . " @ " . $cpuInfo['speed'] . " MHz";
    
    // Output memory details
    echo "Memory: " . round($memoryInfo['total'] / (1024 * 1024 * 1024), 2) . " GB";
    
  3. Where to Look First


Implementation Patterns

Common Workflows

1. System Monitoring Dashboard

// In a Laravel controller or service
public function getSystemStats()
{
    $systemInfo = new SystemInformation();
    return [
        'cpu' => [
            'type' => $systemInfo->getCpuInfo()['type'],
            'cores' => $systemInfo->getCpuInfo()['cores'],
            'speed' => $systemInfo->getCpuInfo()['speed'],
        ],
        'memory' => [
            'total' => $this->formatBytes($systemInfo->getMemoryInfo()['total']),
            'free' => $this->formatBytes($systemInfo->getMemoryInfo()['free']),
        ],
        'disk' => $this->getDiskUsage(),
    ];
}

private function formatBytes($bytes)
{
    return round($bytes / (1024 ** 2), 2) . ' MB';
}
  • Integration Tip: Cache results for 1 minute to avoid repeated system calls:
    return Cache::remember('system_stats', now()->addMinutes(1), function () {
        return $this->getSystemStats();
    });
    

2. Hardware Requirements Validation

public function validateHardwareRequirements()
{
    $systemInfo = new SystemInformation();
    $memory = $systemInfo->getMemoryInfo()['total'];
    $cpuCores = $systemInfo->getCpuInfo()['cores'];

    if ($memory < 4 * 1024 * 1024 * 1024) { // <4GB
        throw new \RuntimeException("Minimum 4GB RAM required.");
    }

    if ($cpuCores < 2) {
        throw new \RuntimeException("Minimum 2 CPU cores required.");
    }

    return true;
}
  • Use Case: Pre-installation checks for Laravel SaaS applications.

3. Logging System Metrics

use Illuminate\Support\Facades\Log;

public function logSystemMetrics()
{
    $systemInfo = new SystemInformation();
    Log::info('System Metrics', [
        'cpu' => $systemInfo->getCpuInfo(),
        'memory' => $systemInfo->getMemoryInfo(),
        'os' => $systemInfo->getOsInfo(),
    ]);
}
  • Integration Tip: Schedule with Laravel’s task scheduler:
    $schedule->call('App\Services\SystemMetricsLogger@logSystemMetrics')->daily();
    

4. Dynamic Configuration Based on Hardware

public function getOptimizedConfig()
{
    $systemInfo = new SystemInformation();
    $cpuCores = $systemInfo->getCpuInfo()['cores'];
    $memoryGB = round($systemInfo->getMemoryInfo()['total'] / (1024 ** 3));

    return [
        'queue' => [
            'connections' => min($cpuCores * 2, 8), // Max 8 workers
            'max_jobs' => $memoryGB * 100, // Arbitrary scaling
        ],
    ];
}

Laravel-Specific Patterns

1. Service Provider Binding

Register the package as a singleton in AppServiceProvider:

public function register()
{
    $this->app->singleton(SystemInformation::class, function () {
        return new SystemInformation();
    });
}

Now inject SystemInformation anywhere:

public function __construct(private SystemInformation $systemInfo) {}

2. View Composers

Share system info across all views:

public function boot()
{
    View::composer('*', function ($view) {
        $view->with('systemInfo', app(SystemInformation::class));
    });
}

Access in Blade:

<div class="system-info">
    CPU: {{ $systemInfo->getCpuInfo()['type'] }} |
    Memory: {{ $systemInfo->getMemoryInfo()['free'] / (1024 ** 2) }} MB
</div>

3. Middleware for Hardware-Based Access Control

public function handle($request, Closure $next)
{
    $systemInfo = new SystemInformation();
    if ($systemInfo->getMemoryInfo()['total'] < 8 * 1024 * 1024 * 1024) { // <8GB
        abort(403, 'Insufficient hardware resources.');
    }
    return $next($request);
}

Gotchas and Tips

Pitfalls

  1. Platform-Specific Data

    • The package relies on php_uname(), sys_getloadavg(), and OS-specific commands (e.g., lscpu, free).
    • Gotcha: On Windows, some methods (e.g., CPU core count) may return null or less accurate data. Fix: Add fallback logic:
      $cpuCores = $systemInfo->getCpuInfo()['cores'] ?? 1; // Default to 1 core
      
  2. Permission Issues

    • Commands like lscpu or free may fail if the PHP process lacks permissions.
    • Gotcha: Silent failures (e.g., getCpuInfo() returns empty array). Fix: Wrap calls in try-catch:
      try {
          $cpuInfo = $systemInfo->getCpuInfo();
      } catch (\RuntimeException $e) {
          $cpuInfo = ['type' => 'unknown', 'cores' => 1];
      }
      
  3. Memory Units Inconsistency

    • getMemoryInfo() returns bytes, but some methods (e.g., getOsInfo()) may return values in KB/MB.
    • Tip: Always normalize units:
      $memoryGB = $systemInfo->getMemoryInfo()['total'] / (1024 ** 3);
      
  4. Caching Stale Data

    • System info changes dynamically (e.g., memory usage).
    • Gotcha: Caching raw system info for too long leads to outdated metrics. Tip: Cache only derived data (e.g., "is memory low?"):
      Cache::remember('is_memory_low', now()->addSeconds(10), function () {
          return app(SystemInformation::class)->getMemoryInfo()['free'] < 1 * 1024 ** 3;
      });
      

Debugging Tips

  1. Verify OS Support Check php_uname('s') to confirm the OS:

    $os = php_uname('s');
    if (strpos($os, 'Linux') === false && strpos($os, 'Darwin') === false) {
        // Windows or other OS; handle gracefully
    }
    
  2. Log Raw Outputs Debug command outputs by enabling verbose mode:

    $systemInfo = new SystemInformation();
    $systemInfo->setVerbose(true); // If supported (check package docs)
    
  3. Fallback Values Provide defaults for critical paths:

    $cpuInfo = $systemInfo->getCpuInfo() ?: [
        'type' => 'unknown',
        'speed' => 0,
        'cores' => 1,
    ];
    

Extension Points

  1. Custom System Info Sources Extend the base class to add support for additional metrics (e.g., GPU, network):
    class ExtendedSystemInformation extends SystemInformation
    {
        public function
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky