本文整理汇总了Python中juliabox.cloud.Compute.get_cluster_average_stats方法的典型用法代码示例。如果您正苦于以下问题:Python Compute.get_cluster_average_stats方法的具体用法?Python Compute.get_cluster_average_stats怎么用?Python Compute.get_cluster_average_stats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类juliabox.cloud.Compute
的用法示例。
在下文中一共展示了Compute.get_cluster_average_stats方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_if_instance_info
# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_cluster_average_stats [as 别名]
def handle_if_instance_info(self, is_allowed):
stats = self.get_argument('instance_info', None)
if stats is None:
return False
if not is_allowed:
AdminHandler.log_error("Show instance info not allowed for user")
response = {'code': -1, 'data': 'You do not have permissions to view these stats'}
else:
try:
if stats == 'load':
result = {}
# get cluster loads
average_load = Compute.get_cluster_average_stats('Load')
if None != average_load:
result['Average Load'] = average_load
machine_loads = Compute.get_cluster_stats('Load')
if None != machine_loads:
for n, v in machine_loads.iteritems():
result['Instance ' + n] = v
elif stats == 'sessions':
result = dict()
instances = Compute.get_all_instances()
for idx in range(0, len(instances)):
try:
inst = instances[idx]
result[inst] = JBoxAsyncJob.sync_session_status(inst)['data']
except:
JBoxHandler.log_error("Error receiving sessions list from %r", inst)
elif stats == 'apis':
result = APIContainer.get_cluster_api_status()
else:
raise Exception("unknown command %s" % (stats,))
response = {'code': 0, 'data': result}
except:
AdminHandler.log_error("exception while getting stats")
AdminHandler._get_logger().exception("exception while getting stats")
response = {'code': -1, 'data': 'error getting stats'}
self.write(response)
return True
示例2: handle_if_instance_info
# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_cluster_average_stats [as 别名]
def handle_if_instance_info(self, is_allowed):
stats = self.get_argument('instance_info', None)
if stats is None:
return False
if not is_allowed:
AdminHandler.log_error("Show instance info not allowed for user")
response = {'code': -1, 'data': 'You do not have permissions to view these stats'}
else:
try:
if stats == 'load':
result = {}
# get cluster loads
average_load = Compute.get_cluster_average_stats('Load')
if average_load is not None:
result['Average Load'] = average_load
machine_loads = Compute.get_cluster_stats('Load')
if machine_loads is not None:
for n, v in machine_loads.iteritems():
result['Instance ' + n] = v
elif stats == 'sessions':
result = JBoxSessionProps.get_active_sessions(Compute.get_install_id())
elif stats == 'apis':
result = JBoxInstanceProps.get_instance_status(Compute.get_install_id())
else:
raise Exception("unknown command %s" % (stats,))
response = {'code': 0, 'data': result}
except:
AdminHandler.log_error("exception while getting stats")
AdminHandler._get_logger().exception("exception while getting stats")
response = {'code': -1, 'data': 'error getting stats'}
self.write(response)
return True