用于获取正在运行的服务器的性能的 WMI 查询

发布于 2024-10-23 00:40:43 字数 862 浏览 1 评论 0原文

我可以使用哪个 WMI 查询来获取正在运行的 httpd 服务的性能信息?

hres = pSvc->ExecQuery(
        bstr_t("WQL"), 
        bstr_t("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process Where Name='httpd'"),
        WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
        NULL,
        &pEnumerator);


    IWbemClassObject *pclsObj;  
    ULONG uReturn = 0;

    while (pEnumerator)
    {
        HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 
            &pclsObj, &uReturn);


        if(0 == uReturn)
        {
            break;
        }

        VARIANT vtProp;

        // Get the value of the Name property
        hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);

        wcout << " test : " << vtProp.bstrVal << endl;

        VariantClear(&vtProp);

        pclsObj->Release();     
    }

Which WMI query can I use to get the performance information of a running httpd service?

hres = pSvc->ExecQuery(
        bstr_t("WQL"), 
        bstr_t("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process Where Name='httpd'"),
        WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
        NULL,
        &pEnumerator);


    IWbemClassObject *pclsObj;  
    ULONG uReturn = 0;

    while (pEnumerator)
    {
        HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 
            &pclsObj, &uReturn);


        if(0 == uReturn)
        {
            break;
        }

        VARIANT vtProp;

        // Get the value of the Name property
        hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);

        wcout << " test : " << vtProp.bstrVal << endl;

        VariantClear(&vtProp);

        pclsObj->Release();     
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┾廆蒐ゝ 2024-10-30 00:40:43

只需在此代码中添加进程名称过滤器:

strComputer ="."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfProc_Process",,48)

        wscript.echo "Computer Name" & "," & "Process Name" & ","& "CPU Usage"
For Each objItem in colProcesses
if objItem.Name <> "Idle"  and objItem.Name <> "_Total" then 
        wscript.echo strcomputer & "," & objItem.Name & ","& objItem.PercentProcessorTime
end if
Next

Just add filter for Process Name in this code:

strComputer ="."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfProc_Process",,48)

        wscript.echo "Computer Name" & "," & "Process Name" & ","& "CPU Usage"
For Each objItem in colProcesses
if objItem.Name <> "Idle"  and objItem.Name <> "_Total" then 
        wscript.echo strcomputer & "," & objItem.Name & ","& objItem.PercentProcessorTime
end if
Next
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文