问题描述
我有一个项目,该项目使用Docker封装控制设备和monitoring
设备的映像。
监视部分是通过多线程实现的,监视信息通过 time.sleep 定期收集并发送到其他组件。但是随着容器运行时间的增加, time.sleep间隔变得越来越小。
我不知道为什么会引起这些问题。
如果您能告诉我如何解决它,我将不胜感激。
部分代码如下
collect_data = Thread(target=collect,args=(client,))
def collect(client):
while 1:
host_info = get_host_info()
print(host_info)
time.sleep(30)
def get_host_info():
host_info = dict()
host_info['cpu_usage'] = "%0.2f"%psutil.cpu_percent(interval=1,percpu=False)+"%"
mem = psutil.virtual_memory()
host_info['mem_usage'] = str(int(mem.used / (1024 ** 2)))
host_info['time'] = time.strftime("%Y-%m-%dT%H:%M:%s",time.localtime(time.time()))
return host_info
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)