Skip to content

Windows containers don't have Performance Counters in registry #1976

Closed

Description

@RajeshBabuJangili

Hi , I am using Windows Server 2019 container, and using below code to get "SystemCpuLoadTicks" from windows container but every time I am getting values [0, 0, 0, 0, 0, 0, 0, 0],because of this every time CPU Usage reporting 100%, please suggest me why I am getting all 0s every time ?

{   
    SystemInfo si = new SystemInfo();
    HardwareAbstractionLayer hal = si.getHardware();

    CentralProcessor cpuInfo = hal.getProcessor();
    int coreCount = cpuInfo.getPhysicalProcessorCount();
    int processorCount = cpuInfo.getLogicalProcessorCount();
    CentralProcessor.ProcessorIdentifier cpuId = cpuInfo.getProcessorIdentifier();
    Map<String, WindowsRawData.Cpu> cpusMap = ImmutableMap.of("CPU", WindowsRawData.Cpu.builder()
            .cpuVendor(cpuId.getVendor())
            .cpuName(cpuId.getName())
            .numCores(coreCount)
            .numLogicalProcessors(processorCount)
            .cpuMaxSpeedMhz(cpuId.getVendorFreq() / 1000000L)
            .build());
    long[] loadTicks = cpuInfo.getSystemCpuLoadTicks();
    log.debug("OSHI library output (SystemCpuLoadTicks): " + Arrays.toString(loadTicks));    

    long idleTicks = loadTicks[CentralProcessor.TickType.IDLE.getIndex()];
    long stealTicks = loadTicks[CentralProcessor.TickType.STEAL.getIndex()];
    long systemTicks = loadTicks[CentralProcessor.TickType.SYSTEM.getIndex()]
            + loadTicks[CentralProcessor.TickType.IRQ.getIndex()]
            + loadTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()];
    long userTicks = loadTicks[CentralProcessor.TickType.USER.getIndex()];
    long timeStamp = idleTicks + stealTicks + systemTicks + userTicks;


    Map<String, WindowsRawData.CpuPerf> cpusPerfMap = ImmutableMap.of("_Total", WindowsRawData.CpuPerf.builder()
            .timestamp(timeStamp)
            .idleTicks(idleTicks)
            .stealTicks(stealTicks)
            .systemTicks(systemTicks)
            .userTicks(userTicks)
            .build());
    
    rawData.setCpusPerf(cpusPerfMap);
    log.debug("OSHI library output (cpusPerf): " + rawData.getCpusPerf());
}

Output :

appdynamics-infraviz-win-xlqnf==> [extension-scheduler-pool-0] 06 Mar 2022 22:52:05,933 DEBUG WindowsRawCollector - OSHI library output (SystemCpuLoadTicks): [0, 0, 0, 0, 0, 0, 0, 0]

appdynamics-infraviz-win-xlqnf==> [extension-scheduler-pool-0] 06 Mar 2022 22:52:05,933 DEBUG WindowsRawCollector - OSHI library output (cpusPerf): {_Total=WindowsRawData.CpuPerf(timestamp=0, idleTicks=0, stealTicks=0, systemTicks=0, userTicks=0)}

And addition I am getting below Error in log, please check :

appdynamics-infraviz-win-xlqnf==> [extension-scheduler-pool-4] 03 Mar 2022 03:08:02,993 ERROR HkeyPerformanceDataUtil - Unable to locate English counter names in registry Perflib 009. Counters may need to be rebuilt:
com.sun.jna.platform.win32.Win32Exception: The system cannot find the file specified.
at com.sun.jna.platform.win32.Advapi32Util.registryGetStringArray(Advapi32Util.java:948) ~[jna-platform-5.8.0.jar:5.8.0 (b0)]
at com.sun.jna.platform.win32.Advapi32Util.registryGetStringArray(Advapi32Util.java:923) ~[jna-platform-5.8.0.jar:5.8.0 (b0)]
at com.sun.jna.platform.win32.Advapi32Util.registryGetStringArray(Advapi32Util.java:897) ~[jna-platform-5.8.0.jar:5.8.0 (b0)]
at oshi.driver.windows.registry.HkeyPerformanceDataUtil.mapCounterIndicesFromRegistry(HkeyPerformanceDataUtil.java:301) ~[oshi-core-5.7.4.jar:5.7.4]
at oshi.driver.windows.registry.HkeyPerformanceDataUtil.(HkeyPerformanceDataUtil.java:69) ~[oshi-core-5.7.4.jar:5.7.4]
at oshi.driver.windows.registry.ProcessPerformanceData.buildProcessMapFromRegistry(ProcessPerformanceData.java:69) ~[oshi-core-5.7.4.jar:5.7.4]
at oshi.software.os.windows.WindowsOperatingSystem.queryProcessMapFromRegistry(WindowsOperatingSystem.java:333) ~[oshi-core-5.7.4.jar:5.7.4]
at oshi.util.Memoizer$1.get(Memoizer.java:87) [oshi-core-5.7.4.jar:5.7.4]
at oshi.software.os.windows.WindowsOperatingSystem.processMapToList(WindowsOperatingSystem.java:303) [oshi-core-5.7.4.jar:5.7.4]
at oshi.software.os.windows.WindowsOperatingSystem.queryAllProcesses(WindowsOperatingSystem.java:265) [oshi-core-5.7.4.jar:5.7.4]
at oshi.software.common.AbstractOperatingSystem.getProcesses(AbstractOperatingSystem.java:107) [oshi-core-5.7.4.jar:5.7.4]
at oshi.software.os.OperatingSystem.getProcesses(OperatingSystem.java:271) [oshi-core-5.7.4.jar:5.7.4]
at com.appdynamics.sim.agent.extensions.servers.model.windows.WindowsRawCollector.fillOshiData(WindowsRawCollector.java:139) [servers-22.1.0-3252.jar:?]
at com.appdynamics.sim.agent.extensions.servers.model.windows.WindowsRawCollector.collectRawData(WindowsRawCollector.java:101) [servers-22.1.0-3252.jar:?]
at com.appdynamics.sim.agent.extensions.servers.model.windows.WindowsRawCollector.collectRawData(WindowsRawCollector.java:47) [servers-22.1.0-3252.jar:?]
at com.appdynamics.sim.agent.extensions.servers.model.Server.collectAndReport(Server.java:65) [servers-22.1.0-3252.jar:?]
at com.appdynamics.sim.agent.extensions.servers.ServersDataCollector.run(ServersDataCollector.java:94) [servers-22.1.0-3252.jar:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_292]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_292]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_292]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_292]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_292]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_292]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_292]

Activity

  1. dbwiddis commented on Mar 15, 2022

    @dbwiddis
    Member

    The stack trace indicates the cause of the error:

    Unable to locate English counter names in registry Perflib 009. Counters may need to be rebuilt:

    Try the following commands:

    cd \windows\system32
    lodctr /R
    

    Please see https://docs.microsoft.com/en-us/troubleshoot/windows-server/performance/rebuild-performance-counter-library-values

  2. changed the title [-]CPU usage reporting as 100% on windows containers[/-] [+]Windows containers don't have Performance Counters in registry[/+] on Mar 15, 2022
  3. dbwiddis commented on Mar 15, 2022

    @dbwiddis
    Member

    So there are two errors here:

    1. The 0 values from the performance counters indicate Windows is failing to read those counter values. I'm surprised there are no associated log messages with those, such as in 2 warnings from SLF4J: Disabling further attempts to query PhysicalDisk + WmiQueryHandler COM exception: Invalid Class #1811.
    2. The stack trace is from the HKeyPerformanceDataUtil that attempts to read process and thread counter information directly from the registry. This is failing, but it is used when fetching process (or thread) counter data, not CPU ticks. I was going to suggest calling GlobalConfig.get(GlobalConfig.OSHI_OS_WINDOWS_HKEYPERFDATA, false); at the beginning of your code, which will bypass the registry and use the performance counter API directly, but the 0 values above seem to indicate that the API eventually calls these registry values anyway.

    Bottom line: the counters are corrupt/missing in this container. It looks like rebuilding them fixes the problem, but I don't know why they would be missing in the first place.

  4. dbwiddis commented on Mar 15, 2022

    @dbwiddis
    Member

    See this issue: microsoft/ApplicationInsights-dotnet-server#676

    It seems isolation in the container is the root cause and a suggested fix is to add this line to the Dockerfile and grant permissions to the IIS executing user.

    RUN net localgroup 'Performance Monitor Users' /add 'IIS APPPOOL\DefaultAppPool'
    
  5. added
    external dependency
    design discussion
    compatibility
    on Mar 15, 2022
  6. RajeshBabuJangili commented on Mar 17, 2022

    @RajeshBabuJangili
    Author

    Hi Daniel, Thank you for your response, we recommend to the customer what you suggested and keep you updated.

  7. dbwiddis commented on Mar 18, 2022

    @dbwiddis
    Member

    If their container is different than the one in the issue the solution is likely different. Also advised would be to make sure they have the most recent version of everything....

  8. RajeshBabuJangili commented on Mar 31, 2022

    @RajeshBabuJangili
    Author

    Hi Daniel,

    Customer team tried adding line to Dockerfile:
    RUN net localgroup 'Performance Monitor Users' /add 'IIS APPPOOL\DefaultAppPool'

    but it fails with the error message below. Based on the issue link, the solution worked on a subset of container types (windows container we're using is: mcr.microsoft.com/windows/servercore:ltsc2019)

    Step 13/16 : RUN net localgroup 'Performance Monitor Users' /add 'IIS APPPOOL\DefaultAppPool'
    ---> Running in f0c20feb0e69
    There is no such global user or group: IIS APPPOOL\DefaultAppPool.

    More help is available by typing NET HELPMSG 3783.

    The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; $verbosePreference='Continue'; net localgroup 'Performance Monitor Users' /add 'IIS APPPOOL\DefaultAppPool'' returned a non-zero code: 1


    Also tried adding

    RUN cd \windows\system32
    RUN lodctr /R

    to rebuild counters, which completes successfully, but CPU usage is still 100% for resulting image

    Step 13/17 : RUN cd \windows\system32
    ---> Running in 9aedfb14ad40
    Removing intermediate container 9aedfb14ad40
    ---> 7a48c2f24043
    Step 14/17 : RUN lodctr /R
    ---> Running in 449e29ceab34

    Info: Successfully rebuilt performance counter setting from system backup storeRemoving intermediate container 449e29ceab34
    ---> 0c3be7d7502b

    Please suggest us next steps.

  9. dbwiddis commented on Mar 31, 2022

    @dbwiddis
    Member

    Unfortunately I'm at a loss here. The proposed solutions were for one type of container but it's not clear what container the customer is using. The "100% CPU" is a symptom based on your implementation; the root cause from OSHI's perspective is that the performance counters are all 0.

    The log message you posted at the top is based on a completely different OSHI API call.

    The bottom line here is that there seems to be an issue reading Performance Counter data from inside the container; This is likely something to do with container configuration. and should probably be addressed in a support forum for that container system.

    OSHI attempts to get data either directly from the counters or from a WMI table that matches the counters, and it is failing here on both counts; there is nowhere else to get that data.

  10. dbwiddis commented on Apr 4, 2022

    @dbwiddis
    Member

    From this page:

    Windows provides a wide variety of performance counters such as processor, memory, and disk usage statistics. You can also define your own performance counters. Performance counters collection is supported as long as your application is running under IIS on an on-premises host, or virtual machine to which you have administrative access. Though applications running as Azure Web Apps don't have direct access to performance counters, a subset of available counters are collected by Application Insights.

    It appears a permissions issue may be the root cause. In order to even attempt to work around that I will need a lot more information about which "subset" is available.

  11. jeffaholmes commented on Apr 6, 2022

    @jeffaholmes
  12. dbwiddis commented on Apr 7, 2022

    @dbwiddis
    Member

    Note from this article from appdynamics:

    Engineers who are used to debugging apps in a traditional Windows environment find that valuable tools like Event Tracing for Windows (ETW) and performance counters are not consistently available.

    I simply don't know where to get the equivalent information inside a container.

    This may be something you want to ask about on an appdynamics support forum to see what alternatives there are.

  13. dbwiddis commented on Apr 7, 2022

    @dbwiddis
    Member

    It looks like this site gives instructions on exposing Windows performance counters to inside AppDynamics.

    You can look at the classes in the oshi.driver.windows.perfmon package to see what counters OSHI reads, and configure them. https://github.com/oshi/oshi/tree/master/oshi-core/src/main/java/oshi/driver/windows/perfmon

  14. added
    containers
    on Jul 6, 2022
  15. dbwiddis commented on Oct 13, 2022

    @dbwiddis
    Member

    Closing this issue as the last comment gave instructions to resolve and there haven't been any further updates in 6 months. Feel free to reopen if you are still experiencing problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compatibilitycontainersdesign discussionexternal dependency

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions