Example #1
0
        private void NetInterfacePerfMonitor_Load(object sender, EventArgs e)
        {
            ShowInterfaceSpeedAndQueue();
            int kk = 0;
            PerformanceCounterCategory categoryInstance = new PerformanceCounterCategory("Network Interface");

            foreach (string strInstanceName in categoryInstance.GetInstanceNames())
            {
                System.Windows.Forms.Application.DoEvents();
                NetInterfaceChart.Series.Add(strInstanceName);
                NetInterfaceChart.Series[strInstanceName].ChartType       = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
                NetInterfaceChart.Series[strInstanceName].YAxisType       = System.Windows.Forms.DataVisualization.Charting.AxisType.Primary;
                NetInterfaceChart.Series[strInstanceName].YValueType      = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
                NetInterfaceChart.Series[strInstanceName].IsXValueIndexed = false;
                //NetInterfaceChart.Series[strInstanceName].IsValueShownAsLabel = false;
                //NetInterfaceChart.Series[strInstanceName].IsVisibleInLegend = false;
                kk++;
            }
            NetInterfaceChart.ResetAutoValues();
            NetInterfaceChart.ChartAreas[0].AxisY.Maximum = 1024 * 1000;//Max Y
            NetInterfaceChart.ChartAreas[0].AxisY.Minimum = 0;
            NetInterfaceChart.ChartAreas[0].AxisX.Enabled = System.Windows.Forms.DataVisualization.Charting.AxisEnabled.False;
            System.Timers.Timer[] scanLiveTimer = new System.Timers.Timer[kk];
            performanceCounter = new PerformanceCounter[kk];
            Netname            = new String[kk];
            for (int i = 0; i < kk; i++)
            {
                Netname[i]                         = NetInterfaceChart.Series[i].Name.ToString();
                performanceCounter[i]              = new System.Diagnostics.PerformanceCounter();
                performanceCounter[i].MachineName  = Dns.GetHostName();
                performanceCounter[i].CategoryName = "Network Interface";
                performanceCounter[i].CounterName  = "Bytes Total/sec";
                performanceCounter[i].BeginInit();
                performanceCounter[i].InstanceName = Netname[i];
                scanLiveTimer[i] = new System.Timers.Timer();
                int x = i;
                System.Diagnostics.PerformanceCounter performanceCounterx = performanceCounter[i];
                scanLiveTimer[i].Elapsed += new System.Timers.ElapsedEventHandler((senderx, ex) => ScanMarketEvent(x, performanceCounterx));
                scanLiveTimer[i].Interval = 1000;
                scanLiveTimer[i].Start();
            }
        }
Example #2
0
 public void SetChart(int si, int val)
 {
     try
     {
         if (NetInterfaceChart.InvokeRequired)
         {
             NetInterfaceChart.BeginInvoke((Action)(() =>
             {
                 NetInterfaceChart.Series[si].Points.AddY(val.ToString());
                 if (NetInterfaceChart.Series[si].Points.Count > 40)
                 {
                     NetInterfaceChart.Series[si].Points.RemoveAt(0);
                 }
                 NetInterfaceChart.Series[si].Name = String.Format("{0} {1} Bytes Total/Sec", Netname[si], val);
                 NetInterfaceChart.Update();
             })
                                           );
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
 }