Reputation: 693
Our monitoring solution currently uses WMI for a few of it's metrics, however when under load WMI performs terribly and often fails to return in time, causing a large number of false alerts of various things being offline or missing metrics.
Replacing WMI queries with calls to windows functions found in psapi.h, sysinfoapi.h and others has resolved a majority of these and return about 100x faster, however I am unable to find a way to get the equivalent value of WMI query Win32_OperatingSystem.MaxNumberOfProcesses
The definition from the windows documentation here states:
MaxNumberOfProcesses
Data type: uint32
Access type: Read-only
Qualifiers: MappingStrings ("MIB.IETF|HOST-RESOURCES-MIB.hrSystemMaxProcesses")
Maximum number of process contexts the operating system can support.
The default value set by the provider is 4294967295 (0xFFFFFFFF). If there is no fixed maximum, the value should be 0 (zero). On systems that have a fixed maximum, this object can help diagnose failures that occur when the maximum is reached—if unknown, enter 4294967295 (0xFFFFFFFF).
This property is inherited from CIM_OperatingSystem.
I've tested this value on about 10 different machines, each with differing numbers of CPU and RAM, all of which have returned the above default value of 4294967295 (0xFFFFFFFF). Am I to assume that Windows is actually just sending back this value directly, or should I be returning the value of ULONG_MAX, or is there another way of finding what this value should be?
I tried figure out a way to access the HOST MIB for windows but can't find any details on it other than using some external tool, not directly via code.
I'm currently programming this in the GO language, utilizing C libraries.
If anyone can provide insight into how to retrieve this value without using WMI that would be greatly appreciated.
Upvotes: 2
Views: 197
Reputation: 9432
You can use CIM_OperatingSystem class
CIM (Common Information Models) https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/cim-operatingsystem
[Abstract, UUID("{8502C565-5FBB-11D2-AAC1-006008C78BC7}"), AMENDMENT]
class CIM_OperatingSystem : CIM_LogicalElement
{
string Caption;
string CreationClassName;
string CSCreationClassName;
string CSName;
sint16 CurrentTimeZone;
string Description;
boolean Distributed;
uint64 FreePhysicalMemory;
uint64 FreeSpaceInPagingFiles;
uint64 FreeVirtualMemory;
datetime InstallDate;
datetime LastBootUpTime;
datetime LocalDateTime;
uint32 MaxNumberOfProcesses; <----------------------------------------
uint64 MaxProcessMemorySize;
string Name;
uint32 NumberOfLicensedUsers;
uint32 NumberOfProcesses;
uint32 NumberOfUsers;
uint16 OSType;
string OtherTypeDescription;
uint64 SizeStoredInPagingFiles;
string Status;
uint64 TotalSwapSpaceSize;
uint64 TotalVirtualMemorySize;
uint64 TotalVisibleMemorySize;
string Version;
};
The DMTF (Distributed Management Task Force) CIM (Common Information Model) classes are the parent classes upon which WMI classes are built. WMI currently supports only the CIM 2.x version schemas.
If the number of processes on a machine is not limited MaxNumberOfProcesses
is 0
Maximum number of process contexts the OperatingSystem can support. If there is no fixed maximum, the value should be 0. On systems that have a fixed maximum, this object can help diagnose failures that occur when the maximum is reached.
On the relation between WMI
and CIM
see https://www.red-gate.com/simple-talk/sysadmin/powershell/powershell-day-to-day-admin-tasks-wmi,-cim-and-pswa/
Common Information Model
Since the third version of PowerShell, a new module has been introduced in Windows Server 2012 and Windows 8 that is called CIMCmdlets. It has been added so as to replace the legacy WMI cmdlets. If you regularly use WMI, then you will not be lost when moving to the new cmdlets as there are lots of similarities.
The first command to use is Get-CimInstance:
PS> Get-CimInstance -Class Win32_Process
You will notice that it is possible to make requests on the WMI classes. To give a simple summary:
Get-WmiObject is replaced by Get-CimInstance Get-WmiObject -list is replaced by Get-CimClass
Let’s see in detail the new functionality presented by CIM
Namespace : https://wutils.com/wmi/root/cimv2/properties/maxnumberofprocesses.html
Upvotes: 2