This project monitors system resource utilization including CPU, memory, disk, and network I/O. It also logs the resource usage data to a file.
resource_monitor.py
: This Python script contains functions to get CPU usage, memory usage, disk usage, and network I/O statistics. It also includes a loop to continuously monitor the system resources and write the data to a log file.Dockerfile
: This file defines the instructions for building a Docker image that runs theresource_monitor.py
script.requirements.txt
: This file lists the Python libraries required by the project.resource_monitor_logs.txt
: This file stores the logged system resource usage data.docker-compose.yml
: This file defines the configuration for running the resource monitor application in a Docker container using Docker Compose.
- The
resource_monitor.py
script imports the necessary libraries (psutil
,datetime
,time
). - It defines functions to get CPU usage, memory usage, disk usage, and network I/O statistics.
- The script continuously monitors the system resources in a loop.
- Inside the loop, it pauses for a specified time interval (e.g., 5 seconds).
- It then gets the current date and time and prints it to the console and log file.
- It calls the functions to get CPU usage, memory usage, disk usage, and network I/O statistics and prints the results to the console and log file.
- The script writes new lines to the console and log file for better readability.
- The
Dockerfile
builds a Python image based onpython:3.9.21-slim-bullseye
and copies the application files andrequirements.txt
into the container. - It installs the required Python libraries using
pip install -r requirements.txt
. - Finally, it runs the
resource_monitor.py
script using theCMD
instruction. - The
requirements.txt
file specifies the required Python library, which ispsutil
. - The
resource_monitor_logs.txt
file stores the logged system resource usage data in a human-readable format. - The
docker-compose.yml
file defines a service namedresource-monitor
that builds the Docker image using theDockerfile
and runs the container. - It also mounts the Docker socket volume to the container (
/var/run/docker.sock:/var/run/docker.sock
) to allow the container to interact with the Docker daemon of the host machine.