简体   繁体   English

Vpn上的性能监视器

[英]Performance monitor on Vpn

I am using the windows performance monitor classes in my C# project to measure bytes sents etc via the network card and all seems fine. 我正在使用我的C#项目中的Windows性能监视器类来测量通过网卡的字节数等,一切似乎都很好。 I am using the network index number to determine the network interface to use to record performance data. 我使用网络索引号来确定用于记录性能数据的网络接口。 I can see the network index numbers via the command prompt (netsh int ipv4 show int) 我可以通过命令提示符看到网络索引号(netsh int ipv4 show int)

However, I have connected to the vpn and changed the network index number to refer to the vpn and when I try to read the performance monitor "nextValue()" I get an exception. 但是,我已连接到vpn并更改了网络索引号以引用vpn,当我尝试读取性能监视器“nextValue()”时,我得到一个异常。

So my question is, can I use the "System.Diagnostic.PerformanceCounters" to get packets sent etc from the VPN or is there another way to do this? 所以我的问题是,我可以使用“System.Diagnostic.PerformanceCounters”从VPN发送数据包等,还是有其他方法可以做到这一点?

Try to use the powershell performance counters, they have a lot of power... 尝试使用powershell性能计数器,它们有很多功能......

The way guide to the power shell commands (import-counter) can be found here.. 可以在这里找到power shell命令(import-counter)的指南。

http://ss64.com/ps/ http://ss64.com/ps/

I have added some example code below for you to see how they are called: 我在下面添加了一些示例代码,以便了解它们的调用方式:

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.

Good luck Matthew 祝你好运马修

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM