1
votes

I want to monitoring remote machine process memory usage in .net core 2.2. My application will run in intranet and check remote machine CPU Usage, process's memory usage. Developing own Application Performance Monitoring application.

Try to use 'Process' class of System.Diagnostics but getting System.InvalidOperationException: 'Couldn't connect to remote machine.' error message. used machine name but getting same error.

Process[] remoteByName = Process.GetProcessesByName("notepad", "\\192.168.3.114");

or

Process[] remoteByName = Process.GetProcessesByName("notepad", "192.168.3.114");
  1. Not able to find any method which accept the username with password to access remote machine.is this kind of method available?
  2. Do i need to turn off remote machine firewall?
  3. Is there any other approach to access remote machine's processes in .net core?
1
Please check if the Remote Registry service is running on remote machine. Besides, using xxx.xxx.xxx.xxx without starting with `\`.Fei Han
yes, i have tried but getting UnauthorizedAccessException: Access to the registry key '230 232' is denied error.Parth Akbari
@ParthAkbari, can you use the remote pc's username and password, if yes there is one way I had working couple of months ago.Clint

1 Answers

-1
votes

As I know, under the hood, Process class uses WMI to perform operations on remote machines. If Process class interface is not enough for your task you can use WMI queries directly.

Authorization

By default, Process class uses current windows credentials to authorize you on remote machines. If your remote machine has different credentials to login, you can switch context to authorize correctly. It's a little tricky solution but it works. Check this article to see how it can be done.

Anyway, you can use WMI query as I mentioned before to perform authorization and get required data. It's more complex but flexible solution.

Firewall

Ofcourse, firewall can blocks remote connections. WMI uses port 135 by-default to access to remote machine so you need to open it on target machine.

I recommend you to check official documentation about WMI connection to remote machines to set up all configurations correctly.

Other approaches

You can use client-server architecture to perform such monitoring tasks. Just create one server application that will be used to aggregate information from clients. Next create one client application that will be used for collecting monitoring data and sending it to server. Then just deploy many client applications to your target machines and configure it to send all required information to server. Deploy one server application accordingly.

This architecture allows you to create your own security protocol for messaging between clients and server. You can choose the port your application will be communicate. Also you can create new/remove old clients without affecting other deployed applications (clients and server). Many existing popular monitoring systems (such as Zabbix) uses this architecture to perform system monitoring.

This eliminates need for configure remote connection to target machines. Client applications can use plain Process class to gather all required data from operation system and then send it to server using i.e. HttpClient. Also this architecture more appropriate for monitoring because there are some tasks that you can't perform by using remote connection.