]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
convert to float instead of int in the watch rule
authorAngus Salkeld <asalkeld@redhat.com>
Thu, 19 Jul 2012 05:01:01 +0000 (15:01 +1000)
committerAngus Salkeld <asalkeld@redhat.com>
Thu, 19 Jul 2012 08:45:12 +0000 (18:45 +1000)
as the data sent from the guests are likely to be floats.

Change-Id: Ice17c23997150db8c52c50767ed94fce8b182d4b
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
heat/engine/watchrule.py

index 4767f5bd0e71a4cec8c20d1af15f05ba12d27db5..e92f66326a555de6ea38069dbd17e3536d489a82 100644 (file)
@@ -53,16 +53,16 @@ class WatchRule(object):
             if d.created_at < self.now - self.timeperiod:
                 continue
             if not have_data:
-                data = int(d.data[self.rule['MetricName']]['Value'])
+                data = float(d.data[self.rule['MetricName']]['Value'])
                 have_data = True
-            if int(d.data[self.rule['MetricName']]['Value']) > data:
-                data = int(d.data[self.rule['MetricName']]['Value'])
+            if float(d.data[self.rule['MetricName']]['Value']) > data:
+                data = float(d.data[self.rule['MetricName']]['Value'])
 
         if not have_data:
             return self.NODATA
 
         if self.do_data_cmp(data,
-                            int(self.rule['Threshold'])):
+                            float(self.rule['Threshold'])):
             return self.ALARM
         else:
             return self.NORMAL
@@ -74,16 +74,16 @@ class WatchRule(object):
             if d.created_at < self.now - self.timeperiod:
                 continue
             if not have_data:
-                data = int(d.data[self.rule['MetricName']]['Value'])
+                data = float(d.data[self.rule['MetricName']]['Value'])
                 have_data = True
-            elif int(d.data[self.rule['MetricName']]['Value']) < data:
-                data = int(d.data[self.rule['MetricName']]['Value'])
+            elif float(d.data[self.rule['MetricName']]['Value']) < data:
+                data = float(d.data[self.rule['MetricName']]['Value'])
 
         if not have_data:
             return self.NODATA
 
         if self.do_data_cmp(data,
-                            int(self.rule['Threshold'])):
+                            float(self.rule['Threshold'])):
             return self.ALARM
         else:
             return self.NORMAL
@@ -99,7 +99,7 @@ class WatchRule(object):
             data = data + 1
 
         if self.do_data_cmp(data,
-                            int(self.rule['Threshold'])):
+                            float(self.rule['Threshold'])):
             return self.ALARM
         else:
             return self.NORMAL
@@ -111,14 +111,14 @@ class WatchRule(object):
             if d.created_at < self.now - self.timeperiod:
                 continue
             samples = samples + 1
-            data = data + int(d.data[self.rule['MetricName']]['Value'])
+            data = data + float(d.data[self.rule['MetricName']]['Value'])
 
         if samples == 0:
             return self.NODATA
 
         data = data / samples
         if self.do_data_cmp(data,
-                            int(self.rule['Threshold'])):
+                            float(self.rule['Threshold'])):
             return self.ALARM
         else:
             return self.NORMAL
@@ -129,10 +129,10 @@ class WatchRule(object):
             if d.created_at < self.now - self.timeperiod:
                 logger.debug('ignoring %s' % str(d.data))
                 continue
-            data = data + int(d.data[self.rule['MetricName']]['Value'])
+            data = data + float(d.data[self.rule['MetricName']]['Value'])
 
         if self.do_data_cmp(data,
-                            int(self.rule['Threshold'])):
+                            float(self.rule['Threshold'])):
             return self.ALARM
         else:
             return self.NORMAL