Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[Preview] CPU and Ram Usage Meter

Hello everyone on HF. Im just showing off my little CPU and RAM meter that I made a few days ago
I got a new computer, and since my old computer had the widgets, I enjoyed using the cpu and ram meter on that. The computer was windows 7 by the way. And my new Windows 8 computer doesn't have that. Microsoft has canceled all widgets because of a security vulnerability with them. So I decided to make my own. Its simple.
Here is a picture of the Meter >
Spoiler (Click to View)
It also has a little menu from where you can exit or lock the widget to the screen >
Spoiler (Click to View)
Thanks for taking a look and if anyone would like it, I will post a download link along with a virus scan
Post the source, would be much more safe :)!
(Jan 27, 2014 10:13 PM)bonsai Wrote:  Post the source, would be much more safe :)!

I have this exact same thing on one of my programs I released here, the source is simply using a few performance counters to monitor each core separately.

[img]http://img15.imageshack.us/img15/1769/3l5l.png[/img]
I added 4 cores and 1 ram monitor, so you will need 5 performance counters.

Firstly, declare new integers via coding
Code
Dim ram as Integer
Dim core1 as Integer
Dim core2 as Integer
Dim core3 as Integer
Dim core4 as Integer

Now, create your first timer

Open timer1, and paste in this
Code
On Error Resume Next
      core1 = PerformanceCounter1.NextValue
      core2 = PerformanceCounter2.NextValue
      ram = PerformanceCounter3.NextValue
      core3 = PerformanceCounter4.NextValue
      core4 = PerformanceCounter5.NextValue
I added OERN because some people don't have 4 cores.

We're gonna start ram first, because CPU can be repeated.

For RAM
Spoiler (Click to View)

For the CPU
Spoiler (Click to View)

Performance counters are great for system monitoring.

Edit: I notice that my source is more in-depth with separate core monitoring, however his should be just as mine.
(Jan 27, 2014 11:49 PM)ecaep42 Wrote:  I have this exact same thing on one of my programs I released here, the source is simply using a few performance counters to monitor each core separately.

[img]http://img15.imageshack.us/img15/1769/3l5l.png[/img]
I added 4 cores and 1 ram monitor, so you will need 5 performance counters.

Firstly, declare new integers via coding
Code
Dim ram as Integer
Dim core1 as Integer
Dim core2 as Integer
Dim core3 as Integer
Dim core4 as Integer

Now, create your first timer

Open timer1, and paste in this
Code
On Error Resume Next
      core1 = PerformanceCounter1.NextValue
      core2 = PerformanceCounter2.NextValue
      ram = PerformanceCounter3.NextValue
      core3 = PerformanceCounter4.NextValue
      core4 = PerformanceCounter5.NextValue
I added OERN because some people don't have 4 cores.

We're gonna start ram first, because CPU can be repeated.

For RAM
Spoiler (Click to View)

For the CPU
Spoiler (Click to View)

Performance counters are great for system monitoring.

Edit: I notice that my source is more in-depth with separate core monitoring, however his should be just as mine.
Wow that looks really amazing. Im impressed. But yes mine Is pretty much the same just not as much since its only monitoring one cpu
Both examples lack Dynamic Multi-CPU support ;( (If that even makes sense, basically generating the performance counters based on how many CPU's can be counted :>)

I'll grab the source for the Dynamic CPU Monitor i wrote a while back, and edit my post w/ it's source. It could most likely be improved upon :P

Code
Dim performance As New List(Of PerformanceCounter)
    Dim CPULoad As New List(Of Label)
    Dim ProgressBar As New List(Of ProgressBar)
    Dim locationx As Integer = 12
    Dim locationy As Integer = 9

    Dim WithEvents Timer As New Timer With {.Interval = 500, .Enabled = True}

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

      Me.Size = New Size(300, 95)

      For i As Integer = 0 To System.Environment.ProcessorCount - 1

      Dim processor As New PerformanceCounter
      processor.CategoryName = "Processor"
      processor.CounterName = "% Processor Time"
      processor.InstanceName = i

      performance.Add(processor)

      Dim CPU As New Label
      CPU.Text = "Logical Processor #" + (i + 1).ToString
      CPU.AutoSize = True
      CPU.Location = New Point(locationx, locationy)

      Dim Progress As New ProgressBar
      Progress.Location = New Point(locationx, locationy + 16)
      Progress.Width = 221

      ProgressBar.Add(Progress)

      Dim Load As New Label
      Load.Text = "0%"
      Load.AutoSize = False
      Load.Size = New Size(33, 13)
      Load.Location = New Point(locationx + 227, locationy + 21)

      CPULoad.Add(Load)

      locationy += 51
      Me.Height += 45

      Me.Controls.AddRange({CPU, Progress, Load})

      Next
    End Sub

    Private Sub TimerTick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer.Tick
      For i As Integer = 0 To performance.Count - 1
      If ProgressBar(i).Value < performance(i).NextValue Then
      ProgressBar(i).Value += 1
      Else
      Try
      ProgressBar(i).Value -= 1
      Catch ex As Exception : End Try
      End If
      CPULoad(i).Text = ProgressBar(i).Value.ToString + "%"
      Next
    End Sub

That'll work if you through it into a Windows Form Application....Most likely.

It could be improved via fixing the Form Sizing (It's incredibly rough, i didn't do the math correctly, so unless the computer has 8 logical processors like mine, it won't look exactly right...), and instead of using 3 separate Lists of controls, possibly creating a single list of a custom class, which holds all the information related to the performance counter.

There also seems to be a problem with large CPU Activity Spikes (For example, i was going to provide a screenshot while i was encoding a video to make my CPU Activity spike, however it was essentially all 8 logical processors at 99% or 100%...), taking too long to update
(Jan 28, 2014 02:39 AM)Nikey646 Wrote:  Both examples lack Dynamic Multi-CPU support ;( (If that even makes sense, basically generating the performance counters based on how many CPU's can be counted :>)

I'll grab the source for the Dynamic CPU Monitor i wrote a while back, and edit my post w/ it's source. It could most likely be improved upon :P

Code
Dim performance As New List(Of PerformanceCounter)
    Dim CPULoad As New List(Of Label)
    Dim ProgressBar As New List(Of ProgressBar)
    Dim locationx As Integer = 12
    Dim locationy As Integer = 9

    Dim WithEvents Timer As New Timer With {.Interval = 500, .Enabled = True}

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

      Me.Size = New Size(300, 95)

      For i As Integer = 0 To System.Environment.ProcessorCount - 1

      Dim processor As New PerformanceCounter
      processor.CategoryName = "Processor"
      processor.CounterName = "% Processor Time"
      processor.InstanceName = i

      performance.Add(processor)

      Dim CPU As New Label
      CPU.Text = "Logical Processor #" + (i + 1).ToString
      CPU.AutoSize = True
      CPU.Location = New Point(locationx, locationy)

      Dim Progress As New ProgressBar
      Progress.Location = New Point(locationx, locationy + 16)
      Progress.Width = 221

      ProgressBar.Add(Progress)

      Dim Load As New Label
      Load.Text = "0%"
      Load.AutoSize = False
      Load.Size = New Size(33, 13)
      Load.Location = New Point(locationx + 227, locationy + 21)

      CPULoad.Add(Load)

      locationy += 51
      Me.Height += 45

      Me.Controls.AddRange({CPU, Progress, Load})

      Next
    End Sub

    Private Sub TimerTick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer.Tick
      For i As Integer = 0 To performance.Count - 1
      If ProgressBar(i).Value < performance(i).NextValue Then
      ProgressBar(i).Value += 1
      Else
      Try
      ProgressBar(i).Value -= 1
      Catch ex As Exception : End Try
      End If
      CPULoad(i).Text = ProgressBar(i).Value.ToString + "%"
      Next
    End Sub

That'll work if you through it into a Windows Form Application....Most likely.

It could be improved via fixing the Form Sizing (It's incredibly rough, i didn't do the math correctly, so unless the computer has 8 logical processors like mine, it won't look exactly right...), and instead of using 3 separate Lists of controls, possibly creating a single list of a custom class, which holds all the information related to the performance counter.

There also seems to be a problem with large CPU Activity Spikes (For example, i was going to provide a screenshot while i was encoding a video to make my CPU Activity spike, however it was essentially all 8 logical processors at 99% or 100%...), taking too long to update

Why would anyone need more than one CPU?
(Jan 28, 2014 12:03 PM)ecaep42 Wrote:  Why would anyone need more than one CPU?

I have a single quad core CPU, the problem is, It has 8 Logical Processors....The 2 examples shown here only keep track of a static amount, meaning that i wouldn't be able to see all the activity in my CPU...
(Jan 28, 2014 12:03 PM)ecaep42 Wrote:  Why would anyone need more than one CPU?

Ever heard of a workstation? Dual Intel Xeons are a standard to go along with professional graphics. A single CPU doesn't cut it for complex 3D modeling work. An assembly of a few hundred parts will keep both processors at around 80% use pretty consistently.
(Jan 28, 2014 02:11 PM)webdev77 Wrote:  Ever heard of a workstation? Dual Intel Xeons are a standard to go along with professional graphics. A single CPU doesn't cut it for complex 3D modeling work. An assembly of a few hundred parts will keep both processors at around 80% use pretty consistently.

I haven't. It's practically used for a game develop workplace?


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by Emre_Nov 3, 2020 10:03 AM 2 217 Nov 3, 2020 10:03 AM
Last Post: Emre_
[Java] by j10maxApr 30, 2017 03:16 PM 0 119 Apr 30, 2017 03:16 PM
Last Post: j10max
[.NET] by TheBlackMarketNov 21, 2016 02:35 AM 23 910 Nov 21, 2016 02:35 AM
Last Post: Icoderz