使用C#客户端与WMI远程连接时无法检索ASP.NET指标 [英] Cannot retrieve ASP.NET metrics when connecting remotely with WMI using a C# client

查看:74
本文介绍了使用C#客户端与WMI远程连接时无法检索ASP.NET指标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只有部分代码。 但除了时间戳之外,所有相关值都返回0。



            System.Management.ManagementScope managementScope1 = new System.Management.ManagementScope(string.Format(" \\\\ {0} \\root \\cimv2",strIP),options);

            managementScope1.Connect();



            var query = new ObjectQuery(" SELECT  * FROM Win32_PerfRawData_ASPNET_ASPNETApplications");

            // var query = new ObjectQuery(" select * from Win32_PerfFormattedData_PerfOS_Processor");

            // var query = new ObjectQuery(" select * from Win32_PerfRawData_W3SVC_WebService");



$
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(managementScope1,query);



            foreach(Searcher.Get()中的ManagementObject obj)

            {

                // var usage = obj [" PercentProcessorTime"];

                // var name = obj [" Name"];

                //Console.WriteLine(name +":" + usage);



                foreach(obj.Properties中的var propertyData)

                {

                    Console.WriteLine(" {0}:{1}",propertyData.Name,propertyData.Value);

                }


                Console.WriteLine("完成");



                //Console.WriteLine(obj.ToString());

            }


            

解决方案



您好yanguchong,


> ;>使用C#客户端与WMI远程连接时无法检索ASP.NET指标


以下代码是如何使用C#远程连接到WMI并获取一些指标。

 ConnectionOptions options = new ConnectionOptions(); 
options.Impersonation = System.Management.ImpersonationLevel.Impersonate;
ManagementScope scope = new ManagementScope("\\\\.XXX.XXX.XXX \\\\\\\\\\\\\\\\
scope.Connect();

//操作系统信息的查询系统
ObjectQuery query = new ObjectQuery(" SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(范围,查询);
ManagementObjectCollection queryCollection = searcher.Get();
StringBuilder sb = new StringBuilder();
foreach(queryObject在queryCollection中)
{
//显示远程计算机信息
sb.AppendLine(" Computer Name" + m [" csname"]) ;
sb.AppendLine(" Windows Directory:" + m [" WindowsDirectory"]);
sb.AppendLine(" Operating System:" + m [" Caption"]);
sb.AppendLine(" Version:" + m [" Version"]);
sb.AppendLine(" Computer Name" + m [" csname"]);
sb.AppendLine("制造商:" + m ["制造商]]);

//Console.WriteLine("Computer Name:{0}",m [" csname"]);
//Console.WriteLine("Windows Directory:{0}",m [" WindowsDirectory"]);
//Console.WriteLine("Operating System:{0}",m [" Caption"]);
//Console.WriteLine("Version:{0}",m [" Version"]);
//Console.WriteLine("Manufacturer:{0}",m [" Manufacturer"]);
}
MessageBox.Show(sb.ToString());





您可以参考以下链接获取详细信息。


正在连接到WMI远程使用C#:

以获取有关如何检索ASP.NET指标的详细信息。


我发现以下链接提供了解决方案。对您有所帮助。


安装.NET 4.5后,ASP.NET性能数据不可用:

https://support.microsoft.com/en-us/help / 2869514 / asp-net-performance-data-not-available-installed-installed-net-4-5


如果你有一般的WMI问题,你可以访问以下论坛。


官方脚本专家论坛

http://social.technet.microsoft.com/Forums/en-US/ITCG/threads




另外,如果您认为这是一个错误,我建议您在Connect上报告您的问题:

https:// connect.microsoft.com/




最好的问候,


Yohann Lu









Only a partial of the code.  But all pertinent values return 0 except for timestamps.

            System.Management.ManagementScope managementScope1 = new System.Management.ManagementScope(string.Format("\\\\{0}\\root\\cimv2", strIP), options);
            managementScope1.Connect();

            var query = new ObjectQuery("SELECT  * FROM Win32_PerfRawData_ASPNET_ASPNETApplications");
            //var query = new ObjectQuery("select * from Win32_PerfFormattedData_PerfOS_Processor");
            //var query = new ObjectQuery("select * from Win32_PerfRawData_W3SVC_WebService");


            ManagementObjectSearcher searcher = new ManagementObjectSearcher(managementScope1, query);

            foreach (ManagementObject obj in searcher.Get())
            {
                //var usage = obj["PercentProcessorTime"];
                //var name = obj["Name"];
                //Console.WriteLine(name + " : " + usage);

                foreach (var propertyData in obj.Properties)
                {
                    Console.WriteLine("{0}:{1}", propertyData.Name, propertyData.Value);
                }

                Console.WriteLine("done");

                //Console.WriteLine(obj.ToString());
            }

            

解决方案


Hi yanguchong,

>>Cannot retrieve ASP.NET metrics when connecting remotely with WMI using a C# client

The following code is how to Connecting to WMI Remotely with C# and get some metrics.

            ConnectionOptions options = new ConnectionOptions();
            options.Impersonation = System.Management.ImpersonationLevel.Impersonate;
            ManagementScope scope = new ManagementScope("\\\\12.XXX.XXX.XXX\\root\\cimv2", options);
            scope.Connect();

            //Query system for Operating System information
            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
            ManagementObjectCollection queryCollection = searcher.Get();
            StringBuilder sb = new StringBuilder();
            foreach (ManagementObject m in queryCollection)
            {
                // Display the remote computer information
                sb.AppendLine("Computer Name "+ m["csname"]);
                sb.AppendLine("Windows Directory : "+ m["WindowsDirectory"]);
                sb.AppendLine("Operating System: "+ m["Caption"]);
                sb.AppendLine("Version:"+ m["Version"]);
                sb.AppendLine("Computer Name " + m["csname"]);
                sb.AppendLine("Manufacturer :" + m["Manufacturer"]);

                //Console.WriteLine("Computer Name     : {0}", m["csname"]);
                //Console.WriteLine("Windows Directory : {0}", m["WindowsDirectory"]);
                //Console.WriteLine("Operating System  : {0}", m["Caption"]);
                //Console.WriteLine("Version           : {0}", m["Version"]);
                //Console.WriteLine("Manufacturer      : {0}", m["Manufacturer"]);
            }
            MessageBox.Show(sb.ToString());


You can refer the following links to getting detailed information.

Connecting to WMI Remotely with C#:
https://msdn.microsoft.com/en-us/library/mt703458(v=vs.85).aspx

ManagementScope.Connect Method ():
https://msdn.microsoft.com/en-us/library/system.management.managementscope.connect(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2

ASP.NET WMI Provider:
https://msdn.microsoft.com/en-us/library/dn776414(v=vs.85).aspx


>>Only a partial of the code.  But all pertinent values return 0 except for timestamps.

I also test your code. It can get some information. So, I think there is no problem to connect the remote machine to get the performance counter information.

I suggest you can ask your issue in the ASP.NET forum to get detailed information about how to retrieve ASP.NET metrics.

I found the following link give a solution. May be helpful for you.

ASP.NET performance data not available after installing .NET 4.5:
https://support.microsoft.com/en-us/help/2869514/asp-net-performance-data-not-available-after-installing--net-4-5

If you have some General WMI issue, you can visit the following forum.

The Official Scripting Guys Forum
http://social.technet.microsoft.com/Forums/en-US/ITCG/threads


Also, If you think it is a bug, I suggest you can report your question at Connect:
https://connect.microsoft.com/


Best Regards,

Yohann Lu


这篇关于使用C#客户端与WMI远程连接时无法检索ASP.NET指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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