【问题标题】:Performance monitor on VpnVpn 上的性能监视器
【发布时间】:2012-10-07 07:15:24
【问题描述】:

我在我的 C# 项目中使用 Windows 性能监视器类来测量通过网卡发送的字节等,一切似乎都很好。我正在使用网络索引号来确定用于记录性能数据的网络接口。我可以通过命令提示符查看网络索引号(netsh int ipv4 show int)

但是,我已连接到 vpn 并将网络索引号更改为引用 vpn,当我尝试读取性能监视器“nextValue()”时出现异常。

所以我的问题是,我可以使用“System.Diagnostic.PerformanceCounters”来获取从 VPN 发送的数据包等,还是有其他方法可以做到这一点?

【问题讨论】:

    标签: c# windows networking


    【解决方案1】:

    尝试使用 powershell 性能计数器,它们的功能非常强大...

    power shell 命令(import-counter)的方法指南可以在这里找到..

    http://ss64.com/ps/

    我在下面添加了一些示例代码供您查看它们是如何调用的:

    private static void LoadBLG(string CounterPath)
            {
                PowerShell ps = PowerShell.Create();
                ps.AddCommand("import-counter");
                ps.AddArgument(CounterPath);
    
                Console.WriteLine(CounterPath);
                Console.WriteLine("------------------------");
    
                foreach (PSObject result in ps.Invoke())
                {
                    if (result.ImmediateBaseObject is PerformanceCounterSampleSet)
                    {
                        PerformanceCounterSampleSet Counters = result.ImmediateBaseObject as PerformanceCounterSampleSet;
                        foreach (PerformanceCounterSample sample in Counters.CounterSamples)
                            Console.WriteLine("{0,-20}{1}",
                                sample.Path, sample.RawValue);
                    }
                } // End foreach.
    

    祝你好运 马修

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-12
      • 1970-01-01
      相关资源
      最近更新 更多