Inovação em Automação: Desenvolvendo um Gerenciador Inteligente de Recursos em PowerShell

Listen to this Post

You Should Know:

PowerShell is a powerful scripting language that can be used to automate and manage system resources efficiently. Below are some practical commands and steps to create a resource manager similar to the one described in the article.

1. Monitoramento em Tempo Real:

  • To monitor CPU usage:
    Get-Counter '\Processor(_Total)\% Processor Time'
    
  • To monitor memory usage:
    Get-Counter '\Memory\% Committed Bytes In Use'
    
  • To monitor disk usage:
    Get-Counter '\LogicalDisk(_Total)\% Free Space'
    

2. Análise Preditiva Básica:

  • Set thresholds for CPU, memory, and disk usage:
    $cpuThreshold = 80
    $memoryThreshold = 70
    $diskThreshold = 20
    
  • Compare current usage with thresholds:
    if ((Get-Counter '\Processor(_Total)\% Processor Time').CounterSamples.CookedValue -gt $cpuThreshold) {
    Write-Host "CPU usage is above threshold!"
    }
    

3. Automação com Controle:

  • Suggest actions to the user:
    $response = Read-Host "Do you want to terminate heavy processes? (Y/N)"
    if ($response -eq 'Y') {
    Get-Process | Sort-Object CPU -Descending | Select-Object -First 5 | Stop-Process -Force
    }
    

4. Relatório Visual em HTML: