创建Peformance计数器的PowerShell:为指定类别的计数器布局无效

创建Peformance计数器的PowerShell:为指定类别的计数器布局无效

问题描述:

我试图创建一个使用PowerShell的性能计数器,但我得到以下错误,由于我使用AverageCount64的:创建Peformance计数器的PowerShell:为指定类别的计数器布局无效

“反布局对于指定的类别是无效的,一个计数器的类型的 :AverageCount64,AverageTimer32,CounterMultiTimer, CounterMultiTimerInverse, CounterMultiTimer100Ns,CounterMultiTimer100NsInverse,RawFraction,或 SampleFraction必须被随后立即任何基部 计数器类型:AverageBase,CounterMultiBase ,RawBase或S ampleBase“。

我知道,我需要添加AverageBase对于那些AverageCount64但我不确定如何添加在我的代码,尤其是因为我有类型(RateOfCountsPerSecond64)类型不需要AverageBase:

$AnalyticsCollection = New-Object System.Diagnostics.CounterCreationDataCollection 
    $AnalyticsCollection.Add((New-Object $ccdTypeName "Aggregation | Total Aggregation Errors/sec", "The total number of interactions which could not be aggregated due to an exception.", RateOfCountsPerSecond64))  
    $AnalyticsCollection.Add((New-Object $ccdTypeName "Aggregation | Average Check Out Time - History (ms)", "Average time it takes to obtain a work item from a range scheduler while rebuilding the reporting database.", AverageCount64)) 
    $AnalyticsCollection.Add((New-Object $ccdTypeName "Collection | Total Visits/sec", "The total number of visits per second that are registered by the system.", RateOfCountsPerSecond64))   
    $AnalyticsCollection.Add((New-Object $ccdTypeName "Aggregation | Average Check In Time - History (ms)", "Average time it takes to mark a work item as completed in a range scheduler while rebuilding the reporting database.", AverageCount64)) 
    [System.Diagnostics.PerformanceCounterCategory]::Create("My Counters", "I love my performance counters", [Diagnostics.PerformanceCounterCategoryType]::MultiInstance, $AnalyticsCollection) | out-null 

这可能会让你的一部分。如果您先创建该对象,则T的类型为[System.Diagnostics.CounterCreationData],然后您可以将其放入Google Analytics集合中。错误消息似乎表明您需要在创建计数器时添加基本类型。所以我改变了你的最后一行。特别地从枚举中添加RawFraction的基类型。

$t = [System.Diagnostics.CounterCreationData]::new() 
$t.CounterName = 'test'    
$t.CounterHelp = 'help me'   
$t.CounterType = [System.Diagnostics.PerformanceCounterType]::AverageCount64 
$AnalyticsCollection.Add($t) 
[System.Diagnostics.PerformanceCounterCategory]::Create('myCounters', 'OK Get Counting', [System.Diagnostics.PerformanceCounterCategoryType]::MultiInstance, $AnalyticsCollection, [System.Diagnostics.PerformanceCountertype]::RawFraction) 

我也使用这个博客来帮助我解密做什么。我希望这可以指导你解决问题的方向。祝你好运 Windows Performance Counter Types

+0

谢谢。我的实际收藏有70多个计数器,有些需要AverageBase,其他则不需要。这将如何工作的混合类型的多个计数器? – Kode

+2

我认为每次添加都可以指定底层计数器的类型,无论它是Averagebase还是Rawfraction。因此您只需围绕添加编写一个循环,并更改您添加到AnalyticsCollection变量中的每个项目所需的类型。 –