From a6bc16a7a16c64070317dc4318100ee43d351ac5 Mon Sep 17 00:00:00 2001 From: saarthak Date: Sun, 21 Jul 2024 23:12:31 +0530 Subject: [PATCH 1/2] docker container monitoring Signed-off-by: saarthak --- docker-monitor.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 docker-monitor.sh diff --git a/docker-monitor.sh b/docker-monitor.sh new file mode 100755 index 0000000..16e6514 --- /dev/null +++ b/docker-monitor.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Start the containers in detached mode +sudo docker-compose -f /home/saarthak/Desktop/scm-probe/scm-prom/monitor.docker-compose.yaml up -d + +# Get the container IDs +CONTAINER_IDS=$(sudo docker-compose -f /home/saarthak/Desktop/scm-probe/scm-prom/monitor.docker-compose.yaml ps -q) + +# Print the container IDs +echo "Started containers with IDs:" +echo "$CONTAINER_IDS" + +FIRST_CONTAINER_ID=$(echo "$CONTAINER_IDS" | head -n 1) + +PIDS=$(sudo docker top $FIRST_CONTAINER_ID | awk 'NR>1 {print $2}') + +echo "Process IDs:" +echo "$PIDS" + +FIRST_PID=$(echo "$PIDS" | head -n 1) + +echo ${FIRST_PID} + +sudo ./main -id ${FIRST_PID} + + + + From 981413d2f404da49bdbb43a0f8b00d2e31a2bea3 Mon Sep 17 00:00:00 2001 From: saarthak Date: Sat, 27 Jul 2024 13:46:34 +0530 Subject: [PATCH 2/2] Readme instructions + docker-monitor.sh improvements Signed-off-by: saarthak --- Readme.md | 5 +++++ docker-monitor.sh | 23 ++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Readme.md b/Readme.md index 3a282ca..42cbe68 100644 --- a/Readme.md +++ b/Readme.md @@ -23,6 +23,11 @@ SCM or system-call-montior is monitoring/auditing tool aimed at tracing system c - Run `make build` to compile the app - Run `sudo ./main -n="name of the process you want to trace"` to run the compiled binary, you can also use `-id=` flag to explicilty provide the process id to track. +## Attaching scm to your docker containers + +- Start your docker container using `docker-compose -f /path/to/your/docker-compose.yml up -d` +- Run the script `./docker-monitor /path/to/your/docker-compose.yml` + ## Developing Environment - Go version=1.22.0+ diff --git a/docker-monitor.sh b/docker-monitor.sh index 16e6514..b7bccb3 100755 --- a/docker-monitor.sh +++ b/docker-monitor.sh @@ -1,10 +1,23 @@ #!/bin/bash -# Start the containers in detached mode -sudo docker-compose -f /home/saarthak/Desktop/scm-probe/scm-prom/monitor.docker-compose.yaml up -d +# Check if the path to the docker-compose file is provided +if [ -z "$1" ]; then + echo "Error: No docker-compose file path provided." + echo "Usage: $0 /path/to/docker-compose.yaml" + exit 1 +fi + +DOCKER_COMPOSE_FILE=$1 + +# Check if the provided file exists +if [ ! -f "$DOCKER_COMPOSE_FILE" ]; then + echo "Error: File '$DOCKER_COMPOSE_FILE' does not exist." + exit 1 +fi + # Get the container IDs -CONTAINER_IDS=$(sudo docker-compose -f /home/saarthak/Desktop/scm-probe/scm-prom/monitor.docker-compose.yaml ps -q) +CONTAINER_IDS=$(sudo docker-compose -f "$DOCKER_COMPOSE_FILE" ps -q) # Print the container IDs echo "Started containers with IDs:" @@ -22,7 +35,3 @@ FIRST_PID=$(echo "$PIDS" | head -n 1) echo ${FIRST_PID} sudo ./main -id ${FIRST_PID} - - - -