def get_total_memory(cls): """ 获取容器占用内存 :return: int """ c = db.execute_sql("select sum(memory) from container") obj = c.fetchone() if not obj or not obj[0]: return 0 return int(obj[0])
fp_path = session_path + "/" + fp fp = open(fp_path, "rb") data = fp.read() fp.close() obj = pickle.loads(data) if obj['time'] < time.time(): os.remove(fp_path) print("清除session结束") # 清除孤儿容器 print("开始清除孤儿容器") start_connect(sqlite_db_use=False) c = db.execute_sql("select id, api_url, container_id, app_id, host, port from app_container where app_id not in " "(select id from app)") objs = c.fetchall() for t in objs: obj['id'] = t[0] obj['api_url'] = t[1] obj['container_id'] = t[2] obj['app_id'] = t[3] obj['host'] = t[4] obj['port'] = t[5] login_log("maintain", "发现孤儿容器,所属应用id:%d,容器id:%s,容器域名:%s,容器端口:%d" % (obj['app_id'], obj['container_id'], obj['host'], obj['port'])) api_url = obj['api_url'] + "remove" data = { "containerId": obj['container_id'] } r = request_api(api_url, data)