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

Kod*_*ode 3 powershell performancecounter

我正在尝试使用PowerShell创建性能计数器,但由于我使用了AverageCount64,我收到以下错误:

"指定类别的计数器布局无效,类型的计数器:AverageCount64,AverageTimer32,CounterMultiTimer,CounterMultiTimerInverse,CounterMultiTimer100Ns,CounterMultiTimer100NsInverse,RawFraction或SampleFraction必须紧跟任何基本计数器类型:AverageBase,CounterMultiBase, RawBase或SampleBase."

我知道我需要为AverageCount64类型添加AverageBase但不确定如何在我的代码中添加它,特别是因为我有不需要AverageBase的类型(RateOfCountsPerSecond64):

    $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
Run Code Online (Sandbox Code Playgroud)

tho*_*her 6

这可能会让你成为一部分.T的类型为[System.Diagnostics.CounterCreationData],如果您先创建该对象,则可以将其放入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)
Run Code Online (Sandbox Code Playgroud)

我也用这个博客来帮我解读做什么.我希望这能指出你的解决方案.祝你好运 Windows性能计数器类型

  • 我认为对于每个添加,您可以指定底层计数器的类型,无论它是Averagebase还是Rawfraction.因此,您需要围绕添加编写一个循环,并更改您需要为添加到AnalyticsCollection变量的每个项目使用的类型. (2认同)