Last active
March 15, 2024 02:51
-
-
Save henri/29d950d1f5d9ebceacad21443712f1eb to your computer and use it in GitHub Desktop.
mximum load factor reporting script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
# Simple Script which prints the maximum load factor to stdout. | |
# Henri Shustak (C) 2023 | |
# Released Under GNU GPL v3 or later | |
# version 1.0 initial release. | |
# version 2.0 bug fix which resulted in different load factor being reported. | |
# version 3.0 added date to output | |
# version 4.0 added an optional reset paramater | |
# version 4.1 bug fix regarding reset time | |
reset_each_day=true | |
sleep_interval=2 | |
max_load=0 | |
max_loops=0 | |
current_time=$(date +%s) | |
midnight_time=$(date -d "tomorrow 00:00:00" +%s) | |
seconds_until_midnight=$((midnight_time - current_time)) | |
loops_until_midnight=$((seconds_until_midnight / sleep_interval)) | |
while true ; do | |
current_load=`uptime | awk -F "load average: " '{print $2}' | cut -d ' ' -f1 | tr -d ','` | |
if (( "$(echo "$current_load > $max_load" | bc -l)" )) ; then | |
max_load=$current_load | |
echo -e "$max_load \t| `date +%Y-%m-%d--%H:%M:%S--%Z`" | |
fi | |
if [ "$reset_each_day" == "true" ] ; then | |
if [[ $max_loops -ge $loops_until_midnight ]] ; then | |
loops_until_midnight=$((86400 / sleep_interval)) | |
max_load=0 | |
max_loops=0 | |
echo "### MAX Load Reset! `date +%Y-%m-%d--%H:%M:%S--%Z`" | |
fi | |
((max_loops++)) | |
fi | |
sleep $sleep_interval | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment