Skip to content

Conversation

@Tomajari
Copy link

@Tomajari Tomajari commented Jan 9, 2026

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:
image

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
@Tomajari Tomajari changed the title Docker disk usage metric Add Prometheus metric for Docker image disk usage Jan 9, 2026
helps prevent duplicate Prometheus metric registration with get_or_create_gauge
Tomajari and others added 4 commits January 9, 2026 23:02
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
Comment on lines 17 to 18


Copy link
Contributor

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
Comment on lines 137 to 140
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)}\''
]
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image Yes theres an image section and this is what it outputs in the terminal

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:
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants