Loading extract_cad_csv_periodically.sh 0 → 100644 +23 −0 Original line number Diff line number Diff line folder_name="cad_exp_1_results" if [ -d "$folder_name" ]; then echo "Folder '$folder_name' already exists. Emptying it..." rm -r "$folder_name"/* else echo "Creating folder '$folder_name'..." mkdir "$folder_name" fi while true; do list=($(kubectl get pods --namespace tfs | grep l3-centralized | awk '{print $1}')) #kubectl -n "tfs" cp $pod_name:exp_1.csv $folder_name/$pod_name.csv -c server echo "These are the pods for now" for item in "${list[@]}"; do echo $item kubectl -n "tfs" cp $item:cad_metrics.csv $folder_name/$item.csv -c server done sleep 2 done # kubectl get pods --namespace tfs | grep l3-centralized | wc -l # kubectl --namespace tfs get all | grep autoscaling/l3-centralizedattackdetectorservice-hpa | awk '{print $3}' No newline at end of file proto/copy_to_dad.sh +7 −2 Original line number Diff line number Diff line #!/bin/bash # Set the variables for the remote host and destination directory REMOTE_HOST="192.168.165.73" REMOTE_HOST="192.168.165.11" DEST_DIR="/home/ubuntu/TeraflowDockerDistributed/l3_distributedattackdetector/proto" # Copy the files to the remote host echo "Copying proto files to the remote host ($REMOTE_HOST)" sshpass -p "ubuntu" scp /home/ubuntu/tfs-ctrl-new/proto/src/python/l3_centralizedattackdetector_pb2.py "$REMOTE_HOST:$DEST_DIR" sshpass -p "ubuntu" scp /home/ubuntu/tfs-ctrl-new/proto/src/python/l3_centralizedattackdetector_pb2_grpc.py "$REMOTE_HOST:$DEST_DIR" echo "CAD proto files copied" sshpass -p "ubuntu" scp /home/ubuntu/tfs-ctrl-new/proto/src/python/l3_attackmitigator_pb2.py "$REMOTE_HOST:$DEST_DIR" sshpass -p "ubuntu" scp /home/ubuntu/tfs-ctrl-new/proto/src/python/l3_attackmitigator_pb2_grpc.py "$REMOTE_HOST:$DEST_DIR" echo "AM proto files copied" echo "Proto files copied to the remote host ($REMOTE_HOST) successfully" No newline at end of file src/l3_centralizedattackdetector/service/l3_centralizedattackdetectorServiceServicerImpl.py +29 −1 Original line number Diff line number Diff line Loading @@ -42,6 +42,8 @@ import uuid from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method import csv LOGGER = logging.getLogger(__name__) current_dir = os.path.dirname(os.path.abspath(__file__)) Loading Loading @@ -192,8 +194,19 @@ class l3_centralizedattackdetectorServiceServicerImpl(L3Centralizedattackdetecto self.replica_uuid = uuid.uuid4() self.first_batch_request_time = 0 self.last_batch_request_time = 0 LOGGER.info("This replica's identifier is: " + str(self.replica_uuid)) csv_file_path = 'hola_mundo.csv' col_names = ['timestamp_first_req', 'timestamp_last_req', 'total_time', 'batch_size'] with open(csv_file_path, 'w', newline='') as file: writer = csv.writer(file) writer.writerow(col_names) """ Create a monitored KPI for a specific service and add it to the Monitoring Client -input: Loading Loading @@ -561,10 +574,13 @@ class l3_centralizedattackdetectorServiceServicerImpl(L3Centralizedattackdetecto @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) def AnalyzeConnectionStatistics(self, request, context): # Perform inference with the data sent in the request if len(self.active_requests) == 0: self.first_batch_request_time = time.perf_counter() self.active_requests.append(request) if len(self.active_requests) == BATCH_SIZE: logging.info("Performing inference...") logging.debug("Performing inference... {}".format(self.replica_uuid)) inference_time_start = time.time() cryptomining_detector_output = self.perform_distributed_inference(self.active_requests) Loading Loading @@ -711,6 +727,18 @@ class l3_centralizedattackdetectorServiceServicerImpl(L3Centralizedattackdetecto # return Empty(message="Ok, information received (no attack detected)") self.active_requests = [] csv_file_path = 'cad_metrics.csv' self.last_batch_request_time = time.perf_counter() col_values = [self.first_batch_request_time, self.last_batch_request_time, self.last_batch_request_time - self.first_batch_request_time, BATCH_SIZE] with open(csv_file_path, 'a', newline='') as file: writer = csv.writer(file) writer.writerow(col_values) return Empty(message="Ok, metrics processed") return Empty(message="Ok, information received") Loading Loading
extract_cad_csv_periodically.sh 0 → 100644 +23 −0 Original line number Diff line number Diff line folder_name="cad_exp_1_results" if [ -d "$folder_name" ]; then echo "Folder '$folder_name' already exists. Emptying it..." rm -r "$folder_name"/* else echo "Creating folder '$folder_name'..." mkdir "$folder_name" fi while true; do list=($(kubectl get pods --namespace tfs | grep l3-centralized | awk '{print $1}')) #kubectl -n "tfs" cp $pod_name:exp_1.csv $folder_name/$pod_name.csv -c server echo "These are the pods for now" for item in "${list[@]}"; do echo $item kubectl -n "tfs" cp $item:cad_metrics.csv $folder_name/$item.csv -c server done sleep 2 done # kubectl get pods --namespace tfs | grep l3-centralized | wc -l # kubectl --namespace tfs get all | grep autoscaling/l3-centralizedattackdetectorservice-hpa | awk '{print $3}' No newline at end of file
proto/copy_to_dad.sh +7 −2 Original line number Diff line number Diff line #!/bin/bash # Set the variables for the remote host and destination directory REMOTE_HOST="192.168.165.73" REMOTE_HOST="192.168.165.11" DEST_DIR="/home/ubuntu/TeraflowDockerDistributed/l3_distributedattackdetector/proto" # Copy the files to the remote host echo "Copying proto files to the remote host ($REMOTE_HOST)" sshpass -p "ubuntu" scp /home/ubuntu/tfs-ctrl-new/proto/src/python/l3_centralizedattackdetector_pb2.py "$REMOTE_HOST:$DEST_DIR" sshpass -p "ubuntu" scp /home/ubuntu/tfs-ctrl-new/proto/src/python/l3_centralizedattackdetector_pb2_grpc.py "$REMOTE_HOST:$DEST_DIR" echo "CAD proto files copied" sshpass -p "ubuntu" scp /home/ubuntu/tfs-ctrl-new/proto/src/python/l3_attackmitigator_pb2.py "$REMOTE_HOST:$DEST_DIR" sshpass -p "ubuntu" scp /home/ubuntu/tfs-ctrl-new/proto/src/python/l3_attackmitigator_pb2_grpc.py "$REMOTE_HOST:$DEST_DIR" echo "AM proto files copied" echo "Proto files copied to the remote host ($REMOTE_HOST) successfully" No newline at end of file
src/l3_centralizedattackdetector/service/l3_centralizedattackdetectorServiceServicerImpl.py +29 −1 Original line number Diff line number Diff line Loading @@ -42,6 +42,8 @@ import uuid from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method import csv LOGGER = logging.getLogger(__name__) current_dir = os.path.dirname(os.path.abspath(__file__)) Loading Loading @@ -192,8 +194,19 @@ class l3_centralizedattackdetectorServiceServicerImpl(L3Centralizedattackdetecto self.replica_uuid = uuid.uuid4() self.first_batch_request_time = 0 self.last_batch_request_time = 0 LOGGER.info("This replica's identifier is: " + str(self.replica_uuid)) csv_file_path = 'hola_mundo.csv' col_names = ['timestamp_first_req', 'timestamp_last_req', 'total_time', 'batch_size'] with open(csv_file_path, 'w', newline='') as file: writer = csv.writer(file) writer.writerow(col_names) """ Create a monitored KPI for a specific service and add it to the Monitoring Client -input: Loading Loading @@ -561,10 +574,13 @@ class l3_centralizedattackdetectorServiceServicerImpl(L3Centralizedattackdetecto @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) def AnalyzeConnectionStatistics(self, request, context): # Perform inference with the data sent in the request if len(self.active_requests) == 0: self.first_batch_request_time = time.perf_counter() self.active_requests.append(request) if len(self.active_requests) == BATCH_SIZE: logging.info("Performing inference...") logging.debug("Performing inference... {}".format(self.replica_uuid)) inference_time_start = time.time() cryptomining_detector_output = self.perform_distributed_inference(self.active_requests) Loading Loading @@ -711,6 +727,18 @@ class l3_centralizedattackdetectorServiceServicerImpl(L3Centralizedattackdetecto # return Empty(message="Ok, information received (no attack detected)") self.active_requests = [] csv_file_path = 'cad_metrics.csv' self.last_batch_request_time = time.perf_counter() col_values = [self.first_batch_request_time, self.last_batch_request_time, self.last_batch_request_time - self.first_batch_request_time, BATCH_SIZE] with open(csv_file_path, 'a', newline='') as file: writer = csv.writer(file) writer.writerow(col_values) return Empty(message="Ok, metrics processed") return Empty(message="Ok, information received") Loading