2011-12-28 9 views
8

मैं 2 अलग-अलग सर्वरों में चल रहे किसी प्रोग्राम के लिए लोड बैलेंसर बनाने की कोशिश कर रहा हूं।किसी दिए गए समय में उपयोग की जाने वाली नेटवर्क बैंडविड्थ को कैसे जानें?

अब तक मेरा लोड बैलेंसर, प्रत्येक सर्वर प्रोग्राम में PerformanceCounter के उदाहरण का उपयोग करके प्रत्येक सर्वर के CPU उपयोग को केवल जांचता है।

मैं प्रत्येक सर्वर के बैंडविड्थ उपयोग को भी देखना चाहूंगा, मैं इसे कैसे देख सकता हूं?

(यह शायद PerformanceCounter का उपयोग कर भी किया जाता है, लेकिन मैं इसके उपयोग से अपरिचित हूँ)

+2

इस सवाल पर एक नज़रhttp://stackoverflow.com/questions/442409/c-bandwidth – Moonlight

उत्तर

17

धन्यवाद चांदनी मैं इस http://www.keyvan.ms/how-to-calculate-network-utilization-in-net

public double getNetworkUtilization(string networkCard){ 

      const int numberOfIterations = 10; 

      PerformanceCounter bandwidthCounter = new PerformanceCounter("Network Interface", "Current Bandwidth", networkCard); 
      float bandwidth = bandwidthCounter.NextValue();//valor fixo 10Mb/100Mn/ 

      PerformanceCounter dataSentCounter = new PerformanceCounter("Network Interface", "Bytes Sent/sec", networkCard); 

      PerformanceCounter dataReceivedCounter = new PerformanceCounter("Network Interface", "Bytes Received/sec", networkCard); 

      float sendSum = 0; 
      float receiveSum = 0; 

      for (int index = 0; index < numberOfIterations; index++) 
      { 
       sendSum += dataSentCounter.NextValue(); 
       receiveSum += dataReceivedCounter.NextValue(); 
      } 
      float dataSent = sendSum; 
      float dataReceived = receiveSum; 


      double utilization = (8 * (dataSent + dataReceived))/(bandwidth * numberOfIterations) * 100; 
      return utilization; 
     } 

पाया है उपलब्ध नेटवर्क कार्ड के लिए इस कोड को खोजने के लिए करने के लिए मुझे मदद की: :

public void printNetworkCards() 
     { 
      PerformanceCounterCategory category = new PerformanceCounterCategory("Network Interface"); 
      String[] instancename = category.GetInstanceNames(); 

      foreach (string name in instancename) 
      { 
       Console.WriteLine(name); 
      } 
     } 
संबंधित मुद्दे