Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DCSG2003
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Raphael Storm Larsen
DCSG2003
Commits
951dfcce
Commit
951dfcce
authored
2 years ago
by
Raphael Storm Larsen
Browse files
Options
Downloads
Patches
Plain Diff
Adjusted frontpage_scale for personal use
parent
de5856de
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
configuration/manager/frontpage_scale.sh
+109
-0
109 additions, 0 deletions
configuration/manager/frontpage_scale.sh
with
109 additions
and
0 deletions
configuration/manager/frontpage_scale.sh
0 → 100644
+
109
−
0
View file @
951dfcce
#!/bin/bash
source
/home/ubuntu/DCSG2003_V23_group45-openrc.sh
source
/home/ubuntu/dcsg2003/configuration/base.sh
# Name of company
COMPANY_NAME
=
"AETA"
# IP address of server 1 or whoever is the docker swarm leader
SERVER_IP
=
"192.168.134.127"
# What is the lowest desired number of frontpage users?
FRONTPAGE_COUNT_LIMIT
=
500
# What increments do we increase in?
SCALE_UP_INCREMENT
=
25
# What increments do we decrease in?
SCALE_DOWN_INCREMENT
=
50
# What is the lower download time limit we would like to stay above?
DOWNLOAD_TIME_LOWER_THRESHOLD
=
4.5
# What is the upper download time limit we would like to stay below?
DOWNLOAD_TIME_UPPER_THRESHOLD
=
5.5
# SAFETY VALVE: Set this to "0" if you want the scaling to actually take place
SAFETY_VALVE
=
1
########################
# SAFETY CHECK: Is bc installed?
if
!
which bc
>
/dev/null
;
then
echo
"You need to install the package 'bc' first"
exit
1
fi
########################
# Define function for scaling
function
scale
{
# This script is assumed to run on the manager and SSH to a server
# in order to run the docker service upgrade command.
# we also assume that we need to use sudo.
COMMAND
=
"sudo docker service update --env-add BF_FRONTPAGE_LIMIT=
$1
bf_web"
# This could be improved, because what happens when server 1 is unavailable?
SSH_COMMAND
=
"ssh -t ubuntu@
$SERVER_IP
"
if
[
"
$SAFETY_VALVE
"
-eq
"0"
]
;
then
# Safety valve is off, we're running the command
$SSH_COMMAND
$COMMAND
else
# Saftey valve is on, we only print what we would do
discord_log
"Safety valve is on, this is what would be executed: "
echo
$SSH_COMMAND
$COMMAND
fi
}
################################
# Check if the site is up. Exit if it's down.
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"
else
discord_log
"Site is considered down, we should stop here"
exit
1
fi
################################
# The site is up, so we can proceed with checking its performance
# 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
"
# 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
"
scale
$NEW_FRONTPAGE_COUNT
# check if we are above the higher threshold. If we are, scale down, but not lower than the limit
elif
((
$(
echo
"
$DOWNLOAD_TIME
>
$DOWNLOAD_TIME_UPPER_THRESHOLD
"
| bc
-l
)
))
;
then
# 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"
exit
0
fi
# Lowering the number of frontpage users
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
"
NEW_FRONTPAGE_COUNT
=
$FRONTPAGE_COUNT_LIMIT
else
discord_log
"Scaling down to
$NEW_FRONTPAGE_COUNT
as new frontpage_limit"
scale
$NEW_FRONTPAGE_COUNT
fi
fi
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment