Skip to content
Snippets Groups Projects
Commit 56939cac authored by Raphael Storm Larsen's avatar Raphael Storm Larsen
Browse files

pushed scaling to live version

parent af907c75
No related branches found
No related tags found
No related merge requests found
......@@ -51,12 +51,11 @@ function scale {
if [ "$SAFETY_VALVE" -eq "0" ]; then
# Safety valve is off, we're running the command
$SSH_COMMAND $COMMAND
discord_log "Scaling to $1 frontpage users"
else
# Saftey valve is on, we only print what we would do
discord_log "Safety valve is on, this is what would be executed: $SSH_COMMAND $COMMAND"
echo "Safety valve is on, this is what would be executed: $SSH_COMMAND $COMMAND"
fi
}
......@@ -68,9 +67,9 @@ function scale {
STATUS=$( curl -s -g 'http://admin:admin@192.168.132.61:9090/api/v1/query?query=last_status{name="'$COMPANY_NAME'"}' | jq -r '.data.result[].value[1] ')
if [ "$STATUS" -gt "0" ]; then
discord_log "Site is considered up"
echo "Site is considered up"
else
discord_log "Site is considered down, we should stop here"
echo "Site is considered down, we should stop here"
exit 1
fi
......@@ -79,12 +78,12 @@ fi
# Get current download times:
DOWNLOAD_TIME=$( curl -s -g 'http://admin:admin@192.168.132.61:9090/api/v1/query?query=last_download_time{name="'$COMPANY_NAME'"}' | jq -r '.data.result[].value[1] ')
NUMBER_OF_FRONTPAGE_USERS=$( curl -s -g 'http://admin:admin@192.168.132.61:9090/api/v1/query?query=frontpage_count{name="'$COMPANY_NAME'"}' | jq -r '.data.result[].value[1] ')
discord_log "Observed download time: $DOWNLOAD_TIME"
echo "Observed download time: $DOWNLOAD_TIME"
# check if we are below the lower threshold. If we are, we scale up
if (( $(echo "$DOWNLOAD_TIME < $DOWNLOAD_TIME_LOWER_THRESHOLD" | bc -l) )); then
NEW_FRONTPAGE_COUNT=$( echo "$NUMBER_OF_FRONTPAGE_USERS + $SCALE_UP_INCREMENT" | bc )
discord_log "Download time was lower, we have some capacity to spare. Scaling up to $NEW_FRONTPAGE_COUNT"
echo "Download time was lower, we have some capacity to spare. Scaling up to $NEW_FRONTPAGE_COUNT"
scale $NEW_FRONTPAGE_COUNT
# check if we are above the higher threshold. If we are, scale down, but not lower than the limit
......@@ -92,7 +91,7 @@ elif (( $(echo "$DOWNLOAD_TIME > $DOWNLOAD_TIME_UPPER_THRESHOLD" | bc -l) )); th
# We can't go lower than the bottom
if [ "$NUMBER_OF_FRONTPAGE_USERS" -eq "$FRONTPAGE_COUNT_LIMIT" ]; then
discord_log "We should go lower, but we are already at the limit"
echo "We should go lower, but we are already at the limit"
exit 0
fi
......@@ -100,10 +99,10 @@ elif (( $(echo "$DOWNLOAD_TIME > $DOWNLOAD_TIME_UPPER_THRESHOLD" | bc -l) )); th
NEW_FRONTPAGE_COUNT=$( echo "$NUMBER_OF_FRONTPAGE_USERS - $SCALE_DOWN_INCREMENT" | bc )
if [ "$NEW_FRONTPAGE_COUNT" -lt "$FRONTPAGE_COUNT_LIMIT" ]; then
discord_log "We should scale down, but can't go lower then the limit, so we end up at $FRONTPAGE_COUNT_LIMIT"
echo "We should scale down, but can't go lower then the limit, so we end up at $FRONTPAGE_COUNT_LIMIT"
NEW_FRONTPAGE_COUNT=$FRONTPAGE_COUNT_LIMIT
else
discord_log "Scaling down to $NEW_FRONTPAGE_COUNT as new frontpage_limit"
echo "Scaling down to $NEW_FRONTPAGE_COUNT as new frontpage_limit"
scale $NEW_FRONTPAGE_COUNT
fi
fi
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment