作为我最后一个问题的后续行动,我想编译一个 perfmon 计数器列表,这些计数器-Continuous
以 1 秒间隔(默认)生成并连续采样()Start-Job
,睡眠 60 秒,然后运行Receive-job
以获取过去 60 秒的统计信息( -Average, -Sum, -Minimum, -Maximum
)。
我现在遇到的问题是当我使用绝对计数器路径时,工作开始并保持在“运行”状态。如果我尝试遍历一组性能计数器字符串,则作业状态将变为“已完成”。
下面是两个代码示例,它们显示了非工作和工作结果。
不工作。即使设置了 -Continuous,作业状态也会完成。不会引发错误。
$jobs=@{}
$counters=@("\Processor(*)\% Processor Time",
"\Network Interface(*)\Bytes Received/sec",
"\Network Interface(*)\Bytes Sent/sec")
foreach ($counterPath in $counters) {
$job=Start-Job {get-counter -Counter "$counterPath" -Continuous | foreach {$_.CounterSamples} }
$jobs[$job.id]=$counterPath
}
按预期工作,但不允许多个计数器通过循环开始工作。
$jobs=@{}
$job=Start-Job {get-counter -Counter "\Processor(*)\% Processor Time" -Continuous | foreach {$_.CounterSamples} }
$jobs[$job.id]=$counter
结果输出
PS C:\Users\msnow> $jobs=@{}
[string]$counter="\Processor(*)\% Processor Time"
$job=Start-Job {get-counter -Counter "$counter" -Continuous | foreach {$_.CounterSamples} }
$jobs[$job.id]=$counter
__________________________________________________________________________________________________________________________
PS C:\Users\msnow> $jobs=@{}
$job=Start-Job {get-counter -Counter "\Processor(*)\% Processor Time" -Continuous | foreach {$_.CounterSamples} }
$jobs[$job.id]=$counter
__________________________________________________________________________________________________________________________
PS C:\Users\msnow> Get-Job
Id Name State HasMoreData Location Command
-- ---- ----- ----------- -------- -------
1 Job1 Completed True localhost get-counter -Counter "...
3 Job3 Running True localhost get-counter -Counter "...
__________________________________________________________________________________________________________________________
PS C:\Users\msnow> receive-job -id 3 | measure CookedValue -sum -Average
Count : 11466
Average : 5.20268509822716
Sum : 59653.9873362726
Maximum :
Minimum :
Property : CookedValue