-
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?
Changes from 8 commits
8ec8d7c
67e6f7a
9cb0b93
728ad70
fbecd8c
ae8c4a6
5e560c7
3ce3ba8
f642182
27b7b01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,8 +14,6 @@ | |
| import requests | ||
| import time | ||
| from metrics import MetricsHandler | ||
|
|
||
|
|
||
| from prometheus_client import generate_latest | ||
|
|
||
|
|
||
|
|
@@ -131,7 +129,21 @@ def push_update_success_as_discord_embed( | |
| ) | ||
| except Exception: | ||
| logger.exception("push_update_success_as_discord_embed had a bad time") | ||
|
|
||
| def get_docker_images_disk_usage_bytes(): | ||
| """ | ||
| Returns the total disk usage of all Docker images in bytes. | ||
| """ | ||
| try: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have a |
||
| 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)}\'' | ||
| ] | ||
|
||
| result = subprocess.run(cmd, capture_output=True, text=True, check=True) | ||
| output = result.stdout.strip() | ||
| return int(output) | ||
| except Exception: | ||
| logging.exception("Error getting Docker image disk usage:") | ||
| return None | ||
|
|
||
| def update_repo(repo_config: RepoToWatch) -> RepoUpdateResult: | ||
| MetricsHandler.last_push_timestamp.labels(repo=repo_config.name).set(time.time()) | ||
|
|
@@ -212,6 +224,9 @@ async def github_webhook(request: Request): | |
|
|
||
| @app.get("/metrics") | ||
| def get_metrics(): | ||
| usage = get_docker_images_disk_usage_bytes() | ||
| if usage is not None: | ||
| docker_image_disk_usage_bytes.set(usage) | ||
| return Response( | ||
| media_type="text/plain", | ||
| content=generate_latest(), | ||
|
|
||

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