EKS
EKS

Reputation: 5623

Performance counters go missing

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?

Upvotes: 2

Views: 1992

Answers (2)

Tiaraju
Tiaraju

Reputation: 139

Being a bit more specific, you can check your Event Viewer and look for PerfLib events.

In my case, they were marked with errors.

Then, after looking around I found the two commands explained above. In my case, the problem was with the perfOS. (you can always run lodctr /q:Perflib to check what's disabled.

Then, run: lodctr /e:perfOS (or change perfOS for whatever service is disabled)

That will do (at least it worked for me)

TLDR: run lodctr /q:perfOs and lodctr /e:perfOS as Admin

Upvotes: 1

Julien
Julien

Reputation: 21

I had exactly the same issue, and this is how I fix it:

Server architecture (x86 or x64) and .net (c#) build target must be the same, otherwise your code is unable to access all the performace counters (only a subset of performance counters is available if your build target and server differs).

So in Visual Studio, right-click on your project (in solution explorer), then select "Properties", then go to "Build" and select x64 as platform target (if your server is in x64, otherwise select x86).

Upvotes: 2

Related Questions