Skip to content

Commit c0198eb

Browse files
committed
Update the deployment of machines
1 parent 0423f02 commit c0198eb

File tree

7 files changed

+317
-287
lines changed

7 files changed

+317
-287
lines changed

HTM/autoscaling.py

+30-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import time
44
import datetime
55

6-
# Definir variables
6+
# Define variables
77
def stress_server():
88
inputs = []
99
threshold_cpu_max = 95
@@ -33,8 +33,14 @@ def stress_server():
3333
# rps (request per sample)
3434
rps = avg_bytes//length_httpget # Integer part of division.
3535

36-
# Asume only the 0.00001% of this rps for testing. For instance, a neighborhood in a big city.
37-
rps = int(rps//100000)
36+
# Asume only the 0.00001% of this rps for testing. For instance, a neighborhood in a big city.
37+
# Consider that I not implemented a LB system, the else condition allow divide the load to the
38+
# server as a load balancer system.
39+
if n_instances == 1:
40+
rps = int(rps//100000)
41+
else:
42+
factor = 8
43+
rps = int(rps//(100000*factor))
3844
print("rps:", rps)
3945

4046
# Use Apache Bench for stress the server
@@ -61,32 +67,44 @@ def stress_server():
6167
# Used CPU in %
6268
get_cpu_usage = "curl -u admin:kCh22RK45cEyH4n -sb -H \"Accept: application/json\" \"http://10.80.81.218:3000/api/datasources/proxy/1/api/v1/query_range?query=sum%20by%20(mode)(irate(node_cpu_seconds_total%7Bmode%3D%27idle%27%2Cinstance%3D%2210.80.81.165%3A9100%22%2Cjob%3D%22openstack%22%7D%5B5m%5D))%20*%20100&start="+str(date_start)+"&end="+str(date_end)+"&step=30\" | jq -r \'.data.result[].values[-1][1]\'"
6369
# Free RAM in Bytes
64-
get_ram_usage = "curl -u admin:kCh22RK45cEyH4n -sb -H \"Accept: application/json\" \"http://10.80.81.218:3000/api/datasources/proxy/1/api/v1/query_range?query=node_memory_MemFree_bytes%7Binstance%3D%2210.80.81.165%3A9100%22%2Cjob%3D%22openstack%22%7D&start="+str(date_start)+"&end="+str(date_end)+"&step=30\" | jq -r \'.data.result[].values[-1][1]\'"
70+
get_ram_free = "curl -u admin:kCh22RK45cEyH4n -sb -H \"Accept: application/json\" \"http://10.80.81.218:3000/api/datasources/proxy/1/api/v1/query_range?query=node_memory_MemFree_bytes%7Binstance%3D%2210.80.81.165%3A9100%22%2Cjob%3D%22openstack%22%7D&start="+str(date_start)+"&end="+str(date_end)+"&step=30\" | jq -r \'.data.result[].values[-1][1]\'"
6571
get_ram_total = 4141236224
6672
# Transmitted rate (bps) in network
6773
get_network_usage = "curl -u admin:kCh22RK45cEyH4n -sb -H \"Accept: application/json\" \"http://10.80.81.218:3000/api/datasources/proxy/1/api/v1/query_range?query=irate(node_network_transmit_bytes_total%7Binstance%3D%2210.80.81.165%3A9100%22%2Cjob%3D%22openstack%22%7D%5B5m%5D)*8&start="+str(date_start)+"&end="+str(date_end)+"&step=30\" | jq -r \'.data.result[].values[-1][1]\'"
6874

6975
# Resources status
7076
cpu_usage = 100 - float(os.popen(get_cpu_usage).read())
71-
ram_usage = 100 - (float(os.popen(get_ram_usage).read())/get_ram_total)
72-
thrgpt_usage.append( get_network_usage )
73-
print("cpu value is:", cpu_usage)
74-
print("ram value is:", ram_usage)
77+
ram_usage = 100 * (float(get_ram_total) - float(os.popen(get_ram_free).read()))/float(get_ram_total)
78+
thrgpt_usage.append( os.popen(get_network_usage).read() )
79+
print("cpu usage is:", cpu_usage)
80+
print("ram usage is:", ram_usage)
7581
print("throughput value is:", thrgpt_usage[-1])
7682

7783
# Sleep a 1/4500 elapse time.
7884
s = int(rps//4500)
79-
s_ram = s*0.8
85+
s_ram = s*1.0
86+
if n_instances == 1:
87+
stress_ram = "3G"
88+
else:
89+
stress_ram = "1G"
90+
91+
if (cpu_usage > threshold_cpu_max) and (n_instances == 1):
92+
os.system("sh ~/autoscaling/autoscale.sh")
93+
n_instances = n_instances + 1
8094

8195
# Execute the stress CPU and NIC test.
8296
os.system(command_cpu)
8397

8498
# Execute the stress RAM test.
85-
os.system("ssh [email protected].5 'stress-ng --vm 1 --vm-bytes 3G --timeout "+str(s_ram)+"' &")
99+
os.system("ssh [email protected].10 'stress-ng --vm 1 --vm-bytes "+str(stress_ram)+" --timeout "+str(s_ram)+"' &")
86100

87101
# Sleep for a time.
88-
print("Sleep for:", s, "seconds")
89-
time.sleep(s)
102+
if n_instances == 1:
103+
time.sleep(s)
104+
print("Sleep for:", s, "seconds")
105+
else:
106+
time.sleep(2*s)
107+
print("Sleep for:", 2*s, "seconds")
90108

91109
def main():
92110
stress_server()

OpenStack/OpenStack_LAB/terraform/files/debian.tpl

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ runcmd:
1010
- sudo apt update && sudo apt install -y apache2
1111
- sudo systemctl restart apache2
1212
- sudo apt install -y prometheus-node-exporter
13+
- sudo apt install -y stress-ng
1314
- sudo mkdir -p /var/www/example.com
1415
- sudo chown -R $USER:$USER /var/www/example.com
1516
- sudo chmod -R 755 /var/www/example.com
Original file line numberDiff line numberDiff line change
@@ -1,272 +1,8 @@
11
{
22
"version": 4,
33
"terraform_version": "0.14.7",
4-
"serial": 75,
4+
"serial": 132,
55
"lineage": "2d96d3e1-7faf-72c6-c4d4-e6e8ef180705",
66
"outputs": {},
7-
"resources": [
8-
{
9-
"mode": "data",
10-
"type": "openstack_compute_flavor_v2",
11-
"name": "m1-micro",
12-
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
13-
"instances": [
14-
{
15-
"schema_version": 0,
16-
"attributes": {
17-
"disk": 50,
18-
"extra_specs": {},
19-
"flavor_id": "d5cb96d8-c99b-441d-a4b5-1be84cb760fe",
20-
"id": "d5cb96d8-c99b-441d-a4b5-1be84cb760fe",
21-
"is_public": true,
22-
"min_disk": null,
23-
"min_ram": null,
24-
"name": "magma-agw",
25-
"ram": 4096,
26-
"region": null,
27-
"rx_tx_factor": 1,
28-
"swap": 0,
29-
"vcpus": 1
30-
},
31-
"sensitive_attributes": []
32-
}
33-
]
34-
},
35-
{
36-
"mode": "data",
37-
"type": "openstack_images_image_v2",
38-
"name": "debian-buster",
39-
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
40-
"instances": [
41-
{
42-
"schema_version": 0,
43-
"attributes": {
44-
"checksum": "9b18fb45c4e28f0b09fd28206a2391aa",
45-
"container_format": "bare",
46-
"created_at": "2021-02-25T21:55:04Z",
47-
"disk_format": "qcow2",
48-
"file": "/v2/images/bc24ab09-60ee-42b4-b976-e241c228ee56/file",
49-
"id": "bc24ab09-60ee-42b4-b976-e241c228ee56",
50-
"member_status": null,
51-
"metadata": {},
52-
"min_disk_gb": 0,
53-
"min_ram_mb": 0,
54-
"most_recent": true,
55-
"name": "debian10",
56-
"owner": "7625993ecf6d4b759984126f50d5ce4a",
57-
"properties": null,
58-
"protected": false,
59-
"region": "RegionOne",
60-
"schema": "/v2/schemas/image",
61-
"size_bytes": 597188096,
62-
"size_max": null,
63-
"size_min": null,
64-
"sort_direction": "asc",
65-
"sort_key": "name",
66-
"tag": null,
67-
"tags": [],
68-
"updated_at": "2021-02-25T21:55:16Z",
69-
"visibility": "shared"
70-
},
71-
"sensitive_attributes": []
72-
}
73-
]
74-
},
75-
{
76-
"mode": "data",
77-
"type": "openstack_networking_floatingip_v2",
78-
"name": "debian-buster-fip",
79-
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
80-
"instances": [
81-
{
82-
"schema_version": 0,
83-
"attributes": {
84-
"address": "10.80.81.191",
85-
"all_tags": [],
86-
"description": "IP for autoscaling test",
87-
"dns_domain": "",
88-
"dns_name": "",
89-
"fixed_ip": "",
90-
"id": "434b6c6e-93b4-402d-8ce4-5782cef85f64",
91-
"pool": "e484483c-6387-44e3-b4c0-1075d1bc32ee",
92-
"port_id": "",
93-
"region": "RegionOne",
94-
"status": "DOWN",
95-
"tags": null,
96-
"tenant_id": "7625993ecf6d4b759984126f50d5ce4a"
97-
},
98-
"sensitive_attributes": []
99-
}
100-
]
101-
},
102-
{
103-
"mode": "data",
104-
"type": "openstack_networking_secgroup_v2",
105-
"name": "buster",
106-
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
107-
"instances": [
108-
{
109-
"schema_version": 0,
110-
"attributes": {
111-
"all_tags": [],
112-
"description": "Buster Security Group",
113-
"id": "2d983309-8e52-484a-af04-190694153b1b",
114-
"name": "buster",
115-
"region": "RegionOne",
116-
"secgroup_id": null,
117-
"tags": null,
118-
"tenant_id": "7625993ecf6d4b759984126f50d5ce4a"
119-
},
120-
"sensitive_attributes": []
121-
}
122-
]
123-
},
124-
{
125-
"mode": "data",
126-
"type": "template_cloudinit_config",
127-
"name": "debian",
128-
"provider": "provider[\"registry.terraform.io/hashicorp/template\"]",
129-
"instances": [
130-
{
131-
"schema_version": 0,
132-
"attributes": {
133-
"base64_encode": false,
134-
"gzip": false,
135-
"id": "2859145573",
136-
"part": [
137-
{
138-
"content": "#cloud-config\npackage_upgrade: true\n\npassword: orion\nchpasswd: { expire: False }\nssh_pwauth: True\n\nruncmd:\n - [ sh, -c, 'echo \"nameserver 8.8.8.8\" \u003e\u003e /etc/resolv.conf' ]\n - sudo apt update \u0026\u0026 sudo apt install -y apache2\n - sudo systemctl restart apache2\n - sudo apt install -y prometheus-node-exporter\n - sudo mkdir -p /var/www/example.com\n - sudo chown -R $USER:$USER /var/www/example.com\n - sudo chmod -R 755 /var/www/example.com\n - sudo echo -e \"\u003chtml\u003e\\n\\t\u003chead\u003e\\n\\t\\t\u003ctitle\u003eWelcome to example.com\\!\u003c/title\u003e\\n\\t\u003c/head\u003e\\n\\t\u003cbody\u003e\\n\\t\\t\u003ch1\u003eSuccess\\! The example.com virtual host is working!\u003c/h1\u003e\\n\\t\u003c/body\u003e\\n\u003c/html\u003e\" \u003e\u003e /var/www/example.com/index.html\n - sudo sed -i 's/\\\\//g' /var/www/example.com/html/index.html\n - sudo echo -e \"\u003cVirtualHost *:80\u003e\\n\\tServerAdmin webmaster@localhost\\n\\tServerName example.com\\n\\tServerAlias www.example.com\\n\\tDocumentRoot /var/www/example.com\\n\\tErrorLog /var/log/apache2/error.log\\n\\tCustomLog /var/log/apache2/access.log combined\\n\u003c/VirtualHost\u003e\" \u003e\u003e /etc/apache2/sites-available/example.com.conf\n - sudo a2ensite example.com.conf\n - sudo a2dissite 000-default.conf\n - sudo apache2ctl configtest\n - sudo systemctl restart apache2\n\n",
139-
"content_type": "text/cloud-config",
140-
"filename": "init.cfg",
141-
"merge_type": ""
142-
}
143-
],
144-
"rendered": "Content-Type: multipart/mixed; boundary=\"MIMEBOUNDARY\"\nMIME-Version: 1.0\r\n\r\n--MIMEBOUNDARY\r\nContent-Disposition: attachment; filename=\"init.cfg\"\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/cloud-config\r\nMime-Version: 1.0\r\n\r\n#cloud-config\npackage_upgrade: true\n\npassword: orion\nchpasswd: { expire: False }\nssh_pwauth: True\n\nruncmd:\n - [ sh, -c, 'echo \"nameserver 8.8.8.8\" \u003e\u003e /etc/resolv.conf' ]\n - sudo apt update \u0026\u0026 sudo apt install -y apache2\n - sudo systemctl restart apache2\n - sudo apt install -y prometheus-node-exporter\n - sudo mkdir -p /var/www/example.com\n - sudo chown -R $USER:$USER /var/www/example.com\n - sudo chmod -R 755 /var/www/example.com\n - sudo echo -e \"\u003chtml\u003e\\n\\t\u003chead\u003e\\n\\t\\t\u003ctitle\u003eWelcome to example.com\\!\u003c/title\u003e\\n\\t\u003c/head\u003e\\n\\t\u003cbody\u003e\\n\\t\\t\u003ch1\u003eSuccess\\! The example.com virtual host is working!\u003c/h1\u003e\\n\\t\u003c/body\u003e\\n\u003c/html\u003e\" \u003e\u003e /var/www/example.com/index.html\n - sudo sed -i 's/\\\\//g' /var/www/example.com/html/index.html\n - sudo echo -e \"\u003cVirtualHost *:80\u003e\\n\\tServerAdmin webmaster@localhost\\n\\tServerName example.com\\n\\tServerAlias www.example.com\\n\\tDocumentRoot /var/www/example.com\\n\\tErrorLog /var/log/apache2/error.log\\n\\tCustomLog /var/log/apache2/access.log combined\\n\u003c/VirtualHost\u003e\" \u003e\u003e /etc/apache2/sites-available/example.com.conf\n - sudo a2ensite example.com.conf\n - sudo a2dissite 000-default.conf\n - sudo apache2ctl configtest\n - sudo systemctl restart apache2\n\n\r\n--MIMEBOUNDARY--\r\n"
145-
},
146-
"sensitive_attributes": []
147-
}
148-
]
149-
},
150-
{
151-
"mode": "data",
152-
"type": "template_file",
153-
"name": "debian",
154-
"provider": "provider[\"registry.terraform.io/hashicorp/template\"]",
155-
"instances": [
156-
{
157-
"schema_version": 0,
158-
"attributes": {
159-
"filename": null,
160-
"id": "10851161db01c3a8666fe9cbf8dc12442346543885f18e115dd10ad4fa83928e",
161-
"rendered": "#cloud-config\npackage_upgrade: true\n\npassword: orion\nchpasswd: { expire: False }\nssh_pwauth: True\n\nruncmd:\n - [ sh, -c, 'echo \"nameserver 8.8.8.8\" \u003e\u003e /etc/resolv.conf' ]\n - sudo apt update \u0026\u0026 sudo apt install -y apache2\n - sudo systemctl restart apache2\n - sudo apt install -y prometheus-node-exporter\n - sudo mkdir -p /var/www/example.com\n - sudo chown -R $USER:$USER /var/www/example.com\n - sudo chmod -R 755 /var/www/example.com\n - sudo echo -e \"\u003chtml\u003e\\n\\t\u003chead\u003e\\n\\t\\t\u003ctitle\u003eWelcome to example.com\\!\u003c/title\u003e\\n\\t\u003c/head\u003e\\n\\t\u003cbody\u003e\\n\\t\\t\u003ch1\u003eSuccess\\! The example.com virtual host is working!\u003c/h1\u003e\\n\\t\u003c/body\u003e\\n\u003c/html\u003e\" \u003e\u003e /var/www/example.com/index.html\n - sudo sed -i 's/\\\\//g' /var/www/example.com/html/index.html\n - sudo echo -e \"\u003cVirtualHost *:80\u003e\\n\\tServerAdmin webmaster@localhost\\n\\tServerName example.com\\n\\tServerAlias www.example.com\\n\\tDocumentRoot /var/www/example.com\\n\\tErrorLog /var/log/apache2/error.log\\n\\tCustomLog /var/log/apache2/access.log combined\\n\u003c/VirtualHost\u003e\" \u003e\u003e /etc/apache2/sites-available/example.com.conf\n - sudo a2ensite example.com.conf\n - sudo a2dissite 000-default.conf\n - sudo apache2ctl configtest\n - sudo systemctl restart apache2\n\n",
162-
"template": "#cloud-config\npackage_upgrade: true\n\npassword: orion\nchpasswd: { expire: False }\nssh_pwauth: True\n\nruncmd:\n - [ sh, -c, 'echo \"nameserver 8.8.8.8\" \u003e\u003e /etc/resolv.conf' ]\n - sudo apt update \u0026\u0026 sudo apt install -y apache2\n - sudo systemctl restart apache2\n - sudo apt install -y prometheus-node-exporter\n - sudo mkdir -p /var/www/example.com\n - sudo chown -R $USER:$USER /var/www/example.com\n - sudo chmod -R 755 /var/www/example.com\n - sudo echo -e \"\u003chtml\u003e\\n\\t\u003chead\u003e\\n\\t\\t\u003ctitle\u003eWelcome to example.com\\!\u003c/title\u003e\\n\\t\u003c/head\u003e\\n\\t\u003cbody\u003e\\n\\t\\t\u003ch1\u003eSuccess\\! The example.com virtual host is working!\u003c/h1\u003e\\n\\t\u003c/body\u003e\\n\u003c/html\u003e\" \u003e\u003e /var/www/example.com/index.html\n - sudo sed -i 's/\\\\//g' /var/www/example.com/html/index.html\n - sudo echo -e \"\u003cVirtualHost *:80\u003e\\n\\tServerAdmin webmaster@localhost\\n\\tServerName example.com\\n\\tServerAlias www.example.com\\n\\tDocumentRoot /var/www/example.com\\n\\tErrorLog /var/log/apache2/error.log\\n\\tCustomLog /var/log/apache2/access.log combined\\n\u003c/VirtualHost\u003e\" \u003e\u003e /etc/apache2/sites-available/example.com.conf\n - sudo a2ensite example.com.conf\n - sudo a2dissite 000-default.conf\n - sudo apache2ctl configtest\n - sudo systemctl restart apache2\n\n",
163-
"vars": null
164-
},
165-
"sensitive_attributes": []
166-
}
167-
]
168-
},
169-
{
170-
"mode": "managed",
171-
"type": "openstack_compute_floatingip_associate_v2",
172-
"name": "debian-buster-fip",
173-
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
174-
"instances": [
175-
{
176-
"schema_version": 0,
177-
"attributes": {
178-
"fixed_ip": "",
179-
"floating_ip": "10.80.81.191",
180-
"id": "10.80.81.191/7f8d3e4e-46b9-4bbd-8d33-d7fd6ed7db47/",
181-
"instance_id": "7f8d3e4e-46b9-4bbd-8d33-d7fd6ed7db47",
182-
"region": "RegionOne",
183-
"timeouts": null,
184-
"wait_until_associated": null
185-
},
186-
"sensitive_attributes": [],
187-
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDB9fQ==",
188-
"dependencies": [
189-
"data.openstack_compute_flavor_v2.m1-micro",
190-
"data.openstack_images_image_v2.debian-buster",
191-
"data.openstack_networking_floatingip_v2.debian-buster-fip",
192-
"data.openstack_networking_secgroup_v2.buster",
193-
"data.template_file.debian",
194-
"openstack_compute_instance_v2.debian-buster"
195-
]
196-
}
197-
]
198-
},
199-
{
200-
"mode": "managed",
201-
"type": "openstack_compute_instance_v2",
202-
"name": "debian-buster",
203-
"provider": "provider[\"registry.terraform.io/terraform-provider-openstack/openstack\"]",
204-
"instances": [
205-
{
206-
"schema_version": 0,
207-
"attributes": {
208-
"access_ip_v4": "172.16.101.5",
209-
"access_ip_v6": "",
210-
"admin_pass": null,
211-
"all_metadata": {
212-
"node_exporter": "true",
213-
"prometheus": "true"
214-
},
215-
"all_tags": [],
216-
"availability_zone": "nova",
217-
"availability_zone_hints": null,
218-
"block_device": [],
219-
"config_drive": null,
220-
"flavor_id": "d5cb96d8-c99b-441d-a4b5-1be84cb760fe",
221-
"flavor_name": "magma-agw",
222-
"floating_ip": null,
223-
"force_delete": false,
224-
"id": "7f8d3e4e-46b9-4bbd-8d33-d7fd6ed7db47",
225-
"image_id": "bc24ab09-60ee-42b4-b976-e241c228ee56",
226-
"image_name": "debian10",
227-
"key_pair": "",
228-
"metadata": {
229-
"node_exporter": "true",
230-
"prometheus": "true"
231-
},
232-
"name": "debian-buster-scaling",
233-
"network": [
234-
{
235-
"access_network": false,
236-
"fixed_ip_v4": "172.16.101.5",
237-
"fixed_ip_v6": "",
238-
"floating_ip": "",
239-
"mac": "fa:16:3e:dc:4f:34",
240-
"name": "SGI_ORAN",
241-
"port": "",
242-
"uuid": "157685f3-5cd3-40ea-aa61-e5cdc458d772"
243-
}
244-
],
245-
"network_mode": null,
246-
"personality": [],
247-
"power_state": "active",
248-
"region": "RegionOne",
249-
"scheduler_hints": [],
250-
"security_groups": [
251-
"buster"
252-
],
253-
"stop_before_destroy": false,
254-
"tags": null,
255-
"timeouts": null,
256-
"user_data": "9f2e64b4b575e24ea206f93c313cab12b164ecbb",
257-
"vendor_options": [],
258-
"volume": []
259-
},
260-
"sensitive_attributes": [],
261-
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInVwZGF0ZSI6MTgwMDAwMDAwMDAwMH19",
262-
"dependencies": [
263-
"data.openstack_compute_flavor_v2.m1-micro",
264-
"data.openstack_images_image_v2.debian-buster",
265-
"data.openstack_networking_secgroup_v2.buster",
266-
"data.template_file.debian"
267-
]
268-
}
269-
]
270-
}
271-
]
7+
"resources": []
2728
}

0 commit comments

Comments
 (0)