Unable to pull all CPUs status using VB.net program against a remote server with 8 cores. Only see up to 4 cores

Martin Ng 21 Reputation points
2023-02-16T01:04:45.56+00:00

The following is a working script (modified) that has been running well for remote servers with up to 4 cores. When I recently need to monitor a server(database server running Windows 2019) with 8 cores, somehow, I could only get up to 4 cores status and the loop (For Each objProc In colCPUSystems) stops at counter, proc=4. I was expecting it to reach 8, because the server was configured with 8 cores.

No sure the problem here and hope someone could help.

Thank you.

Martin

Dim strComputer = "Server_A"
        Dim arrProcessors : ReDim arrProcessors(2, 0)
        Dim PLoad(16) As Integer
        Dim objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Dim colCPUSystems = objWMIService.ExecQuery("Select AddressWidth,DataWidth,NumberOfCores,Name,MaxClockSpeed,LoadPercentage from Win32_Processor")
        Dim proc = 0
        For Each objProc In colCPUSystems
            arrProcessors(0, proc) = objProc.NumberOfCores
            arrProcessors(1, proc) = objProc.MaxClockSpeed
            arrProcessors(2, proc) = objProc.LoadPercentage
            proc = proc + 1
            ReDim Preserve arrProcessors(2, proc)
        Next
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,805 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Martin Ng 21 Reputation points
    2023-02-16T15:46:05.83+00:00

    Thank you Viorel,

    I have replaced the 'NumberOfCores' with 'NumberOfLogicalProcessors' in the GetObject statement, and in the objProc loop, but the script still ends at 4. Still couldn't pass above 4 in the colCPUSystems loop when I ran it. I have attached the change as follows.

    Dim strComputer = "Server_A"
            Dim arrProcessors : ReDim arrProcessors(2, 0)
            Dim PLoad(16) As Integer
            Dim objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
            Dim colCPUSystems = objWMIService.ExecQuery("Select AddressWidth,DataWidth,NumberOfLogicalProcessors,Name,MaxClockSpeed,LoadPercentage from Win32_Processor")
            Dim proc = 0
            For Each objProc In colCPUSystems
                arrProcessors(0, proc) = objProc.NumberOfLogicalProcessors
                arrProcessors(1, proc) = objProc.MaxClockSpeed
                arrProcessors(2, proc) = objProc.LoadPercentage
                proc = proc + 1
                ReDim Preserve arrProcessors(2, proc)
            Next
    

  2. Martin Ng 21 Reputation points
    2023-02-16T21:25:30.5966667+00:00

    It tuned out both Viorel's suggestion and my original are good. It was the server that was configured with Socket=4 and Virtual Processor=8 under the Task Manager screen. The Socket parameter will need to be 8 in order for the vb code to pull all 8 cores cpu status. I tested the same vb code on a different server which gave correct no. of cores cpu status, and I found out that the Socket and Virtual Processors are equal to 8. Lucky day. Now, I will work with our infrastructure team to resolve the issue for it is more like a configuration issue.

    Thank you for helping in this matter.

    Martin

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.