@@ -57,7 +57,10 @@ def get_metric_diff(db_name, metric_name, current_time, current_value):
57
57
if derive_dict_key in DERIVE_DICT :
58
58
last_time , last_value = DERIVE_DICT [derive_dict_key ]
59
59
seconds_since_last_check = (current_time - last_time ).seconds
60
- diff = float (current_value - last_value ) / seconds_since_last_check
60
+ if seconds_since_last_check == 0 :
61
+ diff = 0
62
+ else :
63
+ diff = float (current_value - last_value ) / seconds_since_last_check
61
64
DERIVE_DICT [derive_dict_key ] = (current_time , current_value )
62
65
return diff
63
66
@@ -156,7 +159,10 @@ def get_heap_hit_statistics(conn):
156
159
recent_heap_hit = get_metric_diff (db_name , 'heap_hit' , time_now , heap_hit_now )
157
160
recent_heap_hit_ratio = None
158
161
if recent_heap_read is not None :
159
- recent_heap_hit_ratio = recent_heap_hit / float (recent_heap_hit + recent_heap_read )
162
+ if recent_heap_hit == 0 :
163
+ recent_heap_hit_ratio = 0
164
+ else :
165
+ recent_heap_hit_ratio = recent_heap_hit / float (recent_heap_hit + recent_heap_read )
160
166
return db_name , recent_heap_read , recent_heap_hit , recent_heap_hit_ratio
161
167
162
168
@@ -217,8 +223,11 @@ def get_index_hit_rates(conn):
217
223
index_hit_rates = []
218
224
LOG .debug (results )
219
225
for db_name , table_name , index_hit , index_miss in results :
220
- if index_hit and index_miss :
221
- recent_ratio = index_hit / float (index_miss + index_hit )
226
+ if index_hit is not None and index_miss is not None :
227
+ if index_hit == 0 :
228
+ recent_ratio = 0
229
+ else :
230
+ recent_ratio = index_hit / float (index_miss + index_hit )
222
231
index_hit_rates .append ((db_name , table_name , recent_ratio ))
223
232
else :
224
233
index_hit_rates .append ((db_name , table_name , None ))
0 commit comments