2017-11-17 202 views
3

我試圖創建一個使用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 

回答

6

這可能會讓你的一部分。如果您先創建該對象,則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變量中的每個項目所需的類型。 –