2014-12-10 1 views
3

특정 응용 프로그램의 네트워크 대역폭 사용을 모니터링하는 방법을 배우려고합니다. IPv4InterfaceStatistics을보고 있는데 NIC 카드의 성능을 모니터하는 것 같습니다.
매초마다 얼마나 많은 대역폭이 소비되는지 확인하려면 특정 응용 프로그램을 모니터링하고 싶습니다.
이 작업을 수행하는 방법에 대한 예는 누구나 알고 있습니까? 당신은 당신이 층으로 상호 작용해야하는 위치는 레이어 3과 상호 작용을 시도 볼 http://en.wikipedia.org/wiki/OSI_model 당신은 OSI 모델에 익숙하다면특정 응용 프로그램의 네트워크 대역폭 사용을 모니터링하는 방법은 무엇입니까?

+0

Windows 용 리소스 모니터. –

+0

@DeepakMishra 나는 C#과 스택, serverfault가 아니기 때문에이 프로그래밍 방식으로 문제를 해결하려고한다. 그러나 나는 틀릴 수도있다. –

+0

예 프로그래밍 방식으로이 문제를 해결하고 싶습니다 –

답변

3
using System; 
using System.Diagnostics; 
using System.Globalization; 
using System.IO; 
using System.Net; 
using System.Net.Sockets; 
using System.Reflection; 
using System.Text; 
using System.Threading; 

namespace ConsoleApplication2 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      while (true) 
      { 
       var bytesSentPerformanceCounter = new PerformanceCounter(); 
       bytesSentPerformanceCounter.CategoryName = ".NET CLR Networking"; 
       bytesSentPerformanceCounter.CounterName = "Bytes Sent"; 
       bytesSentPerformanceCounter.InstanceName = GetInstanceName(); 
       bytesSentPerformanceCounter.ReadOnly = true; 

       var bytesReceivedPerformanceCounter = new PerformanceCounter(); 
       bytesReceivedPerformanceCounter.CategoryName = ".NET CLR Networking"; 
       bytesReceivedPerformanceCounter.CounterName = "Bytes Received"; 
       bytesReceivedPerformanceCounter.InstanceName = GetInstanceName(); 
       bytesReceivedPerformanceCounter.ReadOnly = true; 

       Console.WriteLine("Bytes sent: {0}", bytesSentPerformanceCounter.RawValue); 
       Console.WriteLine("Bytes received: {0}", bytesReceivedPerformanceCounter.RawValue); 
       Thread.Sleep(1000); 
      } 
     } 

     private static string GetInstanceName() 
     { 
      string returnvalue = "not found"; 
      //Checks bandwidth usage for CUPC.exe..Change it with your application Name 
      string applicationName = "CUPC"; 
       PerformanceCounterCategory[] Array = PerformanceCounterCategory.GetCategories(); 
      for (int i = 0; i < Array.Length; i++) 
      { 
       if (Array[i].CategoryName.Contains(".NET CLR Networking")) 
        foreach (var item in Array[i].GetInstanceNames()) 
        { 
         if (item.ToLower().Contains(applicationName.ToString().ToLower())) 
          returnvalue = item; 

        } 

      } 
      return returnvalue; 
     } 
    } 
} 
-1

7

나는 당신이 할 수있는 사용하는 지금까지 어떤 클래스와 연결 측정 바이트, 특히 개별 바이트를 전송하는 경우 (이것은 코드가 어떻게 보이는지 모르기 때문에), 초당 바이트 수를 나누어 계산할 수 있어야하며, 너의 결과.

관련 문제