@@ -241,6 +241,7 @@ def job_perform_account_aggr(*args, **job_params):
241
241
values .extend (NetFlowBot .get_top_N_protocols_for_entity (interval_label , last_used_ts , max_ts , time_between , direction , entity_id , entity_ip ))
242
242
values .extend (NetFlowBot .get_top_N_protocols_for_entity_interfaces (interval_label , last_used_ts , max_ts , time_between , direction , entity_id , entity_ip ))
243
243
values .extend (NetFlowBot .get_top_N_connections_for_entity (interval_label , last_used_ts , max_ts , time_between , direction , entity_id , entity_ip ))
244
+ values .extend (NetFlowBot .get_top_N_dstports_for_entity (interval_label , last_used_ts , max_ts , time_between , direction , entity_id , entity_ip ))
244
245
245
246
if not values :
246
247
log .warning ("No values found to be sent to Grafolean" )
@@ -519,6 +520,39 @@ def get_top_N_connections_for_entity(interval_label, last_used_ts, max_ts, time_
519
520
520
521
return values
521
522
523
+ @staticmethod
524
+ @slow_down
525
+ def get_top_N_dstports_for_entity (interval_label , last_used_ts , max_ts , time_between , direction , entity_id , entity_ip ):
526
+ with get_db_cursor () as c :
527
+ values = []
528
+ c .execute (f"""
529
+ SELECT
530
+ f.l4_dst_port,
531
+ sum(f.in_bytes) "traffic"
532
+ FROM
533
+ { DB_PREFIX } flows2 "f"
534
+ WHERE
535
+ f.client_ip = %s AND
536
+ f.ts > %s AND
537
+ f.ts <= %s AND
538
+ f.direction = %s
539
+ GROUP BY
540
+ f.l4_dst_port
541
+ ORDER BY
542
+ traffic desc
543
+ LIMIT { TOP_N_MAX } ;
544
+ """ , (entity_ip , last_used_ts , max_ts , direction ,))
545
+
546
+ output_path_entity = NetFlowBot .construct_output_path_prefix (interval_label , direction , entity_id , interface = None )
547
+ for l4_dst_port , traffic_bytes in c .fetchall ():
548
+ output_path = f"{ output_path_entity } .topdstports.{ path_part_encode (l4_dst_port )} "
549
+ values .append ({
550
+ 'p' : output_path ,
551
+ 'v' : traffic_bytes / time_between , # Bps
552
+ })
553
+
554
+ return values
555
+
522
556
# @staticmethod
523
557
# @slow_down
524
558
# def get_top_N_protocols(output_path_prefix, from_time, to_time, interface_index, is_direction_in=True):
0 commit comments