本文介绍了可以像指标一样获得azurevm Throught Powershell的cpu使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何通过csv文件将Azure vm的cpu使用情况获取到本地计算机是否有可能..?例如:-我希望当前的CPU使用率为50%.

how can we get cpu usage of azure vm to local machine through csv file is it possible..?example:-i would like to get current cpu usage is 50%.

我可以使用单个任务示例:task1 = 0.20 task2 = 6.98但我正在寻找整个东西来谁能帮我

i am able to get single task usageexample : task1=0.20 task2=6.98but i am searching whole thing to get Can any one please help me

我能够在基本计算机上获得cpu的使用率"wmic cpu get loadpercentage"就像我尝试使用Azure vm一样

i am able to get cpu usage in base machine"wmic cpu get loadpercentage"like the same i am trying for azure vm

在此先感谢吉里

推荐答案

我们可以使用以下命令获取CPU使用率:

We can use this command to get the CPU usage:

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

此外,如果您想远程运行此脚本,我们可以使用Winrm来运行它并将其复制到本地PC:

Also if you want to remote run this script, we can use Winrm to run it and copy it to local 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

顺便说一下,这是test.ps1脚本:

By the way, here is the test.ps1 script:

  $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

这篇关于可以像指标一样获得azurevm Throught Powershell的cpu使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 11:46