My problem is that some of the performance counter category seems to go missing sometimes, and I don't understand why.
The code below will throw an exception, like this:
Failed to lookup Performance Category
Error Msg: Category does not exist. CategoryName: HP EVA Physical Disk
Group Category list on target:
ServiceModelService 4.0.
bla bla
Print out contains a long list of performance counters, but not the one I'm after. If I look in perfmon.exe I can find the missing category once.
I'm using the following code to find the different counters inside a category.
public static string[] GetPerformanceCategory(string CategoryName)
{
//Console.WriteLine("CategoryName to Search for: " + CategoryName);
if (string.IsNullOrEmpty(CategoryName))
throw new NullReferenceException("CategoryName is empty");
try
{
PerformanceCounterCategory perfCat = new PerformanceCounterCategory(CategoryName);
string[] catInstances = perfCat.GetInstanceNames();
return catInstances;
}
catch(Exception Ex)
{
StringBuilder ErrorMsg = new StringBuilder();
ErrorMsg.AppendLine("Failed to lookup Preformance Category");
ErrorMsg.AppendLine("Error Msg: " + Ex.Message);
ErrorMsg.AppendLine("CategoryName: " + CategoryName);
ErrorMsg.AppendLine("Category list on target:");
StringBuilder CatList = new StringBuilder();
var categories = PerformanceCounterCategory.GetCategories();
foreach (var Cat in categories)
CatList.AppendLine(Cat.CategoryName);
ErrorMsg.AppendLine(CatList.ToString());
Logger.WriteToLog(ErrorMsg.ToString(), EventLogEntryType.Error);
return null;
}
}
The question boils down to, is there some "magic" that can make performance counters disappear? Or perhaps I need to do something specific?