Commit b5d5bf17 by Bach Dániel

vm: add exception handling to get_monitor_info()

parent f2794a01
...@@ -199,29 +199,30 @@ class Node(TimeStampedModel): ...@@ -199,29 +199,30 @@ class Node(TimeStampedModel):
return default return default
def get_monitor_info(self): def get_monitor_info(self):
collected = {}
try: try:
handler = GraphiteHandler() handler = GraphiteHandler()
except: except RuntimeError:
response = self.remote_query(vm_tasks.get_node_metrics, 30) return self.remote_query(vm_tasks.get_node_metrics, 30)
collected['cpu.usage'] = response['cpu.usage']
collected['memory.usage'] = response['memory.usage']
return collected
query = Query() query = Query()
query.set_target(self.host.hostname + ".circle") query.set_target(self.host.hostname + ".circle")
query.set_format("json") query.set_format("json")
query.set_relative_start(5, "minutes") query.set_relative_start(5, "minutes")
metrics = ["cpu.usage", "memory.usage"] metrics = ["cpu.usage", "memory.usage"]
collected = {}
for metric in metrics: for metric in metrics:
query.set_metric(metric) query.set_metric(metric)
query.generate() query.generate()
handler.put(query) handler.put(query)
handler.send() handler.send()
collected = {}
for metric in metrics: for metric in metrics:
response = handler.pop() response = handler.pop()
length = len(response[0]["datapoints"]) try:
cache = response[0]["datapoints"][length - 1][0] cache = response[0]["datapoints"][-1][0]
except (IndexError, KeyError):
cache = 0
if cache is None: if cache is None:
cache = 0 cache = 0
collected[metric] = cache collected[metric] = cache
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment