简体   繁体   English

可以像指标一样获得azurevm Throught Powershell的cpu使用率

[英]it is possbile to get the cpu usage of azurevm Throught powershell like metrics

how can we get cpu usage of azure vm to local machine through csv file is it possible..? 我们如何才能通过csv文件将Azure vm的cpu使用率传输到本地计算机,这是可能的..? example:-i would like to get current cpu usage is 50%. 示例:-我想获得当前的CPU使用率是50%。

i am able to get single task usage example : task1=0.20 task2=6.98 but i am searching whole thing to get Can any one please help me 我能够获得单个任务的使用示例:task1 = 0.20 task2 = 6.98,但是我正在搜索整个事物,请问有人可以帮我吗

i am able to get cpu usage in base machine "wmic cpu get loadpercentage" like the same i am trying for azure vm 我能够在基本计算机“ wmic cpu get loadpercentage”中获得cpu的使用,就像我为azure vm尝试的一样

Thanks In Advance Giri 在此先感谢Giri

We can use this command to get the CPU usage: 我们可以使用以下命令来获取CPU使用率:

$cpu = gwmi win32_Processor
$Havecpu = "{0:0.0} %" -f $cpu.LoadPercentage
$Havecpu

Also if you want to remote run this script, we can use Winrm to run it and copy it to local PC: 另外,如果您想远程运行此脚本,我们可以使用Winrm运行它并将其复制到本地PC:

$username = 'user'
$pass = ConvertTo-SecureString -string 'password' -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $pass
$s = New-PSSession -ConnectionUri 'http://xx.xx.xx.xx:5985' -Credential $cred -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
Invoke-Command -Session $s -ScriptBlock {powershell c:\test.ps1 > c:\jason2.csv}
Copy-Item -Path C:\jason2.csv -Destination D:\test\test12.csv -fromSession $s

By the way, here is the test.ps1 script: 顺便说一下,这是test.ps1脚本:

  $cpu = gwmi  win32_Processor 
  $men = gwmi  win32_OperatingSystem 
  $Disks = gwmi  win32_logicaldisk -filter "drivetype=3" 
  $Havecpu = "{0:0.0} %" -f $cpu.LoadPercentage 
  $Allmen = "{0:0.0} MB" -f ($men.TotalVisibleMemorySize  / 1KB) 
  $Freemen = "{0:0.0} MB" -f ($men.FreePhysicalMemory  / 1KB) 
  $Permem =  "{0:0.0} %" -f ((($men.TotalVisibleMemorySize-$men.FreePhysicalMemory)/$men.TotalVisibleMemorySize)*100) 
  Write-Host "CPU: $Havecpu"`r`n
  Write-Host "Total Mem:$Allmen"`r`n 
  Write-Host "Left Mem:$Freemen"`r`n
  Write-Host "Used Mem:$Permem"`r`n
  $IpAdd = (Get-WmiObject -class win32_NetworkAdapterConfiguration -Filter 'ipenabled = "true"').ipaddress[0]
  Write-Host "Ipaddress:$IpAdd"`r`n

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM