简体   繁体   English

使用Python进行简单的远程过程监控

[英]Simple remote process monitoring with Python

I'd like to write a python script to perform some very simple "agentless" monitoring of remote processes running on linux servers. 我想编写一个python脚本来对linux服务器上运行的远程进程执行一些非常简单的“无代理”监视。

It 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. 一种方法是在子进程中使用python调用shell脚本并解析它们的输出。 That seems pretty inefficient. 这似乎效率很低。 Is there a better way to do this via python libraries? 有没有更好的方法通过python库来做到这一点?

All I could find via research here and elsewhere was: 通过这里和其他地方的研究我能找到的是:

  • psutil - looks like it doesn't do remote monitoring, so I'd have to run agents on the remote machines to report stats back via RPC. psutil - 看起来它没有进行远程监控,因此我必须在远程计算机上运行代理以通过RPC报告统计信息。
  • pymeter - I would have to write my own plugin for monitoring a specific remote service. pymeter - 我必须编写自己的插件来监控特定的远程服务。
  • stackoverflow #4546492 - Some helpful links but the poster was looking for a different solution. stackoverflow#4546492 - 一些有用的链接,但海报正在寻找一个不同的解决方案。

Thanks, and please go easy on me, it's my first question :-) 谢谢,请放轻松我,这是我的第一个问题:-)

Fabric库可能是您感兴趣的。

Check out paramiko . 看看paramiko You can use it to ssh into the server and run commands. 您可以使用它来ssh到服务器并运行命令。 You can then parse the results and do what you'd like with them. 然后,您可以解析结果并使用它们执行您想要的操作。

It might be heavier than what you're looking for, but Zenoss supports agentless monitoring. 它可能比您正在寻找的更重,但Zenoss支持无代理监控。

paramiko and Fabric, suggested in the other answers, are great options too. 在其他答案中建议的paramiko和Fabric也是很好的选择。

Taking cues from the answers above, I investigated Fabric and found the following presentation particularly interesting/helpful. 从上面的答案中提取线索,我调查了Fabric,发现以下介绍特别有趣/有帮助。 It is an overview of three libraries -- Fabric, Cuisine, and Watchdog -- for server monitoring and administration. 它概述了三个库 - Fabric,Cuisine和Watchdog - 用于服务器监视和管理。 For posterity: 后人:

Using Fabric, Cuisine, and Watchdog for server administration in Python 使用Fabric,Cuisine和Watchdog在Python中进行服务器管理

Why don't you use a dedicated monitoring tool like Nagios ? 你为什么不使用像Nagios这样的专用监控工具? Nagios has agent and agent less monitoring through NRPE plugins and SSH plugins etc. Try it out. Nagios通过NRPE插件和SSH插件等代理和代理监控较少。试试看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM