0

I'm a engineer student and quite new to programing, although I'm familiar with the basics of algorithm, never really really developed any programs. And I've been tasked as a school project to develop an system that monitors CPU and memory usage of all tasks running on a machine, establish a threshold each(CPU/memory), and if CPU or memory tasks suprasses the threshold, create a "error log" and send and alert via email. And it must be writen in C#.

As quite new to programming, let alone projects of this complexity, I would like to be adviced what course of steps should I follow create a solution for this, aswell as where can I find good study material for this.

ps:it's first time using stack overflow, if i'm being too bland or not giving enough details I apologise.

Haven't tried anything yet, I'm in the phase of studying/researching/planning as when I was giving the project was a blank sheet.

Kambs
  • 3
  • 2
  • You might want to start by reading what is [on topic](https://stackoverflow.com/help/on-topic): "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow" – JonasH Mar 15 '23 at 07:58
  • As with any problem you break it down into smaller steps: [How do I get CPU usage](https://stackoverflow.com/questions/278071/how-to-get-the-cpu-usage-in-c), [How do I send an Email](https://stackoverflow.com/questions/449887/sending-e-mail-using-c-sharp) etc. – JonasH Mar 15 '23 at 08:00
  • What you ask is built into Windows itself as Performance Counters. There are perf counters for RAM, CPU etc. You can use Performance Monitor to read and graph perf counters and even collect them regularly to a file. In .NET you can use the [PerformanceCounter](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.performancecounter?view=dotnet-plat-ext-7.0) class to read the values of specific counters – Panagiotis Kanavos Mar 15 '23 at 08:08
  • You might find this site helpful look at the questions https://www.codeproject.com/ – Vector Mar 15 '23 at 22:59

1 Answers1

0

Please note that the nature of StackOverflow, is to at least show that you "tried" something. (Some code that you cant get to work...)

Research with google, and at least try something...

Seeing as you took the time to pose a quite detailed question, and you are new here, I'll get you started.

Learn about WMI Information

You can get most of the system info using WMI Queries (Windows Management Instrumentation)

Get familiar with what WMI is. Once you know what you are in for, use a tool called "wbemtest" from the windows command prompt. This tool can list all WMI classes with their properties.

You can run "queries" on the WMI classes from this tool, I.e. select * from Win32_OperatingSystem. This will show you all relevant properties with values.

wbemtest example

You will do something similar from within c#, to get the properties/values of different WMI classes.

As mentioned in various comments to this question, you can also get this info via "Performance Counters", where you can continue "sampling" counter properties to get updated values "on the go".

Good luck... It's a fun area to get things figured out, but all the info should be there.

Louis van Tonder
  • 3,664
  • 3
  • 31
  • 62
  • 1
    A better feature is Performance Counters, available through the PerformanceCounter class. WMI is an interface that reads perf counters – Panagiotis Kanavos Mar 15 '23 at 08:09
  • Agreed. I use both, but WMI is a nice "entry point" to see what is involved/available. – Louis van Tonder Mar 15 '23 at 08:12
  • @LouisvanTonder: I think there is far too much in WMI for a beginner to cope with - I would always recommend starting with the PerformanceCounter class & then as you progress look at WMI if you really need to. – PaulF Mar 15 '23 at 08:25
  • I have found some properties not available (or easy enough to find), in Performance Counters, where they are easy to locate and interrogate using WMI classes. Total Physical Installed Memory, is one such case. I can read the available memory in a performance counter, but not the total Physical Installed System Memory. I guess a good compromise would be to get the "static" info in WMI (Like Total memory), but measure the available and used memory directly from performance counters. On my system, performance counters reports my `Committed Bytes` as my total physical + shared memory. – Louis van Tonder Mar 15 '23 at 09:59
  • 1
    Thank you all for your answers. I did quite the research on Performance. Counter and it was exactly what I was looking for. Thank you. I'll keep it in mind for future posts to come with some already-tried code and issues. Thank you – Kambs Mar 16 '23 at 13:29