【发布时间】:2017-09-25 09:47:16
【问题描述】:
有没有什么方法可以在 python 中从另一台机器检查 apache tomcat 服务器的状态?
例如,RESTful API 正在一台机器上运行,该机器的 apache tomcat 服务器位于 8086 端口。
现在,我想要的是在 python 中以编程方式从我的电脑检查指定机器的 apache tomcat 服务的状态。
是的,我可以通过在 python 中使用os.system ping 来检查机器是否正在运行。
import os
hostname = "xxx.xxx.xxx.xxx" #example
response = os.system("ping -c 1 " + hostname)
#and then check the response...
if response == 0:
print hostname, 'is up!'
else:
print hostname, 'is down!'
但是,我感兴趣的是,是否可以在 python 中以编程方式检查服务的状态 (real_ip:8086/BotAPI) 而不是机器的活跃度?
更新:使用 paramiko 我得到了以下回溯
channel.exec_command('ps -ef| grep tomcat')
Traceback (most recent call last):
File "<pyshell#67>", line 1, in <module>
channel.exec_command('ps -ef| grep tomcat')
File "E:\python\lib\site-packages\paramiko\channel.py", line 63, in _check
return func(self, *args, **kwds)
File "E:\python\lib\site-packages\paramiko\channel.py", line 241, in exec_command
self._wait_for_event()
File "E:\python\lib\site-packages\paramiko\channel.py", line 1197, in _wait_for_event
raise e
paramiko.ssh_exception.SSHException: Channel closed.
【问题讨论】:
-
你能ssh进入tomcat机器吗?
-
是的。我可以远程登录到tomcat机器。