要使用 Powershell 获取 Windows 性能计数器,我们可以使用Get-Counter cmdlet。
有多种性能计数器可用于测量 Windows 操作系统的性能。Get-Counter cmdlet 用于检索具有特定计数器名称的本地或远程系统的性能。
当您运行 Get-Counter 命令时,它会显示本地系统上的主要基本计数器,如 Nic、处理器、磁盘等。如下所示。
PS C:\> Get-Counter Timestamp CounterSamples --------- -------------- 4/7/2021 7:41:42 PM \labmachine2k16\network interface(intel[r] 82574l gigabit network connection)\bytes total/sec : 0 \labmachine2k16\network interface(isatap.{5008ca11-6974-4ec6-b2d7-eef6f9632c45})\bytes total/sec : 0 \labmachine2k16\processor(_total)\% processor time : 65.3778486182899 \labmachine2k16\memory\% committed bytes in use : 36.8481297364571 \labmachine2k16\memory\cache faults/sec : 1168.99908419505 \labmachine2k16\physicaldisk(_total)\% disk time : 16.2392354345686 \labmachine2k16\physicaldisk(_total)\current disk queue length : 2
要获取远程系统上的计数器,请使用 - ComputerName参数。
Get-Counter -ComputerName TestMachine
要获取各种可用的计数器列表,请使用-ListSet参数。
Get-Counter -ListSet *输出结果
您可以在Counter属性中看到带有各种计数器的counterSetName 。machinename属性显示本地或远程机器。点 (.) 表示本地计算机名称。
要查找与处理器相关的特定计数器,请使用以下命令。
Get-Counter -ListSet * | where{$_.CounterSetName -like "*Processor*"} | Select CounterSetName, Counter输出结果
同样要获取与磁盘相关的计数器,请使用以下命令,
Get-Counter -ListSet * | where{$_.CounterSetName -like "*disk*"} | Select CounterSetName, Counter