Simple remote process monitoring with Python

I want to write a python script to perform a very simple "agent" monitoring of remote processes running on Linux servers.

He would perform the following tasks in psuedocode:

for each remoteIPAddress in listOfIPAddresses:
    log into server@remoteIPAddress via ssh
    execute the equivalent of a 'ps -ef' command
    grep the result to make sure a particular process (by name) is still running

One way to do this is to have python call shell scripts in a subprocess and parse their output. It seems rather inefficient. Is there a better way to do this through python libraries?

All I could find through research here and elsewhere:

  • psutil - it seems that it does not perform remote monitoring, so I would have to run agents on remote computers that reports RPC statistics.
  • pymeter - I would need to write my own plugin to monitor a specific remote service.
  • https://stackoverflow.com/questions/1123323/...- Some useful links, but the poster was looking for a different solution.

Thank you, and please calm down, my first question is :-)

+5
source share
5 answers

You might be interested in the Fabric library .

+3
source

Check out paramiko . You can use it for ssh on the server and run commands. Then you can analyze the results and do what you would like with them.

+1
source

, , Zenoss .

paramiko Fabric, , .

0

Taking the answers from the answers above, I researched Fabric and found the following presentation particularly interesting / useful. This is an overview of three libraries — Fabric, Cuisine, and Watchdog — for monitoring and administering the server. For posterity:

Using Fabric, Cuisine, and Watchdog to administer a Python server

0
source

Why don't you use a special monitoring tool like Nagios? Nagios has an agent and an agent that has less control over NRPE plugins and SSH plugins, etc. Give it a try.

0
source

All Articles