Windows Forms: Create CPU and RAM Monitor with Real time Charts in C#

This tutorial shows you how to create CPU and RAM monitor with real time charts using Metro Framework, Performance Counter and Chart controls in C# .NET Windows Forms Application.

Ram and CPU Meter is a small application which resides on your desktop and provides useful information about your computer's processor and memory usage.

The PerformanceCounter component provides information as to how well the operating system or an application, service or driver is performing. You should use the Performance Counters API when you want to provide or consume counter data.

Drag the MetroLabel, MetroProgressBar and Chart controls from your visual studio toolbox to your winform, then you can layout your UI as shown below.

To create a metro form using MetroFramework you should change inherit from your Form to MetroForm.

If you don't see the metro framework in your visual toolbox, you can view How to download and install metro framework

cpu and ram monitor with real time chart

Add the Timer and PerformanceCounter controls to your metro form, then add a tick event handler to the timer control allows you to update your real time chart as the following c# code.

private void timer_Tick(object sender, EventArgs e)
{
    float fcpu = pCPU.NextValue();
    float fram = pRAM.NextValue();
    //Set value to cpu and ram
    metroProgressBarCPU.Value = (int)fcpu;
    metroProgressBarRAM.Value = (int)fram;
    //Update value to cpu and ram label
    lblCPU.Text = string.Format("{0:0.00}%", fcpu);
    lblRAM.Text = string.Format("{0:0.00}%", fram);
    //Draw cpu and ram chart
    chart1.Series["CPU"].Points.AddY(fcpu);
    chart1.Series["RAM"].Points.AddY(fram);
}

And don't forget to call the Start method of the timer in your Form_Load event as shown below.

private void Form1_Load(object sender, EventArgs e)
{
    timer.Start();
}

VIDEO TUTORIAL