我正在尝试从我的python应用程序中监视docker容器的CPU和内存。我计划使用psutil来完成这项工作。我在其他论坛上看到过/proc
可能会在psutil中被更改。
import psutil
psutil.PROCFS_PATH = 'proc/self'
psutil.cpu_percent()
这让我遇到了以下错误:
File "app.py", line 22, in <module>
web-vote-app_1 | r = psutil.cpu_percent()
web-vote-app_1 | File "/usr/local/lib/python2.7/site-packages/psutil /__init__.py", line 1773, in cpu_percent
web-vote-app_1 | _last_cpu_times = cpu_times()
web-vote-app_1 | File "/usr/local/lib/python2.7/site-packages/psutil/__init__.py", line 1645, in cpu_times
web-vote-app_1 | return _psplatform.cpu_times()
web-vote-app_1 | File "/usr/local/lib/python2.7/site-packages/psutil/_pslinux.py", line 544, in cpu_times
web-vote-app_1 | fields = [float(x) / CLOCK_TICKS for x in fields]
web-vote-app_1 | ValueError: could not convert string to float: (python)
web-result_1 | * Running on http://0.0.0.0:5002/ (Press CTRL+C to quit)
swarmmicroservicedemov1_web-vote-app_1 exited with code 1
请问是否有可能获取容器的相同信息而不是主机,如果可以的话,该怎么做?谢谢。
htop
,您将看到与主机对应的CPU活动(百分比))。 - Robert