private void LookupNic(Stat stat, GetIPv4StatValue getter, double factor)
        {
            // Get the one nic that has the name of this stat
            IEnumerable <NetworkInterface> nics = NetworkInterface.GetAllNetworkInterfaces().Where(
                (network) => network.Name == stat.Description);

            try
            {
                foreach (NetworkInterface nic in nics)
                {
                    IPv4InterfaceStatistics intrStats = nic.GetIPv4Statistics();
                    if (intrStats != null)
                    {
                        double newVal = Math.Round(getter(intrStats) / factor, 3);
                        stat.Value = newVal;
                    }
                    break;
                }
            }
            catch
            {
                // There are times interfaces go away so we just won't update the stat for this
                m_log.ErrorFormat("{0} Exception fetching stat on interface '{1}'", LogHeader, stat.Description);
            }
        }
예제 #2
0
 private void LookupNic(Stat stat, GetIPv4StatValue getter, double factor)
 {
     // Get the one nic that has the name of this stat
     IEnumerable<NetworkInterface> nics = NetworkInterface.GetAllNetworkInterfaces().Where(
                           (network) => network.Name == stat.Description);
     try
     {
         foreach (NetworkInterface nic in nics)
         {
             IPv4InterfaceStatistics intrStats = nic.GetIPv4Statistics();
             if (intrStats != null)
             {
                 double newVal = Math.Round(getter(intrStats) / factor, 3);
                 stat.Value = newVal;
             }
             break;
         }
     }
     catch
     {
         // There are times interfaces go away so we just won't update the stat for this
         m_log.ErrorFormat("{0} Exception fetching stat on interface '{1}'", LogHeader, stat.Description);
     }
 }