@@ -282,7 +282,7 @@ def get_traffic_for_entity(interval_label, last_used_ts, max_ts, time_between, d
282
282
# returns cumulative traffic for the whole entity, and traffic per interface for this entity
283
283
with get_db_cursor () as c :
284
284
285
- c . execute ( f"""
285
+ sql = f"""
286
286
SELECT
287
287
f.{ 'input_snmp' if direction == DIRECTION_INGRESS else 'output_snmp' } ,
288
288
sum(f.in_bytes)
@@ -295,15 +295,23 @@ def get_traffic_for_entity(interval_label, last_used_ts, max_ts, time_between, d
295
295
f.direction = %s
296
296
GROUP BY
297
297
f.{ 'input_snmp' if direction == DIRECTION_INGRESS else 'output_snmp' }
298
- """ , (entity_ip , last_used_ts , max_ts , direction ))
298
+ """
299
+ c .execute (sql , (entity_ip , last_used_ts , max_ts , direction ))
299
300
300
301
values = []
301
302
sum_traffic = 0
302
303
for if_index , traffic_bytes in c .fetchall ():
303
304
output_path = NetFlowBot .construct_output_path_prefix (interval_label , direction , entity_id , interface = if_index )
305
+ v = traffic_bytes / time_between
306
+ if v < 0 :
307
+ # invalid condition - to find the cause we need some additional logging:
308
+ log .error (f"Sum of positive numbers should never be negative! " +
309
+ "{v} {traffic_bytes} {time_between} {sql} {entity_ip} {last_used_ts} {max_ts} {direction}" )
310
+ continue # this is never ok - skip this value
311
+
304
312
values .append ({
305
313
'p' : output_path ,
306
- 'v' : traffic_bytes / time_between ,
314
+ 'v' : v ,
307
315
})
308
316
sum_traffic += traffic_bytes
309
317
0 commit comments