3

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 

1 Answer 1

6
+50

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. My actual collection is over 70 counters, some require AverageBase and others do not. How would this work for multiple counters of mixed types?
i think with each add you can specify the type of underlying counter whether it be a Averagebase or Rawfraction. so you'd need to just write a loop around the add and change the types you need to use for each item you add to the AnalyticsCollection Variable.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.