Repository navigation
Description
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
dbwiddis commentedon Mar 15, 2022
The stack trace indicates the cause of the error:
Try the following commands:
Please see https://docs.microsoft.com/en-us/troubleshoot/windows-server/performance/rebuild-performance-counter-library-values
[-]CPU usage reporting as 100% on windows containers[/-][+]Windows containers don't have Performance Counters in registry[/+]dbwiddis commentedon Mar 15, 2022
So there are two errors here:
HKeyPerformanceDataUtilthat 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 callingGlobalConfig.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.
dbwiddis commentedon Mar 15, 2022
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.
RajeshBabuJangili commentedon Mar 17, 2022
Hi Daniel, Thank you for your response, we recommend to the customer what you suggested and keep you updated.
dbwiddis commentedon Mar 18, 2022
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....
RajeshBabuJangili commentedon Mar 31, 2022
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.
dbwiddis commentedon Mar 31, 2022
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.
dbwiddis commentedon Apr 4, 2022
From this page:
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.
jeffaholmes commentedon Apr 6, 2022
This is the Dockerfile being use with info on specific base image:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
https://github.com/CiscoDevNet/appdynamics-docker-images/blob/master/appd-machine-agent-analytics/windows/Dockerfile
dbwiddis commentedon Apr 7, 2022
Note from this article from appdynamics:
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.
dbwiddis commentedon Apr 7, 2022
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.perfmonpackage to see what counters OSHI reads, and configure them. https://github.com/oshi/oshi/tree/master/oshi-core/src/main/java/oshi/driver/windows/perfmondbwiddis commentedon Oct 13, 2022
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.