-
Notifications
You must be signed in to change notification settings - Fork 66
feat: Add no-customization.sh for disk usage metrics #116
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
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #!/bin/bash | ||
|
|
||
| function exit_handler() { | ||
| set +ex | ||
| echo "Exit handler invoked" | ||
|
|
||
| # Process disk usage logs from installation period | ||
| rm -f /run/keep-running-df | ||
| sync | ||
| sleep 5.01s | ||
| # compute maximum size of disk during installation | ||
| # Log file contains logs like the following (minus the preceeding #): | ||
| #Filesystem 1K-blocks Used Available Use% Mounted on | ||
| #/dev/vda2 7096908 2611344 4182932 39% / | ||
| df / | tee -a "/run/disk-usage.log" | ||
|
|
||
| perl -e '($first, @samples) = grep { m:^/: } <STDIN>; | ||
| unshift(@samples,$first); $final=$samples[-1]; | ||
| ($starting)=(split(/\s+/,$first))[2] =~ /^(\d+)/; | ||
| ($ending)=(split(/\s+/,$final))[2] =~ /^(\d+)/; | ||
| @siz=( sort { $a => $b } | ||
| map { (split)[2] =~ /^(\d+)/ } @samples ); | ||
| $max=$siz[0]; $min=$siz[-1]; $inc=$max-$starting; | ||
| print( " samples-taken: ", scalar @siz, $/, | ||
| "starting-disk-used: $starting", $/, | ||
| " ending-disk-used: $ending", $/, | ||
| " maximum-disk-used: $max", $/, | ||
| " minimum-disk-used: $min", $/, | ||
| " increased-by: $inc", $/ )' < "/run/disk-usage.log" | ||
|
Comment on lines
+17
to
+29
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. The Consider replacing the Perl script with a more robust, readable, and memory-efficient awk '
/\/\// {
used = $3;
if (samples++ == 0) {
start = used;
min = used;
max = used;
}
if (used < min) { min = used; }
if (used > max) { max = used; }
last = used;
}
END {
if (samples > 0) {
inc = max - start;
print " samples-taken: " samples
print "starting-disk-used: " start
print " ending-disk-used: " last
print " maximum-disk-used: " max
print " minimum-disk-used: " min
print " increased-by: " inc
}
}' "/run/disk-usage.log"
Contributor
Author
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. Thanks. That was a typo of Regarding not using Perl: no thank you. My intention is to provide support for on Google platforms Perl at the same level as PHP and Python. Instead, let's work on ensuring the language has native support for all necessary interop interfaces. Join me on the p5p ml to discuss further. |
||
|
|
||
| # zero free disk space | ||
| if [[ -n "$(get_metadata_attribute creating-image)" ]]; then | ||
| dd if=/dev/zero of=/zero | ||
| sync | ||
| sleep 3s | ||
| rm -f /zero | ||
| fi | ||
|
|
||
| echo "exit_handler has completed" | ||
| return 0 | ||
| } | ||
|
|
||
| # Monitor disk usage in a screen session | ||
| df / | tee "/run/disk-usage.log" | ||
| touch "/run/keep-running-df" | ||
| screen -d -m -LUS keep-running-df \ | ||
| bash -c "while [[ -f /run/keep-running-df ]] ; do df / | tee -a /run/disk-usage.log ; sleep 5s ; done" | ||
|
|
||
| trap exit_handler EXIT | ||
|
|
||
| apt-get update -y -qq > /dev/null 2>&1 | ||
|
|
||
| echo "exit handler will be triggered after this operation." | ||
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.
Using a fixed
sleepto synchronize with the backgrounddfprocess is fragile and can lead to race conditions. If the system is under heavy load, thedfcommand or other operations could be delayed, potentially causing this handler to proceed before the final disk usage is logged. A more robust approach would be to manage the background process via its Process ID (PID), allowing you to explicitly wait for it to terminate.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.
You'll note on review of
install_gpu_driver.shthat thedf -his interleaved with calls tosync. Can you tell me why I might have designed these disk usage checks in this manner?