1

Is there a way to get the CPU, RAM and HardDisk status data from a remote server and show it in a dotnet core 3.0 application?

Fixed:

I've made a new project in .net framework which can get RAM and CPU data easily with Performance Counter How to get the CPU Usage in C#?

  • This sounds like [an XY Problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). If you want to monitor server status, there are tools for that. If you want to display data from those tools (that are already mostly server based - you could build the right dashboard using those tools ready) using a .NET Core server application seems a bit redundant. – omajid Nov 01 '19 at 16:41
  • This is something .NET Core won't help directly. Your remote server (what OS?) must expose such data via an interface (SNMP, WMI, or others) and then your application can consume them. Talk to the server administrators to see what you actually can use. – Lex Li Nov 03 '19 at 14:40

1 Answers1

1

From your question it is hard to see what exactly you want to achive but you can take a look at the HealthCheck in ASP.NET Core here. You can also take a look at this example.

How to extract the application status info using Process class

You can use the Process class from the System.Diagnostics namespace in order to extract this information from the server where you application process is running. Here you can see the implementation of the Process.cs class.

For memory you can simple use one of the properties:

Process.GetCurrentProcess().PrivateMemorySize64;

Process.GetCurrentProcess().VirtualMemorySize64;

Process.GetCurrentProcess().WorkingSet64;

For getting CPU usage:

There are some properties from Process class which you can use for example:

Process.GetCurrentProcess().TotalProcessorTime

But if you want to get it in percentage you can calculate it yourself. Here is an example how you can do it.

xargs
  • 2,741
  • 2
  • 21
  • 33
  • Maybe it's not the best solution but i added an extra .net framework api. In .net you can monitor pc performance easier. – lammertpuntbakker Nov 11 '19 at 09:20
  • Then you should update your question with more details and provide examples how you do it in .NET so people can relate more to what exactly you want to achieve. – xargs Nov 11 '19 at 12:24