Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting Windows performance counter categories

Tags:

I have a custom performance counter category. Visual Studio Server Explorer refuses to delete it, claiming it is 'not registered or a system category'. Short of doing it programmatically, how can I delete the category? Is there a registry key I can delete?

like image 492
Matt Howells Avatar asked Sep 26 '08 15:09

Matt Howells


People also ask

How do I remove performance counters?

Delete the Performance and Linkage keys under the application's Services key. To delete these keys, use either the Regedt32.exe utility or call RegDeleteKey.

What are Windows performance counters?

Windows Performance Counters provide a high-level abstraction layer that provides a consistent interface for collecting various kinds of system data such as CPU, memory, and disk usage. System administrators often use performance counters to monitor systems for performance or behavior problems.

Where are performance counters stored?

When you run a Data Collector Set, the data that is collected for performance counters is stored to a log file (. blg) in the location that was defined when the Data Collector Set was created. In Windows Performance Monitor, you can view log files to see a visual representation of performance counter data.


1 Answers

As far as I know, there is no way to safely delete them except programatically (they're intended for apps to create and remove during install) but it is trivial to do from a PowerShell command-line console. Just run this command:

[Diagnostics.PerformanceCounterCategory]::Delete( "Your Category Name" ) 

HOWEVER: (EDIT)

You can delete the registry key that's created, and that will make the category vanish.

For a category called "Inventory" you can delete the whole key at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Inventory ... and although I wouldn't be willing to bet that cleans up everything, it will make the category disappear. (If you run Process Monitor while running the Delete() method, you can see can a lot of other activity happening, and there doesn't seem to be any other changes made).

It's important to note that as I said originally: when you get that error from Visual Studio, it might be that it's already deleted and you need to refresh the view in VS. In my testing, I had to restart applications in order to get them to actually get a clean list of the available categories.

You can check the full list of categories from PowerShell to see if it's listed:

[Diagnostics.PerformanceCounterCategory]::GetCategories() | Format-Table -auto 

But if you check them, then delete the registry key ... they'll still show up, until you restart PowerShell (if you start another instance, you can run the same query over there, and it will NOT show the deleted item, but re-running GetCategories in the first one will continue showing it.

By the way, you can filter that list if you want to using -like for patterns, or -match for full regular expressions:

[Diagnostics.PerformanceCounterCategory]::GetCategories() | Where {$_.CategoryName -like "*network*" } | Format-Table -auto [Diagnostics.PerformanceCounterCategory]::GetCategories() | Where {$_.CategoryName -match "^SQL.*Stat.*" } | Format-Table -auto 
like image 153
Jaykul Avatar answered Oct 24 '22 09:10

Jaykul