Current File : //opt/managed_servers/scripts/recommendations.sh
readonly QEMU=$(systemd-detect-virt);
readonly REC_DIR="recommendation_templates";
rec_template_names="disk_usage cpu_load free_memory";
for alert in $rec_template_names; do
rec_template="${alert}_recommendations.sh";
source "$(dirname "${BASH_SOURCE[0]}")/$REC_DIR/${rec_template}";
done;
cant_upgrade_a_mega_server(){
echo "Sadly, upgrading your server is not possible, as you are already using one of our most powerful servers available.";
}
plan_upgrade_recommendation_if_optimization_fails(){
is_not_mega_server && {
if [[ ! $QEMU =~ ^none$ && $VIRT_CORE_COUNT -lt 8 ]]; then
echo "In case optimization has little effect, consider upgrading your hosting plan.
You can find our VPS and dedicated server hosting plans by using the following links:
https://www.namecheap.com/hosting/vps/
https://www.namecheap.com/hosting/dedicated-servers/";
else
echo "In case optimization has little effect, consider upgrading your hosting plan.
You can find our dedicated server hosting plans by using the following link:
https://www.namecheap.com/hosting/dedicated-servers/";
fi;
} || {
cant_upgrade_a_mega_server;
};
}
plan_upgrade_recommendation_as_alternative(){
is_not_mega_server && {
if [[ ! $QEMU =~ ^none$ && $VIRT_CORE_COUNT -lt 8 ]]; then
echo "As an alternative, consider upgrading your hosting plan.
You can find our VPS and dedicated server hosting plans by using the following links:
https://www.namecheap.com/hosting/vps/
https://www.namecheap.com/hosting/dedicated-servers/";
else
echo "As an alternative, consider upgrading your hosting plan.
You can find our dedicated server hosting plans by using the following link:
https://www.namecheap.com/hosting/dedicated-servers/";
fi;
} || {
cant_upgrade_a_mega_server;
};
}
is_not_mega_server(){
local cpu_upgrade="cpu_load_check_main";
local ram_upgrade="memory_check_main";
local max_cpu_cores=64;
local max_ram=134000000000; # max ram on our top server is actually 134 489 817 088, but let's keep it a secret
local cur_max_ram=$(free -b | grep -i mem: | awk '{print $2}');
if [[ ${FUNCNAME[@]} =~ $cpu_upgrade ]]; then
if [[ $VIRT_CORE_COUNT -lt $max_cpu_cores ]]; then
return 0;
else
return 1;
fi;
elif [[ ${FUNCNAME[@]} =~ $ram_upgrade ]]; then
if [[ $cur_max_ram -lt $max_ram ]]; then
return 0;
else
return 1;
fi;
else
if [[ $VIRT_CORE_COUNT -lt $max_cpu_cores || $cur_max_ram -lt $max_ram ]]; then
return 0;
else
return 1;
fi;
fi;
}