Skip to content

Commit

Permalink
Make parsing of usage stats from XS more robust.
Browse files Browse the repository at this point in the history
Better handle odd values in parsing of usage data from xenserver.
Fixes bug 918490

Change-Id: Ie634ba6a740d0ea098d7fc4e13b4b46b5203ce79
  • Loading branch information
DragonDM committed Feb 1, 2012
1 parent cbe943c commit 66a1bb3
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions nova/virt/xenapi/vm_utils.py
Expand Up @@ -30,7 +30,7 @@
import time
import urllib
import uuid
from decimal import Decimal
from decimal import Decimal, InvalidOperation
from xml.dom import minidom

from nova.common import cfg
Expand Down Expand Up @@ -1082,9 +1082,21 @@ def parse_rrd_update(doc, start, until=None):
def average_series(data, col, start, until=None):
vals = [row['values'][col] for row in data
if (not until or (row['time'] <= until)) and
not row['values'][col].is_nan()]
row['values'][col].is_finite()]
if vals:
return (sum(vals) / len(vals)).quantize(Decimal('1.0000'))
try:
return (sum(vals) / len(vals)).quantize(Decimal('1.0000'))
except InvalidOperation:
# (mdragon) Xenserver occasionally returns odd values in
# data that will throw an error on averaging (see bug 918490)
# These are hard to find, since, whatever those values are,
# Decimal seems to think they are a valid number, sortof.
# We *think* we've got the the cases covered, but just in
# case, log and return NaN, so we don't break reporting of
# other statistics.
LOG.error(_("Invalid statistics data from Xenserver: %s")
% str(vals))
return Decimal('NaN')
else:
return Decimal('0.0000')

Expand Down

0 comments on commit 66a1bb3

Please sign in to comment.