Reputation: 3215
I am trying to create Performance Counters using PowerShell, but am getting the following error due to my use of AverageCount64:
"The Counter layout for the Category specified is invalid, a counter of the type: AverageCount64, AverageTimer32, CounterMultiTimer, CounterMultiTimerInverse, CounterMultiTimer100Ns,CounterMultiTimer100NsInverse, RawFraction, or SampleFraction has to be immediately followed by any of the base counter types: AverageBase, CounterMultiBase, RawBase or SampleBase."
I know that I need to add AverageBase for the types that are AverageCount64 but am unsure how to add that in my code, especially since I have types (RateOfCountsPerSecond64) that don't require 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
Upvotes: 3
Views: 1086
Reputation: 1583
This might get you part of the way. T is of type [System.Diagnostics.CounterCreationData] if you create that object first then you can put in in your Analytics collection. The error messsage seems to indicate that you need to add the base type in the creation of the counter. so i changed your last line a bit.. Specically adding the basetype of RawFraction from the enumeration.
$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)
I also used this blog to help me decipher what to do. I hope this points you in a solution direction. Good luck Windows Performance Counter Types
Upvotes: 6