Link to home
Start Free TrialLog in
Avatar of Robb Hill
Robb HillFlag for United States of America

asked on

powershell monitoring of a process

I have a process.exe.

I need to have a powershell script running.

I would run this on a taskschedule and check every 10 minutes.

Here is what I need to get this thing to do.


When the job is kicked off it should check all the process.exe's running..there will be more than one.

It should check if any are non responsive.

If so it should open another process.exe.

It should check again after a variable number of minutes...if its still non responsive it should email a helpdesk email.

I would add if it determined anything else negative about the process...it should also do the same thing..
Just make a custom comment in the email.

So if the process was stopped...a differente email..

And anything else that might mean the process is not running properly...such as an error on the proccess...locked up ..etc.
Avatar of Qlemo
Qlemo
Flag of Germany image

You can't do that. There is no way to know how many process.exe should be running, and so we cannot check if one is missing. There is also no standard way to tell if a process is non-responsive.

We can register something getting informed whenever process.exe terminates. For everything else you need to tell specific makers we can check for, e.g. a TCP port for a network service.
I would recommend setting up your recovery options for critical services to accomplish this for if the service is down. (see img)

But wait...Is the problem the service is dropping or is the service staying up and just becoming unresponsive?
ServiceNotifySetup.PNG
Avatar of Robb Hill

ASKER

For example...

This would tell me non responsive...but its not where near what I need.

so it is possible..but perhaps my question is being misunderstood.


get-process | ?{$_.path -ne $null} | ?{$_.path.endswith("\process.exe") -and $_.responding -eq $false}
With get-proccess you get 64bit processes in a 64bit shell only, and 32bit processes in a 32bit shell, so you need to pay attention to that.
[System.Diagnostics.Process]:Responding uses the Windows Message queue, and so only works for processes showing a window.
Details: https://msdn.microsoft.com/de-DE/library/system.diagnostics.process_properties.aspx
this is a process....its 32 bit.  

but the code above does recognize when this process.exe is non responsive.


It can run with a window..or hidden as a background process
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It is unreliable and a bad means to use that feature, but if you insist ... We can, however, not satisfy your other requests but the second check-and-mail one.

Please clarify this statemtn.

What about it will be unreliable and bad.

What does second check-and-mail one mean.


Can you explain what this script will do exactly.

And is this script ok to run from task scheduler
The script will check all processes with a specified name. For any unresponsive one, it will start a new one, and store the process ID in a text file for the next run.

In the next run, the list of unresponsive process IDs is checked against the text file created in the prior run. If it is found in that list, we keep that PID for mailing it, and do [u}not[/u] start a new process. Otherwise we would start a process in each run for the same unresponsive process ID.
The list of PIDs found to be unresponsive for at least two runs is then sent as simple body of an email. The mail parameters you have to change (like Server, From and To) should be obvious.

^^^ This is what we can do.
As said before, we do not know how many processes should be running, so cannot check if one is missing. We also do not know why a process is not running. We cannot also not "determine anything negative". That would require to know a lot about the process and how it should interact; e.g. by monitoring a log file. This is asking for too much, there is no crystal ball to look into ;-).
this is a program running.  We usually run 4 or 5 instances of this process.  That number is a variable but they always have the same name.
The process id would be different but the name of the process is the same.

If for any reason they were not running or there was any issue with the process we would want to open a new process and if they other process did not start working...lets say after x amount of minutes...we would want to send the email.

Anyways we can tweak your script to do that?
The script as-is would require three runs to catch "if they [sic] other process did not start working". First run sees it has to start a new process, second that it is not responding (and creating another process), third that it is still not responding => send the mail.
In that scenario another process get started in each run.
But why should the process hang while started fresh? This pretty much look like you are trying to get around a very poor design.

Further, "any issue" cannot get checked. It is like "if I'm ill, I want a cure".
yes there is a poor design..and I am trying to catch this behavior until some code rewrites can happen.

Unfortantely this is very black box and I need to get something in place to try and alleviate the issue while the root of the issue is resolved.

This script too might help with getting information to further investigate why and when this is happening....

Its a big mess
Then use the script as-is now, to see if it needs another tweak later.
i just got unresponsives...it does not seem to be detecting them...or writing to the log file
I had to do some tweeks...had to do a cd to change the directory so it new where to run the exe.

thanks for your help
I had to do some tweeks...had to do a cd to change the directory so it new where to run the exe.

thanks for your help