mirror of
https://github.com/20kaushik02/real-time-traffic-analysis-clickhouse.git
synced 2025-12-06 06:54:07 +00:00
Added resources, created a prototype trigger and its corresponding dockerfile for update configurations, Testing required
This commit is contained in:
parent
4d9526ae60
commit
52fc788eee
9
clickhouse/config_update_scripts/Dockerfile
Normal file
9
clickhouse/config_update_scripts/Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM python
|
||||
|
||||
WORKDIR /update_scripts
|
||||
|
||||
COPY . /update_scripts/
|
||||
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
CMD ["python3","update_trigger.py"]
|
||||
8
clickhouse/config_update_scripts/requirements.txt
Normal file
8
clickhouse/config_update_scripts/requirements.txt
Normal file
@ -0,0 +1,8 @@
|
||||
subprocess
|
||||
json
|
||||
jinja2
|
||||
yaml
|
||||
re
|
||||
xml
|
||||
schedule
|
||||
time
|
||||
@ -4,6 +4,7 @@ import subprocess
|
||||
import json
|
||||
import xml.etree.ElementTree as ET
|
||||
import os
|
||||
import re
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@ -15,14 +16,10 @@ if __name__ == "__main__":
|
||||
|
||||
all_services = [json.loads(s) for s in all_services]
|
||||
# extracting the name, removing the custom id from it and storing it in a list
|
||||
all_service_names = [service['Names'].split('.')[0] for service in all_services]
|
||||
# extracting only 'keeper1', 'server1'...
|
||||
all_service_names = [service['Names'].split('.')[0] for service in all_services if re.findall(r'clickhouse-server',service['Names'])]
|
||||
# extracting only 'server1','server2'...
|
||||
all_service_names = [ name.split('-')[-1] for name in all_service_names]
|
||||
|
||||
# removing all keeepers
|
||||
all_service_names.remove('keeper1')
|
||||
all_service_names.remove('keeper2')
|
||||
all_service_names.remove('keeper3')
|
||||
curr_num_servers = sorted(all_service_names)[-1][-1]
|
||||
|
||||
replication_factor = 2
|
||||
|
||||
34
clickhouse/config_update_scripts/update_trigger.py
Normal file
34
clickhouse/config_update_scripts/update_trigger.py
Normal file
@ -0,0 +1,34 @@
|
||||
import subprocess
|
||||
import json
|
||||
import re
|
||||
import schedule
|
||||
import time
|
||||
|
||||
def check_util_exec():
|
||||
# extracting details of each running container in json format
|
||||
try:
|
||||
all_services = subprocess.check_output(["docker","stats","--no-stream","--format","json"],text=True).split('\n')[:-1]
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Command failed with return code {e.returncode}")
|
||||
|
||||
all_services = [json.loads(s) for s in all_services]
|
||||
|
||||
resource_util_exceed_flag = True # Flag to check if all of the containers have exceeded 80% memory utilization
|
||||
for service in all_services:
|
||||
if re.findall(r'clickhouse-server',service['Name']):
|
||||
if float(service['MemPerc'][:-1]) < 80:
|
||||
resource_util_exceed_flag = False
|
||||
|
||||
if resource_util_exceed_flag:
|
||||
process = subprocess.Popen(['python3','update_compose.py'],text=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
||||
stdout, stderr = process.communicate() # Wait for the process to finish and capture output
|
||||
print("Standard Output:", stdout)
|
||||
print("Standard Error:", stderr)
|
||||
|
||||
if __name__ == "__main__":
|
||||
schedule.every(30).seconds.do(check_util_exec)
|
||||
while True:
|
||||
schedule.run_pending()
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
services:
|
||||
registry:
|
||||
image: registry:2
|
||||
ports:
|
||||
- "5000:5000"
|
||||
|
||||
clickhouse-keeper1:
|
||||
image: clickhouse/clickhouse-server:latest
|
||||
container_name: clickhouse-keeper1
|
||||
@ -69,10 +74,10 @@ services:
|
||||
# constraints: [node.labels.role == server]
|
||||
update_config:
|
||||
delay: 10s
|
||||
# resources:
|
||||
# limits:
|
||||
# cpus: "0.50"
|
||||
# memory: 100M
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.50"
|
||||
memory: 1200M
|
||||
depends_on:
|
||||
- clickhouse-keeper1
|
||||
- clickhouse-keeper2
|
||||
@ -100,10 +105,10 @@ services:
|
||||
# constraints: [node.labels.role == server]
|
||||
update_config:
|
||||
delay: 10s
|
||||
# resources:
|
||||
# limits:
|
||||
# cpus: "0.50"
|
||||
# memory: 100M
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.50"
|
||||
memory: 1200M
|
||||
depends_on:
|
||||
- clickhouse-keeper1
|
||||
- clickhouse-keeper2
|
||||
@ -115,8 +120,10 @@ services:
|
||||
networks:
|
||||
clickhouse-server-network:
|
||||
driver: overlay
|
||||
attachable: true
|
||||
clickhouse-keeper-network:
|
||||
driver: overlay
|
||||
attachable: true
|
||||
|
||||
volumes:
|
||||
clickhouse_data1:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user