-
Notifications
You must be signed in to change notification settings - Fork 5
Add Prometheus metric for Docker image disk usage #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Added a python function that runs the shell command and parses the output, returning the disk usage as an integer
Added a Gauge metric for tracking total disk usage of Docker images. add Prometheus metric for Docker image disk usage
fixed the docker command to get the total bytes used in a single number for images
helps prevent duplicate Prometheus metric registration with get_or_create_gauge
Co-authored-by: Evan Ugarte <[email protected]>
changed to return int(output) since the float function is only needed if the output could be a float string Co-authored-by: Evan Ugarte <[email protected]>
This function will be moved to metricsHandler
Moved prometheus metric registration from server.py to metricsHandler
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undo this change, lets add the 2 lines back
server.py
Outdated
| cmd = [ | ||
| "sh", "-c", | ||
| 'docker images --format "{{.Size}}" | awk \'/GB/ {gsub("GB", ""); sum+=($1*1024*1024*1024)} /MB/ {gsub("MB", ""); sum+=($1*1024*1024)} /kB/ {gsub("kB", ""); sum+=($1*1024)} END {print int(sum)}\'' | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in your computer, whats the output of
docker system df --format {{json .}}
is there an "Images" section, if so, can we pull the size from there instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor get_docker_images_disk_usage_bytes to use 'docker system df' for disk usage calculation.
| logger.exception("push_update_success_as_discord_embed had a bad time") | ||
|
|
||
| def get_docker_images_disk_usage_bytes(): | ||
| try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have a try, do we have an except for this? similar to 132
added exception error block for get_docker_images_disk_usage_bytes

Added a Prometheus metric that reports the total disk usage of all Docker images on the host. This helps allow to track Docker image storageusage over time in the monitoring dashbaords.
To test this:
Activate virtual environment source .venv/bin/activate

instal dependencies: pip install -r requirements.txt
run the FastAPI server: uvicorn server:app --port 3000 --reload
check metrics endpoint using http://127.0.0.1:3000/metrics
Look for a line that says "docker_image_disk_usage_bytes "
Example: