在没有WMI的Windows中查找MaxNumberOfProcess [英] Find MaxNumberOfProcesses in Windows without WMI

查看:11
本文介绍了在没有WMI的Windows中查找MaxNumberOfProcess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的监控解决方案目前使用WMI作为其少数指标,但在负载下,WMI性能很差,经常无法及时返回,导致大量各种情况下线或指标缺失的错误警报。

用在psapi.h、sysinfoapi.h等中找到的Windows函数调用替换WMI查询已经解决了大部分问题,返回速度提高了大约100倍,但我找不到一种方法来获得等同于WMI查询Win32_OperatingSystem.MaxNumberOfProcesses

的值

Windows文档here中的定义如下:

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.

我在大约10台不同的机器上测试了这个值,每台机器都有不同数量的中央处理器和内存,所有这些机器都返回了上面的缺省值4294967295(0xFFFFFFFFF)。我是应该假定Windows实际上只是直接发回此值,还是应该返回ULONG_MAX的值,或者是否有其他方法可以找到此值应该是什么?

我尝试了一种访问Windows主机MIB的方法,但除了使用一些外部工具,而不是直接通过代码,我找不到任何有关它的详细信息。

我目前正在用Go语言编程,使用C库。

如果有人能够深入了解如何在不使用WMI的情况下检索此值,将不胜感激。

推荐答案

可以使用CIM_OperatingSystem classCIM(公共信息模型)https://docs.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;
};
DMTF(分布式管理任务组)CIM(公共信息 模型)类是WMI类所基于的父类 建造了。WMI当前仅支持CIM 2.x版架构。

如果计算机上的进程数不受限制MaxNumberOfProcesses0

操作系统可以支持的最大进程上下文数。如果没有固定的最大值,则该值应为0。在具有固定最大值的系统上,此对象可以帮助诊断达到最大值时发生的故障。

WMICIM的关系见https://www.red-gate.com/simple-talk/sysadmin/powershell/powershell-day-to-day-admin-tasks-wmi,-cim-and-pswa/

公共信息模型

从PowerShell的第三版开始,新增了一个模块 在Windows Server 2012和Windows 8中引入,称为 CIMCmdlet。添加它是为了替换旧的WMI cmdlet。 如果您经常使用WMI,那么在迁移到 新cmdlet,因为有很多相似之处。

要使用的第一个命令是Get-CimInstance:

PS> Get-CimInstance -Class Win32_Process

您会注意到,可以在WMI上发出请求 上课。简单总结一下:

Get-WmiObject is replaced by Get-CimInstance
Get-WmiObject -list is replaced by Get-CimClass

让我们详细了解CIM提供的新功能

命名空间:https://wutils.com/wmi/root/cimv2/properties/maxnumberofprocesses.html

这篇关于在没有WMI的Windows中查找MaxNumberOfProcess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆