Diagnostics.PerformanceCounter Returns 0 for SQL Counters

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 2 years, 6 months ago.

  • Author
    Posts
  • #15450
    Profile photo of Allen White
    Allen White
    Participant

    Hi,

    On systems where I've implemented minimally privileged domain service accounts for SQL Server services I've run into a problem accessing perf counter data using the System.Diagnostics.PerformanceCounter object. If I run perfmon the counters all return valid results, and I get proper values from the OS counters (Pct Processor Used, Available Memory, etc.) through the PerformanceCounter object, but the SQL Server counters all return zero.

    The service accounts are part of an AD group, and I've added that group to both the Performance Log Users and Performance Monitor Users groups in the local machine.

    Any idea why this is happening? I've got scripts that have worked everywhere else, but this one client, and I'm not sure where to look to find it. (I've refreshed the counters – they work in perfmon.)

    Thanks.

    Allen White

  • #15458
    Profile photo of Don Jones
    Don Jones
    Keymaster

    I think you might get a better response from something like StackOverflow.com – only because this isn't PowerShell per se; you're dealing with the .NET Framework classes and it's more likely someone over there has done so.

    I unfortunately don't know enough about how SQL works with those counters, although have you tried accessing them via WMI instead? I'm just wondering if that'd be any different. The fact that they work in PerfMon is vexing.

  • #15461
    Profile photo of Allen White
    Allen White
    Participant

    Vexing is a good way to put it, Don. If I run PowerShell as Administrator, the counters return valid values as well, but my login is part of the local Admin group and returns 0, unless I run PowerShell as Administrator. I just don't know what security settings it requires to get valid values.

    Thanks for responding.

    Allen

  • #15470
    Profile photo of Allen White
    Allen White
    Participant

    Apparently the same problem exists with the Get-Counter cmdlet. Here's a post on StackExchange identifying the problem: http://dba.stackexchange.com/questions/64898/powershell-get-counter-not-returning-values-for-sql-counters

  • #15489
    Profile photo of Don Jones
    Don Jones
    Keymaster

    It's likely a user privilege thing – there's an explicit privilege for being able to profile the system. Might be connected to that.

You must be logged in to reply to this topic.