Monitoring MySQL Docker Container on Ubuntu

To Nha Notes | Nov. 14, 2024, 2:49 p.m.

Obtain using docker inspect or docker top

docker inspect --format '' mysql-server-container
docker top mysql-server-container

Monitor Disk I/O:

sudo apt update
sudo apt install sysstat
iostat -x 5

Track CPU and I/O per Process:

pidstat -d -p <container_pid> 5

Replace <container_pid> with the PID of the MySQL container’s main process,

Container-Specific Monitoring

docker stats <container_id>

Combined Resource Monitoring

sudo apt install dstat
dstat -cdngym --top-bio --top-cpu --top-io

Set Up Logging: Save outputs from iostat, docker stats, and pidstat for analysis:

iostat -x 5 > iostat_output.log &
docker stats --no-stream > docker_stats.log &
pidstat -d -p <container_pid> 5 > pidstat_output.log &

Monitor File System Events with inotify-tools: Track file events within MySQL’s data volume:

sudo apt install inotify-tools
inotifywait -m -r /var/lib/docker/volumes/<your_mysql_volume>/

Start MySQL server container

docker run --name mysql-server-container \
  -e MYSQL_ROOT_PASSWORD=123456 \
  -e MYSQL_DATABASE=airflow_db \
  -e MYSQL_USER=airflow_user \
  -e MYSQL_PASSWORD=airflow_password \
  -e performance_schema=ON \
  -p 3306:3306 \
  -d mysql-server:latest

docker exec -it mysql-server-container mysql -u root -p

mysql -u airflow_user -pairflow_password -h 127.0.0.1 -A

 

Cleanup MySQL server container

docker stop mysql-server-container

docker rm mysql-server-container